PeerConnection * peer_connection_new(OscarData *od, guint64 type, const char *bn) { PeerConnection *conn; PurpleAccount *account; account = purple_connection_get_account(od->gc); conn = g_new0(PeerConnection, 1); conn->od = od; conn->type = type; conn->bn = g_strdup(bn); conn->buffer_outgoing = purple_circ_buffer_new(0); conn->listenerfd = -1; conn->fd = -1; conn->lastactivity = time(NULL); conn->use_proxy |= purple_account_get_bool(account, "always_use_rv_proxy", FALSE); if (type == OSCAR_CAPABILITY_DIRECTIM) memcpy(conn->magic, "ODC2", 4); else if (type == OSCAR_CAPABILITY_SENDFILE) memcpy(conn->magic, "OFT2", 4); od->peer_connections = g_slist_prepend(od->peer_connections, conn); return conn; }
MsnServConn * msn_servconn_new(MsnSession *session, MsnServConnType type) { MsnServConn *servconn; g_return_val_if_fail(session != NULL, NULL); servconn = g_new0(MsnServConn, 1); servconn->type = type; servconn->session = session; servconn->cmdproc = msn_cmdproc_new(session); servconn->cmdproc->servconn = servconn; servconn->httpconn = msn_httpconn_new(servconn); servconn->num = session->servconns_count++; servconn->tx_buf = purple_circ_buffer_new(MSN_BUF_LEN); servconn->tx_handler = 0; servconn->timeout_sec = 0; servconn->timeout_handle = 0; servconn->fd = -1; return servconn; }
static gint tcp_send_out(PurpleConnection *gc, guint8 *data, gint data_len) { qq_data *qd; qq_connection *conn; gint ret; g_return_val_if_fail(data != NULL && data_len > 0, -1); g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, -1); qd = (qq_data *) gc->proto_data; conn = connection_find(qd, qd->fd); g_return_val_if_fail(conn, -1); #if 0 purple_debug_info("TCP_SEND_OUT", "Send %d bytes to socket %d\n", data_len, qd->fd); #endif if (conn->can_write_handler == 0) { ret = write(qd->fd, data, data_len); } else { ret = -1; errno = EAGAIN; } /* purple_debug_info("TCP_SEND_OUT", "Socket %d, total %d bytes is sent %d\n", qd->fd, data_len, ret); */ if (ret < 0 && errno == EAGAIN) { /* socket is busy, send later */ purple_debug_info("TCP_SEND_OUT", "Socket is busy and send later\n"); ret = 0; } else if (ret <= 0) { /* TODO: what to do here - do we really have to disconnect? */ gchar *tmp = g_strdup_printf(_("Lost connection with server: %s"), g_strerror(errno)); purple_debug_error("TCP_SEND_OUT", "Send to socket %d failed: %d, %s\n", qd->fd, errno, g_strerror(errno)); purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, tmp); g_free(tmp); return ret; } if (ret < data_len) { purple_debug_info("TCP_SEND_OUT", "Add %d bytes to buffer\n", data_len - ret); if (conn->can_write_handler == 0) { conn->can_write_handler = purple_input_add(qd->fd, PURPLE_INPUT_WRITE, tcp_can_write, gc); } if (conn->tcp_txbuf == NULL) { conn->tcp_txbuf = purple_circ_buffer_new(4096); } purple_circ_buffer_append(conn->tcp_txbuf, data + ret, data_len - ret); } return ret; }
static void irc_login(PurpleAccount *account) { PurpleConnection *gc; struct irc_conn *irc; char **userparts; const char *username = purple_account_get_username(account); gc = purple_account_get_connection(account); gc->flags |= PURPLE_CONNECTION_NO_NEWLINES; if (strpbrk(username, " \t\v\r\n") != NULL) { purple_connection_error(gc, _("IRC nicks may not contain whitespace")); return; } gc->proto_data = irc = g_new0(struct irc_conn, 1); irc->fd = -1; irc->account = account; irc->outbuf = purple_circ_buffer_new(512); userparts = g_strsplit(username, "@", 2); purple_connection_set_display_name(gc, userparts[0]); irc->server = g_strdup(userparts[1]); g_strfreev(userparts); irc->buddies = g_hash_table_new_full((GHashFunc)irc_nick_hash, (GEqualFunc)irc_nick_equal, NULL, (GDestroyNotify)irc_buddy_free); irc->cmds = g_hash_table_new(g_str_hash, g_str_equal); irc_cmd_table_build(irc); irc->msgs = g_hash_table_new(g_str_hash, g_str_equal); irc_msg_table_build(irc); purple_connection_update_progress(gc, _("Connecting"), 1, 2); if (purple_account_get_bool(account, "ssl", FALSE)) { if (purple_ssl_is_supported()) { irc->gsc = purple_ssl_connect(account, irc->server, purple_account_get_int(account, "port", IRC_DEFAULT_SSL_PORT), irc_login_cb_ssl, irc_ssl_connect_failure, gc); } else { purple_connection_error(gc, _("SSL support unavailable")); return; } } if (!irc->gsc) { if (purple_proxy_connect(gc, account, irc->server, purple_account_get_int(account, "port", IRC_DEFAULT_PORT), irc_login_cb, gc) == NULL) { purple_connection_error(gc, _("Couldn't create socket")); return; } } }
PurpleBOSHConnection* jabber_bosh_connection_init(JabberStream *js, const char *url) { PurpleBOSHConnection *conn; char *host, *path, *user, *passwd; int port; if (!purple_url_parse(url, &host, &port, &path, &user, &passwd)) { purple_debug_info("jabber", "Unable to parse given URL.\n"); return NULL; } conn = g_new0(PurpleBOSHConnection, 1); conn->host = host; conn->port = port; conn->path = g_strdup_printf("/%s", path); g_free(path); conn->pipelining = TRUE; if (purple_ip_address_is_valid(host)) js->serverFQDN = g_strdup(js->user->domain); else js->serverFQDN = g_strdup(host); if ((user && user[0] != '\0') || (passwd && passwd[0] != '\0')) { purple_debug_info("jabber", "Ignoring unexpected username and password " "in BOSH URL.\n"); } g_free(user); g_free(passwd); conn->js = js; /* * Random 64-bit integer masked off by 2^52 - 1. * * This should produce a random integer in the range [0, 2^52). It's * unlikely we'll send enough packets in one session to overflow the rid. */ conn->rid = ((guint64)g_random_int() << 32) | g_random_int(); conn->rid &= 0xFFFFFFFFFFFFFLL; conn->pending = purple_circ_buffer_new(0 /* default grow size */); conn->state = BOSH_CONN_OFFLINE; if (purple_strcasestr(url, "https://") != NULL) conn->ssl = TRUE; else conn->ssl = FALSE; conn->connections[0] = jabber_bosh_http_connection_init(conn); return conn; }
static PurpleHTTPConnection* jabber_bosh_http_connection_init(PurpleBOSHConnection *bosh) { PurpleHTTPConnection *conn = g_new0(PurpleHTTPConnection, 1); conn->bosh = bosh; conn->fd = -1; conn->state = HTTP_CONN_OFFLINE; conn->write_buf = purple_circ_buffer_new(0 /* default grow size */); return conn; }
static BonjourJabberConversation * bonjour_jabber_conv_new(PurpleBuddy *pb, PurpleAccount *account, const char *ip) { BonjourJabberConversation *bconv = g_new0(BonjourJabberConversation, 1); bconv->socket = -1; bconv->tx_buf = purple_circ_buffer_new(512); bconv->tx_handler = 0; bconv->rx_handler = 0; bconv->pb = pb; bconv->account = account; bconv->ip = g_strdup(ip); bonjour_parser_setup(bconv); return bconv; }
/** * Allocate a new empty connection structure. * * @param od The oscar session associated with this connection. * @param type Type of connection to create * * @return Returns the new connection structure. */ FlapConnection * flap_connection_new(OscarData *od, int type) { FlapConnection *conn; conn = g_new0(FlapConnection, 1); conn->od = od; conn->buffer_outgoing = purple_circ_buffer_new(0); conn->fd = -1; conn->subtype = -1; conn->type = type; od->oscar_connections = g_slist_prepend(od->oscar_connections, conn); return conn; }
/** * Allocate a new empty connection structure. * * @param od The oscar session associated with this connection. * @param type Type of connection to create * * @return Returns the new connection structure. */ FlapConnection * flap_connection_new(OscarData *od, int type) { FlapConnection *conn; conn = g_new0(FlapConnection, 1); conn->od = od; conn->buffer_outgoing = purple_circ_buffer_new(0); conn->fd = -1; conn->subtype = -1; conn->type = type; conn->rateclass_members = g_hash_table_new(g_direct_hash, g_direct_equal); od->oscar_connections = g_slist_prepend(od->oscar_connections, conn); return conn; }
MsnHttpConn * msn_httpconn_new(MsnServConn *servconn) { MsnHttpConn *httpconn; g_return_val_if_fail(servconn != NULL, NULL); httpconn = g_new0(MsnHttpConn, 1); purple_debug_info("msn", "new httpconn (%p)\n", httpconn); /* TODO: Remove this */ httpconn->session = servconn->session; httpconn->servconn = servconn; httpconn->tx_buf = purple_circ_buffer_new(MSN_BUF_LEN); httpconn->tx_handler = 0; return httpconn; }
NPHttpConn * np_httpconn_new(NPServConn *servconn) { NPHttpConn *httpconn; g_return_val_if_fail(servconn != NULL, NULL); httpconn = g_new0(NPHttpConn, 1); // purple_debug_info("np", "new httpconn (%p)\n", httpconn); /* TODO: Remove this */ httpconn->session = servconn->session; httpconn->servconn = servconn; httpconn->tx_buf = purple_circ_buffer_new(NP_BUF_LEN); httpconn->tx_handler = 0; httpconn->fd = -1; return httpconn; }
void fetion_login(PurpleAccount * account) { PurpleConnection *gc; struct fetion_account_data *sip; gchar **userserver; gint ret; const char *username = purple_account_get_username(account); gc = purple_account_get_connection(account); gc->proto_data = sip = g_new0(struct fetion_account_data, 1); sip->gc = gc; sip->tg = 0; //temp group chat id sip->cseq = 0; sip->account = account; sip->registerexpire = 400; sip->reregister = time(NULL) + 100; sip->txbuf = purple_circ_buffer_new(0); sip->impresa = NULL; sip->icon_buf = purple_circ_buffer_new(0); sip->GetContactFlag = 0; purple_debug_info("Fetion:", "shit\n"); userserver = g_strsplit(username, "@", 2); purple_connection_set_display_name(gc, userserver[0]); if (IsCMccNo(userserver[0])) { sip->username = NULL; sip->mobileno = g_strdup(userserver[0]); } else { sip->mobileno = NULL; sip->username = g_strdup(userserver[0]); } // sip->servername = g_strdup(userserver[1]); sip->SysCfgServer = g_strdup("nav.fetion.com.cn"); sip->password = g_strdup(purple_connection_get_password(gc)); g_strfreev(userserver); sip->buddies = g_hash_table_new((GHashFunc) fetion_ht_hash_nick, (GEqualFunc) fetion_ht_equals_nick); sip->tempgroup = g_hash_table_new((GHashFunc) fetion_ht_hash_nick, (GEqualFunc) fetion_ht_equals_nick); sip->group = g_hash_table_new((GHashFunc) fetion_ht_hash_nick, (GEqualFunc) fetion_ht_equals_nick); sip->group2id = g_hash_table_new((GHashFunc) fetion_ht_hash_nick, (GEqualFunc) fetion_ht_equals_nick); purple_connection_update_progress(gc, _("Connecting"), 1, 2); /* TODO: Set the status correctly. */ sip->status = g_strdup("available"); sip->registertimeout = purple_timeout_add(60000, (GSourceFunc) LoginToSsiPortal, sip); //Try to get systemconfig sip->ServerVersion = NULL; sip->ServiceNoVersion = NULL; sip->ParaVersion = NULL; sip->HttpAppVersion = NULL; sip->ClientCfgVersion = NULL; sip->HintsVersion = NULL; ret = ParseCfg(sip); //if(ret!=0) sip->SysCfg.conn = purple_proxy_connect(NULL, sip->account, sip->SysCfgServer, 80, (PurpleProxyConnectFunction) RetriveSysCfg, sip); }
static void peer_connection_close(PeerConnection *conn) { if (conn->type == OSCAR_CAPABILITY_DIRECTIM) peer_odc_close(conn); else if (conn->type == OSCAR_CAPABILITY_SENDFILE) peer_oft_close(conn); if (conn->verified_connect_data != NULL) { purple_proxy_connect_cancel(conn->verified_connect_data); conn->verified_connect_data = NULL; } if (conn->client_connect_data != NULL) { purple_proxy_connect_cancel(conn->client_connect_data); conn->client_connect_data = NULL; } if (conn->listen_data != NULL) { purple_network_listen_cancel(conn->listen_data); conn->listen_data = NULL; } if (conn->connect_timeout_timer != 0) { purple_timeout_remove(conn->connect_timeout_timer); conn->connect_timeout_timer = 0; } if (conn->watcher_incoming != 0) { purple_input_remove(conn->watcher_incoming); conn->watcher_incoming = 0; } if (conn->watcher_outgoing != 0) { purple_input_remove(conn->watcher_outgoing); conn->watcher_outgoing = 0; } if (conn->listenerfd >= 0) { close(conn->listenerfd); conn->listenerfd = -1; } if (conn->fd >= 0) { close(conn->fd); conn->fd = -1; } g_free(conn->buffer_incoming.data); conn->buffer_incoming.data = NULL; conn->buffer_incoming.len = 0; conn->buffer_incoming.offset = 0; purple_circ_buffer_destroy(conn->buffer_outgoing); conn->buffer_outgoing = purple_circ_buffer_new(0); conn->flags &= ~PEER_CONNECTION_FLAG_IS_INCOMING; }