|
| |||||||||||||
#include "libjabber.h"#include "libjwgc.h"#include "libxode.h"Go to the source code of this file.
Defines | |
| #define | KEYBUF 100 |
Functions | |
| xode | jabutil_presnew (int type, char *to, char *status, int priority) |
| xode | jabutil_iqnew (int type, char *ns) |
| xode | jabutil_msgnew (char *type, char *to, char *subj, char *body, char *encrypt) |
| xode | jabutil_pingnew (char *type, char *to) |
| xode | jabutil_header (char *xmlns, char *server) |
| int | jabutil_priority (xode x) |
| void | jabutil_tofrom (xode x) |
| xode | jabutil_iqresult (xode x) |
| char * | jabutil_timestamp (void) |
| void | jabutil_error (xode x, terror E) |
| void | jabutil_delay (xode msg, char *reason) |
| char * | jabutil_regkey (char *key, char *seed) |
| char * | jab_type_to_ascii (int j_type) |
| char * | jab_subtype_to_ascii (int j_subtype) |
| char * | jab_contype_to_ascii (int j_contype) |
|
|
Definition at line 320 of file jutil.c. Referenced by jabutil_regkey(). |
|
|
Definition at line 478 of file jutil.c. References JABCONN_STATE_AUTH, JABCONN_STATE_CONNECTED, JABCONN_STATE_OFF, and JABCONN_STATE_ON. Referenced by show_status(). 00480 {
00481 char *result;
00482
00483 switch (j_contype) {
00484 case JABCONN_STATE_OFF:
00485 result = "off";
00486 break;
00487
00488 case JABCONN_STATE_CONNECTED:
00489 result = "connected";
00490 break;
00491
00492 case JABCONN_STATE_ON:
00493 result = "on";
00494 break;
00495
00496 case JABCONN_STATE_AUTH:
00497 result = "auth";
00498 break;
00499
00500 default:
00501 result = "<unknown connection type>";
00502 break;
00503 }
00504
00505 return (strdup(result));
00506 }
|
|
|
Definition at line 399 of file jutil.c. References JABPACKET__AVAILABLE, JABPACKET__CHAT, JABPACKET__ERROR, JABPACKET__GET, JABPACKET__GROUPCHAT, JABPACKET__HEADLINE, JABPACKET__INTERNAL, JABPACKET__NONE, JABPACKET__PROBE, JABPACKET__RESULT, JABPACKET__SET, JABPACKET__SUBSCRIBE, JABPACKET__UNAVAILABLE, JABPACKET__UNKNOWN, JABPACKET__UNSUBSCRIBE, and JABPACKET__UNSUBSCRIBED. Referenced by decode_notice(). 00401 {
00402 char *result;
00403
00404 switch (j_subtype) {
00405 case JABPACKET__UNKNOWN:
00406 result = "unknown";
00407 break;
00408
00409 case JABPACKET__NONE:
00410 result = "none";
00411 break;
00412
00413 case JABPACKET__ERROR:
00414 result = "error";
00415 break;
00416
00417 case JABPACKET__CHAT:
00418 result = "chat";
00419 break;
00420
00421 case JABPACKET__GROUPCHAT:
00422 result = "groupchat";
00423 break;
00424
00425 case JABPACKET__INTERNAL:
00426 result = "internal";
00427 break;
00428
00429 case JABPACKET__GET:
00430 result = "get";
00431 break;
00432
00433 case JABPACKET__SET:
00434 result = "set";
00435 break;
00436
00437 case JABPACKET__RESULT:
00438 result = "result";
00439 break;
00440
00441 case JABPACKET__SUBSCRIBE:
00442 result = "subscribe";
00443 break;
00444
00445 case JABPACKET__UNSUBSCRIBE:
00446 result = "unsubscribe";
00447 break;
00448
00449 case JABPACKET__UNSUBSCRIBED:
00450 result = "unsubscribed";
00451 break;
00452
00453 case JABPACKET__AVAILABLE:
00454 result = "available";
00455 break;
00456
00457 case JABPACKET__UNAVAILABLE:
00458 result = "unavailable";
00459 break;
00460
00461 case JABPACKET__PROBE:
00462 result = "probe";
00463 break;
00464
00465 case JABPACKET__HEADLINE:
00466 result = "headline";
00467 break;
00468
00469 default:
00470 result = "<unknown subtype>";
00471 break;
00472 }
00473
00474 return (strdup(result));
00475 }
|
|
|
Definition at line 368 of file jutil.c. References JABPACKET_IQ, JABPACKET_MESSAGE, JABPACKET_PRESENCE, and JABPACKET_UNKNOWN. Referenced by decode_notice(). 00370 {
00371 char *result;
00372
00373 switch (j_type) {
00374 case JABPACKET_UNKNOWN:
00375 result = "unknown";
00376 break;
00377
00378 case JABPACKET_MESSAGE:
00379 result = "message";
00380 break;
00381
00382 case JABPACKET_PRESENCE:
00383 result = "presence";
00384 break;
00385
00386 case JABPACKET_IQ:
00387 result = "iq";
00388 break;
00389
00390 default:
00391 result = "<unknown type>";
00392 break;
00393 }
00394
00395 return (strdup(result));
00396 }
|
|
||||||||||||
|
Definition at line 308 of file jutil.c. References jabutil_timestamp(), NS_DELAY, xode, xode_get_attrib(), xode_insert_cdata(), xode_insert_tag(), and xode_put_attrib(). 00309 {
00310 xode delay;
00311
00312 delay = xode_insert_tag(msg, "x");
00313 xode_put_attrib(delay, "xmlns", NS_DELAY);
00314 xode_put_attrib(delay, "from", xode_get_attrib(msg, "to"));
00315 xode_put_attrib(delay, "stamp", jabutil_timestamp());
00316 if (reason != NULL)
00317 xode_insert_cdata(delay, reason, strlen(reason));
00318 }
|
|
||||||||||||
|
Definition at line 291 of file jutil.c. References terror_struct::code, jabutil_tofrom(), terror_struct::msg, snprintf, terror, xode, xode_insert_cdata(), xode_insert_tag(), and xode_put_attrib(). 00292 {
00293 xode err;
00294 char code[4];
00295
00296 xode_put_attrib(x, "type", "error");
00297 err = xode_insert_tag(x, "error");
00298
00299 snprintf(code, 4, "%d", E.code);
00300 xode_put_attrib(err, "code", code);
00301 if (E.msg != NULL)
00302 xode_insert_cdata(err, E.msg, strlen(E.msg));
00303
00304 jabutil_tofrom(x);
00305 }
|
|
||||||||||||
|
Definition at line 198 of file jutil.c. References xode, xode_new(), and xode_put_attrib(). Referenced by jab_start(). 00199 {
00200 xode result;
00201 if ((xmlns == NULL) || (server == NULL))
00202 return NULL;
00203 result = xode_new("stream:stream");
00204 xode_put_attrib(result, "xmlns:stream", "http://etherx.jabber.org/streams");
00205 xode_put_attrib(result, "xmlns", xmlns);
00206 xode_put_attrib(result, "to", server);
00207
00208 return result;
00209 }
|
|
||||||||||||
|
Definition at line 117 of file jutil.c. References JABPACKET__ERROR, JABPACKET__GET, JABPACKET__RESULT, JABPACKET__SET, ns, xode, xode_insert_tag(), xode_new(), and xode_put_attrib(). Referenced by jab_auth(), jab_on_state_handler(), jab_reg(), and jwg_on_event_handler(). 00118 {
00119 xode iq;
00120
00121 iq = xode_new("iq");
00122 switch (type) {
00123 case JABPACKET__GET:
00124 xode_put_attrib(iq, "type", "get");
00125 break;
00126 case JABPACKET__SET:
00127 xode_put_attrib(iq, "type", "set");
00128 break;
00129 case JABPACKET__RESULT:
00130 xode_put_attrib(iq, "type", "result");
00131 break;
00132 case JABPACKET__ERROR:
00133 xode_put_attrib(iq, "type", "error");
00134 break;
00135 }
00136 xode_put_attrib(xode_insert_tag(iq, "query"), "xmlns", ns);
00137
00138 return iq;
00139 }
|
|
|
Definition at line 251 of file jutil.c. References jabutil_tofrom(), xode, xode_get_firstchild(), xode_get_nextsibling(), xode_hide(), and xode_put_attrib(). 00252 {
00253 xode cur;
00254
00255 jabutil_tofrom(x);
00256
00257 xode_put_attrib(x, "type", "result");
00258
00259 /* hide all children of the iq, they go back empty */
00260 for (cur = xode_get_firstchild(x); cur != NULL; cur = xode_get_nextsibling(cur))
00261 xode_hide(cur);
00262
00263 return x;
00264 }
|
|
||||||||||||||||||||||||
|
Definition at line 143 of file jutil.c. References NS_ENCRYPTED, NS_EVENT, xode, xode_insert_cdata(), xode_insert_tag(), xode_new(), and xode_put_attrib(). Referenced by fake_startup_packet(), and jwg_on_event_handler(). 00144 {
00145 xode msg;
00146
00147 msg = xode_new("message");
00148 xode_put_attrib(msg, "type", type);
00149 xode_put_attrib(msg, "to", to);
00150
00151 if (subj) {
00152 xode_insert_cdata(xode_insert_tag(msg, "subject"), subj, strlen(subj));
00153 }
00154
00155 if (encrypt) {
00156 xode x;
00157
00158 x = xode_insert_tag(msg, "x");
00159 xode_put_attrib(x, "xmlns", NS_ENCRYPTED);
00160 xode_insert_cdata(x, encrypt, strlen(encrypt));
00161 }
00162
00163 {
00164 xode x;
00165
00166 x = xode_insert_tag(msg, "x");
00167 xode_put_attrib(x, "xmlns", NS_EVENT);
00168 xode_insert_tag(x, "composing");
00169 }
00170
00171 if (body) {
00172 xode_insert_cdata(xode_insert_tag(msg, "body"), body, strlen(body));
00173 }
00174
00175 return msg;
00176 }
|
|
||||||||||||
|
Definition at line 180 of file jutil.c. References NS_EVENT, xode, xode_insert_tag(), xode_new(), and xode_put_attrib(). Referenced by jwg_on_event_handler(). 00181 {
00182 xode msg;
00183 xode x, y;
00184
00185 msg = xode_new("message");
00186 xode_put_attrib(msg, "type", type);
00187 xode_put_attrib(msg, "to", to);
00188
00189 x = xode_insert_tag(msg, "x");
00190 xode_put_attrib(x, "xmlns", NS_EVENT);
00191 xode_insert_tag(x, "composing");
00192
00193 return msg;
00194 }
|
|
||||||||||||||||||||
|
Definition at line 50 of file jutil.c. References dExecution, dprintf(), JABPACKET__INVISIBLE, JABPACKET__PROBE, JABPACKET__SUBSCRIBE, JABPACKET__SUBSCRIBED, JABPACKET__UNAVAILABLE, JABPACKET__UNSUBSCRIBE, JABPACKET__UNSUBSCRIBED, jVars_get(), NS_SIGNED, snprintf, xode, xode_insert_cdata(), xode_insert_tag(), xode_new(), and xode_put_attrib(). Referenced by jab_on_state_handler(), jwg_on_event_handler(), jwgc_change_presence_event_handler(), and process_presence(). 00051 {
00052 xode pres;
00053 char pribuff[32];
00054
00055 pres = xode_new("presence");
00056 switch (type) {
00057 case JABPACKET__SUBSCRIBE:
00058 xode_put_attrib(pres, "type", "subscribe");
00059 break;
00060 case JABPACKET__UNSUBSCRIBE:
00061 xode_put_attrib(pres, "type", "unsubscribe");
00062 break;
00063 case JABPACKET__SUBSCRIBED:
00064 xode_put_attrib(pres, "type", "subscribed");
00065 break;
00066 case JABPACKET__UNSUBSCRIBED:
00067 xode_put_attrib(pres, "type", "unsubscribed");
00068 break;
00069 case JABPACKET__PROBE:
00070 xode_put_attrib(pres, "type", "probe");
00071 break;
00072 case JABPACKET__UNAVAILABLE:
00073 xode_put_attrib(pres, "type", "unavailable");
00074 break;
00075 case JABPACKET__INVISIBLE:
00076 xode_put_attrib(pres, "type", "invisible");
00077 break;
00078 }
00079 if (to != NULL)
00080 xode_put_attrib(pres, "to", to);
00081 #ifdef USE_GPGME
00082 if (*(int *)jVars_get(jVarUseGPG)) {
00083 char *signature;
00084 char *tmpstatus;
00085
00086 if (status == NULL) {
00087 tmpstatus = "online";
00088 }
00089 else {
00090 tmpstatus = status;
00091 }
00092
00093 signature = JTrimPGPMessage(JSign(tmpstatus));
00094 if (signature) {
00095 xode x;
00096
00097 dprintf(dExecution, "Adding status signature.\n");
00098 x = xode_insert_tag(pres, "x");
00099 xode_put_attrib(x, "xmlns", NS_SIGNED);
00100 xode_insert_cdata(x, signature, strlen(signature));
00101 status = tmpstatus;
00102 }
00103 }
00104 #endif /* USE_GPGME */
00105 if (status != NULL)
00106 xode_insert_cdata(xode_insert_tag(pres, "status"), status, strlen(status));
00107 if (priority >= 0) {
00108 snprintf(pribuff, sizeof(pribuff), "%d", priority);
00109 xode_insert_cdata(xode_insert_tag(pres, "priority"), pribuff, strlen(pribuff));
00110 }
00111
00112 return pres;
00113 }
|
|
|
Definition at line 213 of file jutil.c. References xode, xode_get_attrib(), xode_get_data(), and xode_get_tag(). 00214 {
00215 char *str;
00216 int p;
00217
00218 if (x == NULL)
00219 return -1;
00220
00221 if (xode_get_attrib(x, "type") != NULL)
00222 return -1;
00223
00224 x = xode_get_tag(x, "priority");
00225 if (x == NULL)
00226 return 0;
00227
00228 str = xode_get_data((x));
00229 if (str == NULL)
00230 return 0;
00231
00232 p = atoi(str);
00233 if (p >= 0)
00234 return p;
00235 else
00236 return 0;
00237 }
|
|
||||||||||||
|
Definition at line 323 of file jutil.c. References j_shahash(), j_strcmp(), KEYBUF, and NULL. 00324 {
00325 static char keydb[KEYBUF][41];
00326 static char seeddb[KEYBUF][41];
00327 static int last = -1;
00328 char *str, strint[32];
00329 int i;
00330
00331 /* blanket the keydb first time */
00332 if (last == -1) {
00333 last = 0;
00334 memset(&keydb, 0, KEYBUF * 41);
00335 memset(&seeddb, 0, KEYBUF * 41);
00336 srand(time(NULL));
00337 }
00338
00339 /* creation phase */
00340 if (key == NULL && seed != NULL) {
00341 /* create a random key hash and store it */
00342 sprintf(strint, "%d", rand());
00343 strcpy(keydb[last], j_shahash(strint));
00344
00345 /* store a hash for the seed associated w/ this key */
00346 strcpy(seeddb[last], j_shahash(seed));
00347
00348 /* return it all */
00349 str = keydb[last];
00350 last++;
00351 if (last == KEYBUF)
00352 last = 0;
00353 return str;
00354 }
00355
00356 /* validation phase */
00357 str = j_shahash(seed);
00358 for (i = 0; i < KEYBUF; i++)
00359 if (j_strcmp(keydb[i], key) == 0 && j_strcmp(seeddb[i], str) == 0) {
00360 seeddb[i][0] = '\0'; /* invalidate this key */
00361 return keydb[i];
00362 }
00363
00364 return NULL;
00365 }
|
|
|
Definition at line 267 of file jutil.c. References NULL, and snprintf. Referenced by jabutil_delay(). 00268 {
00269 time_t t;
00270 struct tm *new_time;
00271 static char timestamp[18];
00272 int ret;
00273
00274 t = time(NULL);
00275
00276 if (t == (time_t) - 1)
00277 return NULL;
00278 new_time = gmtime(&t);
00279
00280 ret = snprintf(timestamp, 18, "%d%02d%02dT%02d:%02d:%02d", 1900 + new_time->tm_year,
00281 new_time->tm_mon + 1, new_time->tm_mday, new_time->tm_hour,
00282 new_time->tm_min, new_time->tm_sec);
00283
00284 if (ret == -1)
00285 return NULL;
00286
00287 return timestamp;
00288 }
|
|
|
Definition at line 240 of file jutil.c. References xode, xode_get_attrib(), and xode_put_attrib(). Referenced by jabutil_error(), and jabutil_iqresult(). 00241 {
00242 char *to, *from;
00243
00244 to = xode_get_attrib(x, "to");
00245 from = xode_get_attrib(x, "from");
00246 xode_put_attrib(x, "from", to);
00247 xode_put_attrib(x, "to", from);
00248 }
|
| Last updated at Tue Dec 18 21:07:42 PST 2007. | This site and project hosted by... |