Changes in protocols/jabber/jabber.c [75a4b85:75cde5d]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/jabber.c
r75a4b85 r75cde5d 471 471 } 472 472 473 static gboolean jabber_callback(gpointer data, gint source, b_input_condition condition)473 static void jabber_callback(gpointer data, gint source, GaimInputCondition condition) 474 474 { 475 475 struct gaim_connection *gc = (struct gaim_connection *)data; … … 477 477 478 478 gjab_recv(jd->gjc); 479 480 return TRUE;481 479 } 482 480 … … 489 487 } 490 488 491 static gboolean gjab_connected(gpointer data, gint source, b_input_condition cond)489 static void gjab_connected(gpointer data, gint source, GaimInputCondition cond) 492 490 { 493 491 xmlnode x; … … 499 497 if (!g_slist_find(get_connections(), gc)) { 500 498 closesocket(source); 501 return FALSE;499 return; 502 500 } 503 501 … … 510 508 if (source == -1) { 511 509 STATE_EVT(JCONN_STATE_OFF) 512 return FALSE;510 return; 513 511 } 514 512 … … 532 530 533 531 gc = GJ_GC(gjc); 534 gc->inpa = b_input_add(gjc->fd, GAIM_INPUT_READ, jabber_callback, gc); 535 536 return FALSE; 537 } 538 539 static gboolean gjab_connected_ssl(gpointer data, void *source, b_input_condition cond) 532 gc->inpa = gaim_input_add(gjc->fd, GAIM_INPUT_READ, jabber_callback, gc); 533 } 534 535 static void gjab_connected_ssl(gpointer data, void *source, GaimInputCondition cond) 540 536 { 541 537 struct gaim_connection *gc = data; … … 548 544 if (source == NULL) { 549 545 STATE_EVT(JCONN_STATE_OFF) 550 return FALSE;546 return; 551 547 } 552 548 553 549 if (!g_slist_find(get_connections(), gc)) { 554 550 ssl_disconnect(source); 555 return FALSE;551 return; 556 552 } 557 553 558 returngjab_connected(data, gjc->fd, cond);554 gjab_connected(data, gjc->fd, cond); 559 555 } 560 556 561 557 static void gjab_start(gjconn gjc) 562 558 { 563 account_t *acc;559 struct aim_user *user; 564 560 int port = -1, ssl = 0; 565 char *server = NULL ;561 char *server = NULL, *s; 566 562 567 563 if (!gjc || gjc->state != JCONN_STATE_OFF) 568 564 return; 569 565 570 acc = GJ_GC(gjc)->acc; 571 server = acc->server; 572 port = set_getint(&acc->set, "port"); 573 ssl = set_getbool(&acc->set, "ssl"); 566 user = GJ_GC(gjc)->user; 567 if (*user->proto_opt[0]) { 568 /* If there's a dot, assume there's a hostname in the beginning */ 569 if (strchr(user->proto_opt[0], '.')) { 570 server = g_strdup(user->proto_opt[0]); 571 if ((s = strchr(server, ':'))) 572 *s = 0; 573 } 574 575 /* After the hostname, there can be a port number */ 576 s = strchr(user->proto_opt[0], ':'); 577 if (s && isdigit(s[1])) 578 sscanf(s + 1, "%d", &port); 579 580 /* And if there's the string ssl, the user wants an SSL-connection */ 581 if (strstr(user->proto_opt[0], ":ssl") || g_strcasecmp(user->proto_opt[0], "ssl") == 0) 582 ssl = 1; 583 } 574 584 575 if (port < JABBER_PORT_MIN || port > JABBER_PORT_MAX) { 585 if (port == -1 && !ssl) 586 port = DEFAULT_PORT; 587 else if (port == -1 && ssl) 588 port = DEFAULT_PORT_SSL; 589 else if (port < JABBER_PORT_MIN || port > JABBER_PORT_MAX) { 576 590 serv_got_crap(GJ_GC(gjc), "For security reasons, the Jabber port number must be in the %d-%d range.", JABBER_PORT_MIN, JABBER_PORT_MAX); 577 591 STATE_EVT(JCONN_STATE_OFF) … … 596 610 } 597 611 598 if (!acc->gc || (gjc->fd < 0)) { 612 g_free(server); 613 614 if (!user->gc || (gjc->fd < 0)) { 599 615 STATE_EVT(JCONN_STATE_OFF) 600 616 return; … … 1496 1512 } 1497 1513 1498 static void jabber_acc_init(account_t *acc) 1499 { 1500 set_t *s; 1501 1502 s = set_add( &acc->set, "port", "5222", set_eval_int, acc ); 1503 s->flags |= ACC_SET_OFFLINE_ONLY; 1504 1505 s = set_add( &acc->set, "resource", "BitlBee", NULL, acc ); 1506 s->flags |= ACC_SET_OFFLINE_ONLY; 1507 1508 s = set_add( &acc->set, "server", NULL, set_eval_account, acc ); 1509 s->flags |= ACC_SET_NOSAVE | ACC_SET_OFFLINE_ONLY; 1510 1511 s = set_add( &acc->set, "ssl", "false", set_eval_bool, acc ); 1512 s->flags |= ACC_SET_OFFLINE_ONLY; 1513 } 1514 1515 static void jabber_login(account_t *acc) 1516 { 1517 struct gaim_connection *gc; 1518 struct jabber_data *jd; 1519 char *resource, *loginname; 1520 1521 /* Time to move some data/things from the old syntax to the new one: */ 1522 if (acc->server) { 1523 char *s, *tmp_server; 1524 int port; 1525 1526 if (g_strcasecmp(acc->server, "ssl") == 0) { 1527 set_setstr(&acc->set, "server", ""); 1528 set_setint(&acc->set, "port", DEFAULT_PORT_SSL); 1529 set_setstr(&acc->set, "ssl", "true"); 1530 1531 g_free(acc->server); 1532 acc->server = NULL; 1533 } else if ((s = strchr(acc->server, ':'))) { 1534 if (strstr(acc->server, ":ssl")) { 1535 set_setint(&acc->set, "port", DEFAULT_PORT_SSL); 1536 set_setstr(&acc->set, "ssl", "true"); 1537 } 1538 if (isdigit(s[1])) { 1539 if (sscanf(s + 1, "%d", &port) == 1) 1540 set_setint(&acc->set, "port", port); 1541 } 1542 tmp_server = g_strndup(acc->server, s - acc->server); 1543 set_setstr(&acc->set, "server", tmp_server); 1544 g_free(tmp_server); 1545 } 1546 } 1547 1548 gc = new_gaim_conn(acc); 1549 jd = gc->proto_data = g_new0(struct jabber_data, 1); 1550 1551 if( strchr( acc->user, '@' ) == NULL ) 1552 { 1553 hide_login_progress( gc, "Invalid account name" ); 1554 signoff( gc ); 1555 return; 1556 } 1557 1558 resource = set_getstr(&acc->set, "resource"); 1559 loginname = create_valid_jid(acc->user, DEFAULT_SERVER, resource); 1560 1514 static void jabber_login(struct aim_user *user) 1515 { 1516 struct gaim_connection *gc = new_gaim_conn(user); 1517 struct jabber_data *jd = gc->proto_data = g_new0(struct jabber_data, 1); 1518 char *loginname = create_valid_jid(user->username, DEFAULT_SERVER, "BitlBee"); 1519 1561 1520 jd->hash = g_hash_table_new(g_str_hash, g_str_equal); 1562 1521 jd->chats = NULL; /* we have no chats yet */ … … 1564 1523 set_login_progress(gc, 1, _("Connecting")); 1565 1524 1566 if (!(jd->gjc = gjab_new(loginname, acc->pass, gc))) {1525 if (!(jd->gjc = gjab_new(loginname, user->password, gc))) { 1567 1526 g_free(loginname); 1568 1527 hide_login_progress(gc, _("Unable to connect")); … … 1584 1543 } 1585 1544 1586 static gboolean jabber_free(gpointer data , gint fd, b_input_condition cond)1545 static gboolean jabber_free(gpointer data) 1587 1546 { 1588 1547 struct jabber_data *jd = data; … … 1629 1588 } 1630 1589 if (gc->inpa) 1631 b_event_remove(gc->inpa);1590 gaim_input_remove(gc->inpa); 1632 1591 1633 1592 if(jd) { 1634 b_timeout_add(50, jabber_free, jd);1593 g_timeout_add(50, jabber_free, jd); 1635 1594 if(jd->gjc != NULL) 1636 1595 xmlnode_free(jd->gjc->current); … … 2374 2333 ret->name = "jabber"; 2375 2334 ret->away_states = jabber_away_states; 2376 ret->acc_init = jabber_acc_init;2377 2335 ret->login = jabber_login; 2378 2336 ret->close = jabber_close; … … 2387 2345 ret->alias_buddy = jabber_roster_update; 2388 2346 ret->group_buddy = jabber_group_change; 2389 ret-> handle_cmp= g_strcasecmp;2347 ret->cmp_buddynames = g_strcasecmp; 2390 2348 2391 2349 register_protocol (ret);
Note: See TracChangeset
for help on using the changeset viewer.