|
|
#include <sysdep.h>
#include "libxode.h"
#include "libjabber_types.h"
#include "libjwgc_types.h"
Go to the source code of this file.
|
Definition at line 24 of file libjabber.h. |
|
Definition at line 489 of file jconn.c. References jabconn_struct::auth_digest, jabconn_struct::auth_password, dExecution, dprintf(), j_shahash(), jab_getid(), jab_recv(), jab_send(), jabconn, JABPACKET__GET, JABPACKET__SET, jabutil_iqnew(), NS_AUTH, xode_struct::p, jabconn_struct::pass, jid_struct::resource, jid_struct::server, jabconn_struct::sid, jabconn_struct::user, jid_struct::user, xode, xode_free(), xode_get_tag(), xode_insert_cdata(), xode_insert_tag(), xode_pool_malloc(), and xode_put_attrib(). Referenced by jabber_init(). 00490 { 00491 xode x, y, z; 00492 char *user, *id; 00493 00494 if (!j) 00495 return (NULL); 00496 00497 user = j->user->user; 00498 id = jab_getid(j); 00499 00500 x = jabutil_iqnew(JABPACKET__GET, NS_AUTH); 00501 xode_put_attrib(x, "id", "auth_1"); 00502 xode_put_attrib(x, "to", j->user->server); 00503 y = xode_get_tag(x, "query"); 00504 00505 if (user) { 00506 z = xode_insert_tag(y, "username"); 00507 xode_insert_cdata(z, user, -1); 00508 } 00509 00510 jab_send(j, x); 00511 xode_free(x); 00512 jab_recv(j); 00513 00514 x = jabutil_iqnew(JABPACKET__SET, NS_AUTH); 00515 xode_put_attrib(x, "id", "auth_2"); 00516 xode_put_attrib(x, "to", j->user->server); 00517 y = xode_get_tag(x, "query"); 00518 00519 if (user) { 00520 dprintf(dExecution, "Got auth user %s...\n", user); 00521 z = xode_insert_tag(y, "username"); 00522 xode_insert_cdata(z, user, -1); 00523 } 00524 00525 z = xode_insert_tag(y, "resource"); 00526 xode_insert_cdata(z, j->user->resource, -1); 00527 dprintf(dExecution, "Got auth resource %s...\n", j->user->resource); 00528 00529 dprintf(dExecution, "Got auth password %s...\n", j->pass); 00530 if (j->sid && j->auth_digest) { 00531 char *hash; 00532 00533 dprintf(dExecution, "Got digest auth id %s...\n", j->sid); 00534 z = xode_insert_tag(y, "digest"); 00535 hash = xode_pool_malloc(x->p, 00536 strlen(j->sid) + strlen(j->pass) + 1); 00537 strcpy(hash, j->sid); 00538 strcat(hash, j->pass); 00539 hash = (char *)j_shahash(hash); 00540 xode_insert_cdata(z, hash, 40); 00541 } 00542 else if (j->auth_password) { 00543 z = xode_insert_tag(y, "password"); 00544 xode_insert_cdata(z, j->pass, -1); 00545 } 00546 00547 jab_send(j, x); 00548 xode_free(x); 00549 jab_recv(j); 00550 00551 return id; 00552 }
|
|
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 87 of file jconn.c. References jab_stop(), jabconn, jabconn_struct::p, and xode_pool_free(). 00088 { 00089 if (!j) 00090 return; 00091 00092 jab_stop(j); 00093 xode_pool_free(j->p); 00094 }
|
|
Definition at line 277 of file jconn.c. References jabconn_struct::fd, and jabconn. Referenced by jab_on_state_handler(), and jabber_init(). 00278 { 00279 if (j) { 00280 #ifdef USE_SSL 00281 if (j->sslfd != -1) { 00282 return j->sslfd; 00283 } 00284 else { 00285 #endif /* USE_SSL */ 00286 return j->fd; 00287 #ifdef USE_SSL 00288 } 00289 #endif /* USE_SSL */ 00290 } 00291 else { 00292 return -1; 00293 } 00294 }
|
|
Definition at line 333 of file jconn.c. References jabconn_struct::id, jabconn_struct::idbuf, jabconn, and snprintf. Referenced by jab_auth(), and jab_reg().
|
|
Definition at line 303 of file jconn.c. References jabconn, and jabconn_struct::user. 00304 { 00305 if (j) 00306 return (j->user); 00307 else 00308 return NULL; 00309 }
|
|
Definition at line 318 of file jconn.c. References jabconn, and jabconn_struct::sid. 00319 { 00320 if (j) 00321 return (j->sid); 00322 else 00323 return NULL; 00324 }
|
|
Definition at line 45 of file jconn.c. References jabconn_struct::dumpfd, jabconn_struct::dumpid, jabconn_struct::fd, jabconn_struct::id, jabconn, jid_new(), jabconn_struct::p, jabconn_struct::pass, jabconn_struct::port, jabconn_struct::state, jabconn_struct::user, xode_pool, xode_pool_mallocx(), xode_pool_new(), and xode_pool_strdup(). Referenced by jabber_init(). 00046 { 00047 xode_pool p; 00048 jabconn j; 00049 00050 if (!user) 00051 return (NULL); 00052 00053 p = xode_pool_new(); 00054 if (!p) 00055 return (NULL); 00056 j = xode_pool_mallocx(p, sizeof(jabconn_struct), 0); 00057 if (!j) 00058 return (NULL); 00059 j->p = p; 00060 00061 j->user = jid_new(p, user); 00062 j->pass = xode_pool_strdup(p, pass); 00063 j->port = 5222; 00064 00065 j->state = JABCONN_STATE_OFF; 00066 j->id = 1; 00067 j->fd = -1; 00068 j->dumpfd = -1; 00069 j->dumpid = NULL; 00070 #ifdef USE_SSL 00071 j->ssl = NULL; 00072 j->ssl_ctx = NULL; 00073 j->sslfd = -1; 00074 #endif /* USE_SSL */ 00075 00076 return j; 00077 }
|
|
Definition at line 120 of file jconn.c. References jabconn, and jabconn_struct::on_packet. Referenced by jabber_init(). 00121 { 00122 if (!j) 00123 return; 00124 00125 j->on_packet = h; 00126 }
|
|
Definition at line 443 of file jconn.c. References jabconn_struct::fd, jab_recv(), jabconn, NULL, and jabconn_struct::state. 00444 { 00445 fd_set fds; 00446 FILE *selfd; 00447 struct timeval tv; 00448 00449 if (!j || j->state == JABCONN_STATE_OFF) 00450 return; 00451 00452 FD_ZERO(&fds); 00453 #ifdef USE_SSL 00454 if (j->sslfd == -1) { 00455 #endif /* USE_SSL */ 00456 FD_SET(j->fd, &fds); 00457 selfd = (FILE *) j->fd; 00458 #ifdef USE_SSL 00459 } 00460 else { 00461 FD_SET(j->sslfd, &fds); 00462 selfd = (FILE *) j->sslfd; 00463 } 00464 #endif /* USE_SSL */ 00465 00466 00467 if (timeout < 0) { 00468 if (select((int) selfd + 1, &fds, NULL, NULL, NULL) > 0) 00469 jab_recv(j); 00470 } 00471 else { 00472 tv.tv_sec = 0; 00473 tv.tv_usec = timeout; 00474 if (select((int) selfd + 1, &fds, NULL, NULL, &tv) > 0) 00475 jab_recv(j); 00476 } 00477 }
|
|
Definition at line 398 of file jconn.c. References dJAB, dParser, dprintf(), jabconn_struct::fd, jab_stop(), jabconn, JABCONN_STATE_OFF, jabconn_struct::parser, jabconn_struct::state, STATE_EVT, XML_ErrorString(), XML_GetCurrentByteIndex(), XML_GetCurrentColumnNumber(), XML_GetCurrentLineNumber(), XML_GetErrorCode(), and XML_Parse(). Referenced by jab_auth(), jab_poll(), jab_start(), jabber_init(), and jwg_on_event_handler(). 00399 { 00400 static char buf[4096]; 00401 int len; 00402 int errcode; 00403 00404 if (!j || j->state == JABCONN_STATE_OFF) 00405 return; 00406 00407 #ifdef USE_SSL 00408 if (j->sslfd == -1) { 00409 #endif /* USE_SSL */ 00410 len = read(j->fd, buf, sizeof(buf) - 1); 00411 #ifdef USE_SSL 00412 } 00413 else { 00414 len = SSL_read(j->ssl, buf, sizeof(buf) - 1); 00415 } 00416 #endif /* USE_SSL */ 00417 if (len > 0) { 00418 buf[len] = '\0'; 00419 dprintf(dJAB, " in: %s\n", buf); 00420 errcode = XML_Parse(j->parser, buf, len, 0); 00421 dprintf(dParser, "parser index %d, line %d, col %d\n", XML_GetCurrentByteIndex(j->parser), XML_GetCurrentLineNumber(j->parser), XML_GetCurrentColumnNumber(j->parser)); 00422 if (errcode == 0) { 00423 dprintf(dParser, "parser error %d at byte %d: %s\n", XML_GetErrorCode(j->parser), XML_GetCurrentByteIndex(j->parser), XML_ErrorString(XML_GetErrorCode(j->parser))); 00424 } 00425 else { 00426 dprintf(dParser, "parser complete\n"); 00427 } 00428 } 00429 else if (len < 0) { 00430 STATE_EVT(JABCONN_STATE_OFF); 00431 jab_stop(j); 00432 } 00433 }
|
|
Definition at line 564 of file jconn.c. References jab_getid(), jab_send(), jabconn, JABCONN_STATE_AUTH, JABPACKET__SET, jabutil_iqnew(), NS_REGISTER, jabconn_struct::pass, jid_struct::resource, jabconn_struct::state, STATE_EVT, jabconn_struct::user, jid_struct::user, xode, xode_free(), xode_get_tag(), xode_insert_cdata(), xode_insert_tag(), and xode_put_attrib(). Referenced by jabber_init(). 00565 { 00566 xode x, y, z; 00567 char *user, *id; 00568 /* UNUSED char *hash; */ 00569 00570 if (!j) 00571 return (NULL); 00572 00573 x = jabutil_iqnew(JABPACKET__SET, NS_REGISTER); 00574 id = jab_getid(j); 00575 xode_put_attrib(x, "id", id); 00576 y = xode_get_tag(x, "query"); 00577 00578 user = j->user->user; 00579 00580 if (user) { 00581 z = xode_insert_tag(y, "username"); 00582 xode_insert_cdata(z, user, -1); 00583 } 00584 00585 z = xode_insert_tag(y, "resource"); 00586 xode_insert_cdata(z, j->user->resource, -1); 00587 00588 if (j->pass) { 00589 z = xode_insert_tag(y, "password"); 00590 xode_insert_cdata(z, j->pass, -1); 00591 } 00592 00593 jab_send(j, x); 00594 xode_free(x); 00595 00596 j->state = JABCONN_STATE_AUTH; 00597 STATE_EVT(JABCONN_STATE_AUTH) 00598 00599 return id; 00600 }
|
|
Definition at line 347 of file jconn.c. References dJAB, dprintf(), jabconn_struct::fd, jabconn, jabconn_struct::state, xode, and xode_to_str(). Referenced by fake_startup_packet(), jab_auth(), jab_on_state_handler(), jab_reg(), jwg_on_event_handler(), jwgc_change_presence_event_handler(), and process_presence(). 00348 { 00349 if (j && j->state != JABCONN_STATE_OFF) { 00350 char *buf = xode_to_str(x); 00351 #ifdef USE_SSL 00352 if (j->sslfd == -1) { 00353 #endif /* USE_SSL */ 00354 if (buf) 00355 write(j->fd, buf, strlen(buf)); 00356 #ifdef USE_SSL 00357 } 00358 else { 00359 if (buf) 00360 SSL_write(j->ssl, buf, strlen(buf)); 00361 } 00362 #endif /* USE_SSL */ 00363 dprintf(dJAB, "out: %s\n", buf); 00364 } 00365 }
|
|
Definition at line 375 of file jconn.c. References dJAB, dprintf(), jabconn_struct::fd, jabconn, and jabconn_struct::state. Referenced by jab_start(). 00376 { 00377 if (j && j->state != JABCONN_STATE_OFF) 00378 #ifdef USE_SSL 00379 if (j->sslfd == -1) { 00380 #endif /* USE_SSL */ 00381 write(j->fd, str, strlen(str)); 00382 #ifdef USE_SSL 00383 } 00384 else { 00385 SSL_write(j->ssl, str, strlen(str)); 00386 } 00387 #endif /* USE_SSL */ 00388 dprintf(dJAB, "out: %s\n", str); 00389 }
|
|
Definition at line 169 of file jconn.c. References jabconn_struct::fd, jab_recv(), jab_send_raw(), jabconn, JABCONN_STATE_AUTH, JABCONN_STATE_CONNECTED, JABCONN_STATE_OFF, jabutil_header(), make_netsocket(), NETSOCKET_CLIENT, NS_CLIENT, NULL, jabconn_struct::parser, jabconn_struct::state, STATE_EVT, XML_ParserCreate(), XML_SetCharacterDataHandler(), XML_SetElementHandler(), XML_SetUserData(), xode, xode_free(), and xode_to_str(). Referenced by jabber_init(). 00170 { 00171 xode x; 00172 char *t, *t2; 00173 00174 if (!j || j->state != JABCONN_STATE_OFF) 00175 return; 00176 00177 j->parser = XML_ParserCreate(NULL); 00178 XML_SetUserData(j->parser, (void *) j); 00179 XML_SetElementHandler(j->parser, startElement, endElement); 00180 XML_SetCharacterDataHandler(j->parser, charData); 00181 00182 j->fd = make_netsocket(j->port, j->user->server, NETSOCKET_CLIENT); 00183 if (j->fd < 0) { 00184 STATE_EVT(JABCONN_STATE_OFF) 00185 return; 00186 } 00187 00188 #ifdef USE_SSL 00189 if (ssl && j->fd >= 0) { 00190 SSL_library_init(); 00191 SSL_load_error_strings(); 00192 j->ssl_ctx = SSL_CTX_new(SSLv23_client_method()); 00193 if (!j->ssl_ctx) { 00194 STATE_EVT(JABCONN_STATE_OFF) 00195 return; 00196 } 00197 j->ssl = (SSL *)SSL_new(j->ssl_ctx); 00198 if (!j->ssl) { 00199 STATE_EVT(JABCONN_STATE_OFF) 00200 return; 00201 } 00202 SSL_set_fd(j->ssl, j->fd); 00203 SSL_connect(j->ssl); 00204 j->sslfd = SSL_get_fd(j->ssl); 00205 if (j->sslfd < 0) { 00206 STATE_EVT(JABCONN_STATE_OFF) 00207 return; 00208 } 00209 } 00210 #endif /* USE_SSL */ 00211 00212 j->state = JABCONN_STATE_CONNECTED; 00213 STATE_EVT(JABCONN_STATE_CONNECTED) 00214 /* start stream */ 00215 x = jabutil_header(NS_CLIENT, j->user->server); 00216 t = xode_to_str(x); 00217 /* 00218 * this is ugly, we can create the string here instead of 00219 * jutil_header 00220 */ 00221 /* what do you think about it? -madcat */ 00222 t2 = strstr(t, "/>"); 00223 *t2++ = '>'; 00224 *t2 = '\0'; 00225 jab_send_raw(j, "<?xml version='1.0'?>"); 00226 jab_send_raw(j, t); 00227 xode_free(x); 00228 00229 jab_recv(j); 00230 00231 j->state = JABCONN_STATE_AUTH; 00232 STATE_EVT(JABCONN_STATE_AUTH); 00233 }
|
|
Definition at line 236 of file jconn.c. References jabconn, JABCONN_STATE_ON, jabconn_struct::state, and STATE_EVT. Referenced by jabber_init().
|
|
Definition at line 104 of file jconn.c. References jabconn, and jabconn_struct::on_state. Referenced by jabber_init(). 00105 { 00106 if (!j) 00107 return; 00108 00109 j->on_state = h; 00110 }
|
|
Definition at line 248 of file jconn.c. References jabconn_struct::dumpfd, jabconn_struct::dumpid, jabconn_struct::fd, jabconn, jabconn_struct::parser, jabconn_struct::state, and XML_ParserFree(). Referenced by jab_delete(), jab_recv(), and jabber_finalize(). 00249 { 00250 if (!j || j->state == JABCONN_STATE_OFF) 00251 return; 00252 00253 j->state = JABCONN_STATE_OFF; 00254 #ifdef USE_SSL 00255 SSL_CTX_free(j->ssl_ctx); 00256 SSL_free(j->ssl); 00257 j->ssl = NULL; 00258 j->sslfd = -1; 00259 #endif /* USE_SSL */ 00260 close(j->fd); 00261 j->fd = -1; 00262 j->dumpfd = -1; 00263 j->dumpid = NULL; 00264 XML_ParserFree(j->parser); 00265 }
|
|
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 48 of file jpacket.c. References _jabpacket, jabpacket, jabpacket_reset(), jabpacket_struct::x, xode, xode_get_pool(), and xode_pool_malloc(). 00049 { 00050 jabpacket p; 00051 00052 if (x == NULL) 00053 return NULL; 00054 00055 p = xode_pool_malloc(xode_get_pool(x), sizeof(_jabpacket)); 00056 p->x = x; 00057 00058 return jabpacket_reset(p); 00059 }
|
|
Definition at line 62 of file jpacket.c. References _jabpacket, jabpacket_struct::from, jabpacket_struct::iq, jabpacket_struct::iqns, jabpacket, jabpacket_subtype(), jid_new(), jabpacket_struct::p, jabpacket_struct::subtype, jabpacket_struct::to, jabpacket_struct::type, jabpacket_struct::x, xode, xode_get_attrib(), xode_get_name(), xode_get_pool(), and xode_get_tag(). Referenced by jab_on_packet_handler(), and jabpacket_new(). 00063 { 00064 char *val; 00065 xode x; 00066 00067 x = p->x; 00068 memset(p, 0, sizeof(_jabpacket)); 00069 p->x = x; 00070 p->p = xode_get_pool(x); 00071 00072 if (strncmp(xode_get_name(x), "message", 7) == 0) { 00073 p->type = JABPACKET_MESSAGE; 00074 } 00075 else if (strncmp(xode_get_name(x), "presence", 8) == 0) { 00076 p->type = JABPACKET_PRESENCE; 00077 } 00078 else if (strncmp(xode_get_name(x), "iq", 2) == 0) { 00079 p->type = JABPACKET_IQ; 00080 p->iq = xode_get_tag(x, "?xmlns"); 00081 p->iqns = xode_get_attrib(p->iq, "xmlns"); 00082 } 00083 00084 val = xode_get_attrib(x, "to"); 00085 if (val != NULL) 00086 if ((p->to = jid_new(p->p, val)) == NULL) 00087 p->type = JABPACKET_UNKNOWN; 00088 val = xode_get_attrib(x, "from"); 00089 if (val != NULL) 00090 if ((p->from = jid_new(p->p, val)) == NULL) 00091 p->type = JABPACKET_UNKNOWN; 00092 00093 p->subtype = JABPACKET__UNKNOWN; 00094 p->subtype = jabpacket_subtype(p); 00095 00096 return p; 00097 }
|
|
Definition at line 101 of file jpacket.c. References j_strcmp(), jabpacket, JABPACKET_IQ, JABPACKET_MESSAGE, JABPACKET_PRESENCE, jabpacket_struct::subtype, jabpacket_struct::type, jabpacket_struct::x, and xode_get_attrib(). Referenced by jabpacket_reset(). 00102 { 00103 char *type; 00104 int ret = p->subtype; 00105 00106 if (ret != JABPACKET__UNKNOWN) 00107 return ret; 00108 00109 ret = JABPACKET__NONE; 00110 type = xode_get_attrib(p->x, "type"); 00111 if (j_strcmp(type, "error") == 0) 00112 ret = JABPACKET__ERROR; 00113 else 00114 switch (p->type) { 00115 case JABPACKET_MESSAGE: 00116 if (j_strcmp(type, "chat") == 0) 00117 ret = JABPACKET__CHAT; 00118 else if (j_strcmp(type, "groupchat") == 0) 00119 ret = JABPACKET__GROUPCHAT; 00120 else if (j_strcmp(type, "headline") == 0) 00121 ret = JABPACKET__HEADLINE; 00122 else if (j_strcmp(type, "internal") == 0) 00123 ret = JABPACKET__INTERNAL; 00124 else 00125 ret = JABPACKET__UNKNOWN; 00126 break; 00127 00128 case JABPACKET_PRESENCE: 00129 if (type == NULL) 00130 ret = JABPACKET__AVAILABLE; 00131 else if (j_strcmp(type, "unavailable") == 0) 00132 ret = JABPACKET__UNAVAILABLE; 00133 else if (j_strcmp(type, "probe") == 0) 00134 ret = JABPACKET__PROBE; 00135 else if (j_strcmp(type, "error") == 0) 00136 ret = JABPACKET__ERROR; 00137 else if (j_strcmp(type, "invisible") == 0) 00138 ret = JABPACKET__INVISIBLE; 00139 else if (j_strcmp(type, "available") == 0) 00140 ret = JABPACKET__AVAILABLE; 00141 else if (j_strcmp(type, "online") == 0) 00142 ret = JABPACKET__AVAILABLE; 00143 else if (j_strcmp(type, "subscribe") == 0) 00144 ret = JABPACKET__SUBSCRIBE; 00145 else if (j_strcmp(type, "subscribed") == 0) 00146 ret = JABPACKET__SUBSCRIBED; 00147 else if (j_strcmp(type, "unsubscribe") == 0) 00148 ret = JABPACKET__UNSUBSCRIBE; 00149 else if (j_strcmp(type, "unsubscribed") == 0) 00150 ret = JABPACKET__UNSUBSCRIBED; 00151 else 00152 ret = JABPACKET__UNKNOWN; 00153 break; 00154 00155 case JABPACKET_IQ: 00156 if (j_strcmp(type, "get") == 0) 00157 ret = JABPACKET__GET; 00158 else if (j_strcmp(type, "set") == 0) 00159 ret = JABPACKET__SET; 00160 else if (j_strcmp(type, "result") == 0) 00161 ret = JABPACKET__RESULT; 00162 else 00163 ret = JABPACKET__UNKNOWN; 00164 break; 00165 } 00166 00167 return ret; 00168 }
|
|
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 }
|
|
Definition at line 291 of file jid.c. References jid, jid_cmp(), jid_full(), jid_new(), jid_struct::next, and jid_struct::p. 00292 { 00293 jid next; 00294 00295 if (a == NULL) 00296 return NULL; 00297 00298 if (b == NULL) 00299 return a; 00300 00301 next = a; 00302 while (next != NULL) { 00303 /* check for dups */ 00304 if (jid_cmp(next, b) == 0) 00305 break; 00306 if (next->next == NULL) 00307 next->next = jid_new(a->p, jid_full(b)); 00308 next = next->next; 00309 } 00310 return a; 00311 }
|
|
Definition at line 257 of file jid.c. References _jid_nullstrcasecmp(), _jid_nullstrcmp(), jid, NULL, jid_struct::resource, jid_struct::server, and jid_struct::user. Referenced by jid_append(), and jid_nodescan(). 00258 { 00259 if (a == NULL || b == NULL) 00260 return -1; 00261 00262 if (_jid_nullstrcmp(a->resource, b->resource) != 0) 00263 return -1; 00264 if (_jid_nullstrcasecmp(a->user, b->user) != 0) 00265 return -1; 00266 if (_jid_nullstrcmp(a->server, b->server) != 0) 00267 return -1; 00268 00269 return 0; 00270 }
|
|
Definition at line 274 of file jid.c. References _jid_nullstrcasecmp(), _jid_nullstrcmp(), jid, JID_RESOURCE, JID_SERVER, JID_USER, NULL, jid_struct::resource, jid_struct::server, and jid_struct::user. 00275 { 00276 if (a == NULL || b == NULL) 00277 return -1; 00278 00279 if (parts & JID_RESOURCE && _jid_nullstrcmp(a->resource, b->resource) != 0) 00280 return -1; 00281 if (parts & JID_USER && _jid_nullstrcasecmp(a->user, b->user) != 0) 00282 return -1; 00283 if (parts & JID_SERVER && _jid_nullstrcmp(a->server, b->server) != 0) 00284 return -1; 00285 00286 return 0; 00287 }
|
|
Definition at line 164 of file jid.c. References jid_struct::full, jid, jid_struct::p, jid_struct::resource, jid_struct::server, jid_struct::user, xode_spool, xode_spool_add(), xode_spool_newfrompool(), xode_spool_tostr(), and xode_spooler(). Referenced by jid_append(). 00165 { 00166 xode_spool s; 00167 00168 if (id == NULL) 00169 return NULL; 00170 00171 /* use cached copy */ 00172 if (id->full != NULL) 00173 return id->full; 00174 00175 s = xode_spool_newfrompool(id->p); 00176 00177 if (id->user != NULL) 00178 xode_spooler(s, id->user, "@", s); 00179 00180 xode_spool_add(s, id->server); 00181 00182 if (id->resource != NULL) 00183 xode_spooler(s, "/", id->resource, s); 00184 00185 id->full = xode_spool_tostr(s); 00186 return id->full; 00187 }
|
|
Definition at line 75 of file jid.c. References jid, jid_safe(), NULL, jid_struct::p, xode_pool, xode_pool_malloco(), and xode_pool_strdup(). Referenced by jab_new(), jabpacket_reset(), jid_append(), and jid_nodescan(). 00076 { 00077 char *server, *resource, *type, *str; 00078 jid id; 00079 00080 if (p == NULL || idstr == NULL || strlen(idstr) == 0) 00081 return NULL; 00082 00083 /* user@server/resource */ 00084 00085 str = xode_pool_strdup(p, idstr); 00086 00087 id = xode_pool_malloco(p, sizeof(struct jid_struct)); 00088 id->p = p; 00089 id->full = xode_pool_strdup(p, idstr); 00090 00091 resource = strstr(str, "/"); 00092 if (resource != NULL) { 00093 *resource = '\0'; 00094 ++resource; 00095 if (strlen(resource) > 0) 00096 id->resource = resource; 00097 } 00098 else { 00099 resource = str + strlen(str); /* point to end */ 00100 } 00101 00102 type = strstr(str, ":"); 00103 if (type != NULL && type < resource) { 00104 *type = '\0'; 00105 ++type; 00106 str = type; /* ignore the type: prefix */ 00107 } 00108 00109 server = strstr(str, "@"); 00110 if (server == NULL || server > resource) { /* if there's no @, it's 00111 * just the server 00112 * address */ 00113 id->server = str; 00114 } 00115 else { 00116 *server = '\0'; 00117 ++server; 00118 id->server = server; 00119 if (strlen(str) > 0) 00120 id->user = str; 00121 } 00122 00123 return jid_safe(id); 00124 }
|
|
Definition at line 314 of file jid.c. References jid, jid_cmp(), jid_new(), NULL, xode, xode_get_attrib(), xode_get_firstchild(), xode_get_nextsibling(), xode_get_type(), xode_pool, xode_pool_free(), and xode_pool_new(). 00315 { 00316 xode cur; 00317 xode_pool p; 00318 jid tmp; 00319 00320 if (id == NULL || xode_get_firstchild(x) == NULL) 00321 return NULL; 00322 00323 p = xode_pool_new(); 00324 for (cur = xode_get_firstchild(x); cur != NULL; cur = xode_get_nextsibling(cur)) { 00325 if (xode_get_type(cur) != XODE_TYPE_TAG) 00326 continue; 00327 00328 tmp = jid_new(p, xode_get_attrib(cur, "jid")); 00329 if (tmp == NULL) 00330 continue; 00331 00332 if (jid_cmp(tmp, id) == 0) 00333 break; 00334 } 00335 xode_pool_free(p); 00336 00337 return cur; 00338 }
|
|
Definition at line 127 of file jid.c. References jid_struct::full, jid, JID_RESOURCE, jid_safe(), JID_SERVER, JID_USER, NULL, jid_struct::p, jid_struct::resource, jid_struct::server, jid_struct::user, and xode_pool_strdup(). 00128 { 00129 char *old; 00130 00131 if (id == NULL) 00132 return; 00133 00134 /* invalidate the cached copy */ 00135 id->full = NULL; 00136 00137 switch (item) { 00138 case JID_RESOURCE: 00139 if (str != NULL && strlen(str) != 0) 00140 id->resource = xode_pool_strdup(id->p, str); 00141 else 00142 id->resource = NULL; 00143 break; 00144 case JID_USER: 00145 old = id->user; 00146 if (str != NULL && strlen(str) != 0) 00147 id->user = xode_pool_strdup(id->p, str); 00148 else 00149 id->user = NULL; 00150 if (jid_safe(id) == NULL) 00151 id->user = old; /* revert if invalid */ 00152 break; 00153 case JID_SERVER: 00154 old = id->server; 00155 id->server = xode_pool_strdup(id->p, str); 00156 if (jid_safe(id) == NULL) 00157 id->server = old; /* revert if invalid */ 00158 break; 00159 } 00160 00161 }
|
|
Definition at line 341 of file jid.c. References jid, NULL, jid_struct::p, jid_struct::resource, jid_struct::server, jid_struct::user, and xode_pool_malloco(). 00342 { 00343 jid ret; 00344 00345 if (a == NULL || a->resource == NULL) 00346 return a; 00347 00348 ret = xode_pool_malloco(a->p, sizeof(struct jid_struct)); 00349 ret->p = a->p; 00350 ret->user = a->user; 00351 ret->server = a->server; 00352 00353 return ret; 00354 }
|
|
Definition at line 194 of file jid.c. References jid, NULL, jid_struct::p, jid_struct::resource, xode, xode_new_frompool(), xode_pool_strdup(), and xode_put_attrib(). 00195 { 00196 char *cur, *qmark, *amp, *eq; 00197 xode x; 00198 00199 if (id == NULL || id->resource == NULL) 00200 return NULL; 00201 00202 cur = xode_pool_strdup(id->p, id->resource); 00203 qmark = strstr(cur, "?"); 00204 if (qmark == NULL) 00205 return NULL; 00206 *qmark = '\0'; 00207 qmark++; 00208 00209 x = xode_new_frompool(id->p, cur); 00210 00211 cur = qmark; 00212 while (cur != '\0') { 00213 eq = strstr(cur, "="); 00214 if (eq == NULL) 00215 break; 00216 *eq = '\0'; 00217 eq++; 00218 00219 amp = strstr(eq, "&"); 00220 if (amp != NULL) { 00221 *amp = '\0'; 00222 amp++; 00223 } 00224 00225 xode_put_attrib(x, cur, eq); 00226 00227 if (amp != NULL) 00228 cur = amp; 00229 else 00230 break; 00231 } 00232 00233 return x; 00234 }
|
Last updated at Tue Dec 18 21:07:42 PST 2007. | This site and project hosted by... |