|
| |||||||||||||
#include "libjabber.h"Go to the source code of this file.
Defines | |
| #define | STATE_EVT(arg) if(j->on_state) { (j->on_state)(j, (arg) ); } |
Functions | |
| jabconn | jab_new (char *user, char *pass) |
| void | jab_delete (jabconn j) |
| void | jab_state_handler (jabconn j, jabconn_state_h h) |
| void | jab_packet_handler (jabconn j, jabconn_packet_h h) |
| void | jab_start (jabconn j, int ssl) |
| void | jab_startup (jabconn j) |
| void | jab_stop (jabconn j) |
| int | jab_getfd (jabconn j) |
| jid | jab_getjid (jabconn j) |
| char * | jab_getsid (jabconn j) |
| char * | jab_getid (jabconn j) |
| void | jab_send (jabconn j, xode x) |
| void | jab_send_raw (jabconn j, const char *str) |
| void | jab_recv (jabconn j) |
| void | jab_poll (jabconn j, int timeout) |
| char * | jab_auth (jabconn j) |
| char * | jab_reg (jabconn j) |
|
|
Definition at line 26 of file jconn.c. Referenced by jab_recv(), jab_reg(), jab_start(), and jab_startup(). |
|
|
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, jid_struct::user, jabconn_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 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, jid_struct::user, jabconn_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 }
|
| Last updated at Tue Dec 18 21:07:42 PST 2007. | This site and project hosted by... |