00001
00002
00003
00004
00005
00006
00007 #ifndef IKSEMEL_H
00008 #define IKSEMEL_H 1
00009
00010 #ifdef __cplusplus
00011 #include <cstddef>
00012 extern "C" {
00013 #else
00014 #include <stddef.h>
00015 #endif
00016
00017
00018
00019 struct ikstack_struct;
00020 typedef struct ikstack_struct ikstack;
00021
00022 ikstack *iks_stack_new (size_t meta_chunk, size_t data_chunk);
00023 void *iks_stack_alloc (ikstack *s, size_t size);
00024 char *iks_stack_strdup (ikstack *s, const char *src, size_t len);
00025 char *iks_stack_strcat (ikstack *s, char *old, size_t old_len, const char *src, size_t src_len);
00026 void iks_stack_stat (ikstack *s, size_t *allocated, size_t *used);
00027 void iks_stack_delete (ikstack *s);
00028
00029
00030
00031 void *iks_malloc (size_t size);
00032 void iks_free (void *ptr);
00033 void iks_set_mem_funcs (void *(*malloc_func)(size_t size), void (*free_func)(void *ptr));
00034
00035 char *iks_strdup (const char *src);
00036 char *iks_strcat (char *dest, const char *src);
00037 int iks_strcmp (const char *a, const char *b);
00038 int iks_strcasecmp (const char *a, const char *b);
00039 int iks_strncmp (const char *a, const char *b, size_t n);
00040 int iks_strncasecmp (const char *a, const char *b, size_t n);
00041 size_t iks_strlen (const char *src);
00042 char *iks_escape (ikstack *s, char *src, size_t len);
00043 char *iks_unescape (ikstack *s, char *src, size_t len);
00044
00045
00046
00047 enum ikstype {
00048 IKS_NONE = 0,
00049 IKS_TAG,
00050 IKS_ATTRIBUTE,
00051 IKS_CDATA
00052 };
00053
00054 struct iks_struct;
00055 typedef struct iks_struct iks;
00056
00057 iks *iks_new (const char *name);
00058 iks *iks_new_within (const char *name, ikstack *s);
00059 iks *iks_insert (iks *x, const char *name);
00060 iks *iks_insert_cdata (iks *x, const char *data, size_t len);
00061 iks *iks_insert_attrib (iks *x, const char *name, const char *value);
00062 iks *iks_insert_node (iks *x, iks *y);
00063 void iks_hide (iks *x);
00064 void iks_delete (iks *x);
00065 iks *iks_next (iks *x);
00066 iks *iks_next_tag (iks *x);
00067 iks *iks_prev (iks *x);
00068 iks *iks_prev_tag (iks *x);
00069 iks *iks_parent (iks *x);
00070 iks *iks_root (iks *x);
00071 iks *iks_child (iks *x);
00072 iks *iks_first_tag (iks *x);
00073 iks *iks_attrib (iks *x);
00074 iks *iks_find (iks *x, const char *name);
00075 char *iks_find_cdata (iks *x, const char *name);
00076 char *iks_find_attrib (iks *x, const char *name);
00077 iks *iks_find_with_attrib (iks *x, const char *tagname, const char *attrname, const char *value);
00078 ikstack *iks_stack (iks *x);
00079 enum ikstype iks_type (iks *x);
00080 char *iks_name (iks *x);
00081 char *iks_cdata (iks *x);
00082 size_t iks_cdata_size (iks *x);
00083 int iks_has_children (iks *x);
00084 int iks_has_attribs (iks *x);
00085 char *iks_string (ikstack *s, iks *x);
00086 iks *iks_copy (iks *x);
00087 iks *iks_copy_within (iks *x, ikstack *s);
00088
00089
00090
00091 enum ikserror {
00092 IKS_OK = 0,
00093 IKS_NOMEM,
00094 IKS_BADXML,
00095 IKS_HOOK
00096 };
00097
00098 enum ikstagtype {
00099 IKS_OPEN,
00100 IKS_CLOSE,
00101 IKS_SINGLE
00102 };
00103
00104 typedef int (iksTagHook)(void *user_data, char *name, char **atts, int type);
00105 typedef int (iksCDataHook)(void *user_data, char *data, size_t len);
00106 typedef void (iksDeleteHook)(void *user_data);
00107
00108 struct iksparser_struct;
00109 typedef struct iksparser_struct iksparser;
00110
00111 iksparser *iks_sax_new (void *user_data, iksTagHook *tagHook, iksCDataHook *cdataHook);
00112 iksparser *iks_sax_extend (ikstack *s, void *user_data, iksTagHook *tagHook, iksCDataHook *cdataHook, iksDeleteHook *deleteHook);
00113 ikstack *iks_parser_stack (iksparser *prs);
00114 void *iks_user_data (iksparser *prs);
00115 unsigned long iks_nr_bytes (iksparser *prs);
00116 unsigned long iks_nr_lines (iksparser *prs);
00117 int iks_parse (iksparser *prs, const char *data, size_t len, int finish);
00118 void iks_parser_reset (iksparser *prs);
00119 void iks_parser_delete (iksparser *prs);
00120
00121
00122
00123 enum iksfileerror {
00124 IKS_FILE_NOFILE = 4,
00125 IKS_FILE_NOACCESS,
00126 IKS_FILE_RWERR
00127 };
00128
00129 iksparser *iks_dom_new (iks **iksptr);
00130 void iks_set_size_hint (iksparser *prs, size_t approx_size);
00131 iks *iks_tree (const char *xml_str, size_t len, int *err);
00132 int iks_load (const char *fname, iks **xptr);
00133 int iks_save (const char *fname, iks *x);
00134
00135
00136
00137 enum iksasyncevents {
00138 IKS_ASYNC_RESOLVED,
00139 IKS_ASYNC_CONNECTED,
00140 IKS_ASYNC_WRITE,
00141 IKS_ASYNC_WRITTEN,
00142 IKS_ASYNC_READ,
00143 IKS_ASYNC_CLOSED,
00144 IKS_ASYNC_ERROR
00145 };
00146
00147 typedef struct iksasyncevent_struct {
00148 int event;
00149 int data0;
00150 int data1;
00151 } iksasyncevent;
00152
00153 typedef void (iksTClose)(void *socket);
00154 typedef int (iksTConnect)(iksparser *prs, void **socketptr, const char *server, int port);
00155 typedef int (iksTSend)(void *socket, const char *data, size_t len);
00156 typedef int (iksTRecv)(void *socket, char *buffer, size_t buf_len, int timeout);
00157 typedef int (iksAsyncNotify)(void *user_data, iksasyncevent *event);
00158 typedef int (iksTConnectAsync)(iksparser *prs, void **socketptr, const char *server, const char *server_name, int port, void *notify_data, iksAsyncNotify *notify_func);
00159
00160 #define IKS_TRANSPORT_V1 0
00161
00162 typedef const struct ikstransport_struct {
00163 int abi_version;
00164
00165 iksTConnect *connect;
00166 iksTSend *send;
00167 iksTRecv *recv;
00168 iksTClose *close;
00169
00170 iksTConnectAsync *connect_async;
00171 } ikstransport;
00172
00173 extern ikstransport iks_default_transport;
00174
00175
00176
00177 enum iksneterror {
00178 IKS_NET_NODNS = 4,
00179 IKS_NET_NOSOCK,
00180 IKS_NET_NOCONN,
00181 IKS_NET_RWERR,
00182 IKS_NET_NOTSUPP,
00183 IKS_NET_TLSFAIL,
00184 IKS_NET_DROPPED,
00185 IKS_NET_UNKNOWN
00186 };
00187
00188 enum iksnodetype {
00189 IKS_NODE_START,
00190 IKS_NODE_NORMAL,
00191 IKS_NODE_ERROR,
00192 IKS_NODE_STOP
00193 };
00194
00195 enum ikssasltype {
00196 IKS_SASL_PLAIN,
00197 IKS_SASL_DIGEST_MD5
00198 };
00199
00200 #define IKS_JABBER_PORT 5222
00201
00202 typedef int (iksStreamHook)(void *user_data, int type, iks *node);
00203 typedef void (iksLogHook)(void *user_data, const char *data, size_t size, int is_incoming);
00204
00205 iksparser *iks_stream_new (char *name_space, void *user_data, iksStreamHook *streamHook);
00206 void *iks_stream_user_data (iksparser *prs);
00207 void iks_set_log_hook (iksparser *prs, iksLogHook *logHook);
00208 int iks_connect_tcp (iksparser *prs, const char *server, int port);
00209 int iks_connect_fd (iksparser *prs, int fd);
00210 int iks_connect_via (iksparser *prs, const char *server, int port, const char *server_name);
00211 int iks_connect_with (iksparser *prs, const char *server, int port, const char *server_name, ikstransport *trans);
00212 int iks_connect_async (iksparser *prs, const char *server, int port, void *notify_data, iksAsyncNotify *notify_func);
00213 int iks_connect_async_with (iksparser *prs, const char *server, int port, const char *server_name, ikstransport *trans, void *notify_data, iksAsyncNotify *notify_func);
00214 int iks_fd (iksparser *prs);
00215 int iks_recv (iksparser *prs, int timeout);
00216 int iks_send_header (iksparser *prs, const char *to);
00217 int iks_send (iksparser *prs, iks *x);
00218 int iks_send_raw (iksparser *prs, const char *xmlstr);
00219 void iks_disconnect (iksparser *prs);
00220 int iks_has_tls (void);
00221 int iks_is_secure (iksparser *prs);
00222 int iks_start_tls (iksparser *prs);
00223 int iks_start_sasl (iksparser *prs, enum ikssasltype type, char *username, char *pass);
00224
00225
00226
00227 #define IKS_NS_CLIENT "jabber:client"
00228 #define IKS_NS_SERVER "jabber:server"
00229 #define IKS_NS_AUTH "jabber:iq:auth"
00230 #define IKS_NS_AUTH_0K "jabber:iq:auth:0k"
00231 #define IKS_NS_REGISTER "jabber:iq:register"
00232 #define IKS_NS_ROSTER "jabber:iq:roster"
00233 #define IKS_NS_XROSTER "jabber:x:roster"
00234 #define IKS_NS_OFFLINE "jabber:x:offline"
00235 #define IKS_NS_AGENT "jabber:iq:agent"
00236 #define IKS_NS_AGENTS "jabber:iq:agents"
00237 #define IKS_NS_BROWSE "jabber:iq:browse"
00238 #define IKS_NS_CONFERENCE "jabber:iq:conference"
00239 #define IKS_NS_DELAY "jabber:x:delay"
00240 #define IKS_NS_VERSION "jabber:iq:version"
00241 #define IKS_NS_TIME "jabber:iq:time"
00242 #define IKS_NS_VCARD "vcard-temp"
00243 #define IKS_NS_PRIVATE "jabber:iq:private"
00244 #define IKS_NS_SEARCH "jabber:iq:search"
00245 #define IKS_NS_OOB "jabber:iq:oob"
00246 #define IKS_NS_XOOB "jabber:x:oob"
00247 #define IKS_NS_ADMIN "jabber:iq:admin"
00248 #define IKS_NS_FILTER "jabber:iq:filter"
00249 #define IKS_NS_GATEWAY "jabber:iq:gateway"
00250 #define IKS_NS_LAST "jabber:iq:last"
00251 #define IKS_NS_SIGNED "jabber:x:signed"
00252 #define IKS_NS_ENCRYPTED "jabber:x:encrypted"
00253 #define IKS_NS_ENVELOPE "jabber:x:envelope"
00254 #define IKS_NS_EVENT "jabber:x:event"
00255 #define IKS_NS_EXPIRE "jabber:x:expire"
00256 #define IKS_NS_XHTML "http://www.w3.org/1999/xhtml"
00257 #define IKS_NS_XMPP_SASL "urn:ietf:params:xml:ns:xmpp-sasl"
00258 #define IKS_NS_XMPP_BIND "urn:ietf:params:xml:ns:xmpp-bind"
00259 #define IKS_NS_XMPP_SESSION "urn:ietf:params:xml:ns:xmpp-session"
00260
00261 #define IKS_ID_USER 1
00262 #define IKS_ID_SERVER 2
00263 #define IKS_ID_RESOURCE 4
00264 #define IKS_ID_PARTIAL IKS_ID_USER | IKS_ID_SERVER
00265 #define IKS_ID_FULL IKS_ID_USER | IKS_ID_SERVER | IKS_ID_RESOURCE
00266
00267 #define IKS_STREAM_STARTTLS 1
00268 #define IKS_STREAM_SESSION 2
00269 #define IKS_STREAM_BIND 4
00270 #define IKS_STREAM_SASL_PLAIN 8
00271 #define IKS_STREAM_SASL_MD5 16
00272
00273 typedef struct iksid_struct {
00274 char *user;
00275 char *server;
00276 char *resource;
00277 char *partial;
00278 char *full;
00279 } iksid;
00280
00281 iksid *iks_id_new (ikstack *s, const char *jid);
00282 int iks_id_cmp (iksid *a, iksid *b, int parts);
00283
00284 enum ikspaktype {
00285 IKS_PAK_NONE = 0,
00286 IKS_PAK_MESSAGE,
00287 IKS_PAK_PRESENCE,
00288 IKS_PAK_IQ,
00289 IKS_PAK_S10N
00290 };
00291
00292 enum iksubtype {
00293 IKS_TYPE_NONE = 0,
00294 IKS_TYPE_ERROR,
00295
00296 IKS_TYPE_CHAT,
00297 IKS_TYPE_GROUPCHAT,
00298 IKS_TYPE_HEADLINE,
00299
00300 IKS_TYPE_GET,
00301 IKS_TYPE_SET,
00302 IKS_TYPE_RESULT,
00303
00304 IKS_TYPE_SUBSCRIBE,
00305 IKS_TYPE_SUBSCRIBED,
00306 IKS_TYPE_UNSUBSCRIBE,
00307 IKS_TYPE_UNSUBSCRIBED,
00308 IKS_TYPE_PROBE,
00309 IKS_TYPE_AVAILABLE,
00310 IKS_TYPE_UNAVAILABLE
00311 };
00312
00313 enum ikshowtype {
00314 IKS_SHOW_UNAVAILABLE = 0,
00315 IKS_SHOW_AVAILABLE,
00316 IKS_SHOW_CHAT,
00317 IKS_SHOW_AWAY,
00318 IKS_SHOW_XA,
00319 IKS_SHOW_DND
00320 };
00321
00322 typedef struct ikspak_struct {
00323 iks *x;
00324 iksid *from;
00325 iks *query;
00326 char *ns;
00327 char *id;
00328 enum ikspaktype type;
00329 enum iksubtype subtype;
00330 enum ikshowtype show;
00331 } ikspak;
00332
00333 ikspak *iks_packet (iks *x);
00334
00335 iks *iks_make_auth (iksid *id, const char *pass, const char *sid);
00336 iks *iks_make_msg (enum iksubtype type, const char *to, const char *body);
00337 iks *iks_make_s10n (enum iksubtype type, const char *to, const char *msg);
00338 iks *iks_make_pres (enum ikshowtype show, const char *status);
00339 iks *iks_make_iq (enum iksubtype type, const char *xmlns);
00340 iks *iks_make_resource_bind(iksid *id);
00341 iks *iks_make_session(void);
00342 int iks_stream_features(iks *x);
00343
00344
00345
00346 #define IKS_RULE_DONE 0
00347 #define IKS_RULE_ID 1
00348 #define IKS_RULE_TYPE 2
00349 #define IKS_RULE_SUBTYPE 4
00350 #define IKS_RULE_FROM 8
00351 #define IKS_RULE_FROM_PARTIAL 16
00352 #define IKS_RULE_NS 32
00353
00354 enum iksfilterret {
00355 IKS_FILTER_PASS,
00356 IKS_FILTER_EAT
00357 };
00358
00359 typedef int (iksFilterHook)(void *user_data, ikspak *pak);
00360
00361 struct iksfilter_struct;
00362 typedef struct iksfilter_struct iksfilter;
00363 struct iksrule_struct;
00364 typedef struct iksrule_struct iksrule;
00365
00366 iksfilter *iks_filter_new (void);
00367 iksrule *iks_filter_add_rule (iksfilter *f, iksFilterHook *filterHook, void *user_data, ...);
00368 void iks_filter_remove_rule (iksfilter *f, iksrule *rule);
00369 void iks_filter_remove_hook (iksfilter *f, iksFilterHook *filterHook);
00370 void iks_filter_packet (iksfilter *f, ikspak *pak);
00371 void iks_filter_delete (iksfilter *f);
00372
00373
00374
00375 struct iksha_struct;
00376 typedef struct iksha_struct iksha;
00377
00378 iksha *iks_sha_new (void);
00379 void iks_sha_reset (iksha *sha);
00380 void iks_sha_hash (iksha *sha, const unsigned char *data, size_t len, int finish);
00381 void iks_sha_print (iksha *sha, char *hash);
00382 void iks_sha_delete (iksha *sha);
00383 void iks_sha (const char *data, char *hash);
00384
00385
00386
00387 struct ikmd5_struct;
00388 typedef struct iksmd5_struct iksmd5;
00389
00390 iksmd5 *iks_md5_new(void);
00391 void iks_md5_reset(iksmd5 *md5);
00392 void iks_md5_hash(iksmd5 *md5, const unsigned char *data, size_t slen, int finish);
00393 void iks_md5_delete(iksmd5 *md5);
00394 void iks_md5_print(iksmd5 *md5, char *buf);
00395 void iks_md5_digest(iksmd5 *md5, unsigned char *digest);
00396 void iks_md5(const char *data, char *buf);
00397
00398
00399
00400 char *iks_base64_decode(const char *buf);
00401 char *iks_base64_encode(const char *buf, int len);
00402
00403 #ifdef __cplusplus
00404 }
00405 #endif
00406
00407 #endif