gboolean Ssi_cb(gpointer sodata, PurpleSslConnection * gsc, gint con) { gchar *head; struct fetion_account_data *sip; // Modified from codes of open-fetion char noUri[128]; char verifyUri[256]; char *password; int passwordType; sip = sodata; purple_debug_info("Fetion:", "Ssi_cb\n"); /*purple_debug_info("Fetion:", "Initialize ssi authentication action\n");*/ password = hash_password_v4(NULL , sip->password); /*password = hash_password_v4(sip->userId , sip->password);*/ memset(noUri, 0, sizeof(noUri)); if(sip->mobileno != NULL) sprintf(noUri , "mobileno=%s" , sip->mobileno); else sprintf(noUri , "sid=%s" , sip->username); memset(verifyUri, 0, sizeof(verifyUri)); /*if(user->verification != NULL && user->verification->code != NULL)*/ /*{*/ /*sprintf(verifyUri , "&pid=%s&pic=%s&algorithm=%s"*/ /*, user->verification->guid*/ /*, user->verification->code*/ /*, user->verification->algorithm);*/ /*}*/ /*passwordType = (strlen(sip->userId) == 0 ? 1 : 2);*/ passwordType = 1; head = g_strdup_printf( "GET /ssiportal/SSIAppSignInV4.aspx?%s" "&domains=fetion.com.cn%s&v4digest-type=%d&v4digest=%s\r\n" "User-Agent: IIC2.0/pc "PROTO_VERSION"\r\n" "Host: %s\r\n" "Cache-Control: private\r\n" "Connection: Keep-Alive\r\n\r\n", noUri , verifyUri , passwordType , password , "uid.fetion.com.cn"); /*if (sip->mobileno != NULL) {*/ /*head =*/ /*g_strdup_printf*/ /*("GET /ssiportal/SSIAppSignIn.aspx?mobileno=%s&pwd=%s HTTP/1.1\r\n"*/ /*"User-Agent: IIC2.0/pc 3.3.0370\r\n" "Host: %s\r\n"*/ /*"Connection: Keep-Alive\r\n\r\n", sip->mobileno,*/ /*sip->password, sip->SsicServer);*/ /*} else {*/ /*head =*/ /*g_strdup_printf*/ /*("GET /ssiportal/SSIAppSignIn.aspx?sid=%s&pwd=%s HTTP/1.1\r\n"*/ /*"User-Agent: IIC2.0/pc 3.3.0370\r\n" "Host: %s\r\n"*/ /*"Connection: Keep-Alive\r\n\r\n", sip->username,*/ /*sip->password, sip->SsicServer);*/ /*}*/ purple_ssl_write(gsc, head, strlen(head)); purple_ssl_input_add(gsc, (PurpleSslInputFunction) read_cookie, sip); return TRUE; }
static void nexus_write_cb(gpointer data, gint source, PurpleInputCondition cond) { MsnNexus *nexus = data; gssize len, total_len; total_len = strlen(nexus->write_buf); len = purple_ssl_write(nexus->gsc, nexus->write_buf + nexus->written_len, total_len - nexus->written_len); if (len < 0 && errno == EAGAIN) return; else if (len <= 0) { purple_input_remove(nexus->input_handler); nexus->input_handler = 0; /* TODO: notify of the error */ return; } nexus->written_len += len; if (nexus->written_len < total_len) return; purple_input_remove(nexus->input_handler); nexus->input_handler = 0; g_free(nexus->write_buf); nexus->write_buf = NULL; nexus->written_len = 0; nexus->written_cb(nexus, source, 0); }
gboolean Ssi_cb(gpointer sodata, PurpleSslConnection * gsc, gint con) { gchar *head; struct fetion_account_data *sip; sip = sodata; purple_debug_info("Fetion:", "Ssi_cb\n"); if (sip->mobileno != NULL) { head = g_strdup_printf ("GET /ssiportal/SSIAppSignIn.aspx?mobileno=%s&pwd=%s HTTP/1.1\r\n" "User-Agent: IIC2.0/pc 3.3.0370\r\n" "Host: %s\r\n" "Connection: Keep-Alive\r\n\r\n", sip->mobileno, sip->password, sip->SsicServer); } else { head = g_strdup_printf ("GET /ssiportal/SSIAppSignIn.aspx?sid=%s&pwd=%s HTTP/1.1\r\n" "User-Agent: IIC2.0/pc 3.3.0370\r\n" "Host: %s\r\n" "Connection: Keep-Alive\r\n\r\n", sip->username, sip->password, sip->SsicServer); } purple_ssl_write(gsc, head, strlen(head)); purple_ssl_input_add(gsc, (PurpleSslInputFunction) read_cookie, sip); return TRUE; }
static void skypeweb_xfer_send_connect_cb(gpointer user_data, PurpleSslConnection *ssl_connection, PurpleInputCondition cond) { SkypeWebFileTransfer *swft = user_data; SkypeWebAccount *sa = swft->sa; PurpleXfer *xfer = swft->xfer; gchar *headers; headers = g_strdup_printf("PUT /v1/objects/%s/content/original HTTP/1.0\r\n" "Connection: close\r\n" "Authorization: skype_token %s\r\n" //slightly different to normal! "Host: " SKYPEWEB_XFER_HOST "\r\n" "Content-Length: %d\r\n" "Content-Type: application/json\r\n" "\r\n\r\n", purple_url_encode(swft->id), sa->skype_token, purple_xfer_get_size(xfer)); purple_ssl_write(ssl_connection, headers, strlen(headers)); swft->conn = ssl_connection; purple_xfer_ref(xfer); purple_xfer_start(xfer, ssl_connection->fd, NULL, 0); //TODO add input watcher that calls this repeatedly purple_xfer_prpl_ready(xfer); //purple_ssl_input_add( g_free(headers); }
void waprpl_ssl_output_cb(gpointer data, gint source, PurpleInputCondition cond) { PurpleConnection *gc = data; whatsapp_connection *wconn = purple_connection_get_protocol_data(gc); char tempbuff[1024]; int ret; do { int datatosend = waAPI_sslsendcb(wconn->waAPI, tempbuff, sizeof(tempbuff)); if (datatosend == 0) break; ret = purple_ssl_write(wconn->gsc, tempbuff, datatosend); if (ret > 0) { waAPI_sslsenddone(wconn->waAPI, ret); } else if (ret == 0 || (ret < 0 && errno == EAGAIN)) { /* Check later */ } else { waprpl_ssl_cerr_cb(0, 0, gc); } } while (ret > 0); /* Check if we need to callback again or not */ waprpl_check_ssl_output(gc); }
static gssize skypeweb_xfer_send_write(const guchar *buf, size_t len, PurpleXfer *xfer) { SkypeWebFileTransfer *swft = purple_xfer_get_protocol_data(xfer); SkypeWebAccount *sa = swft->sa; return purple_ssl_write(swft->conn, buf, len); }
static int do_send(struct irc_conn *irc, const char *buf, gsize len) { int ret; if (irc->gsc) { ret = purple_ssl_write(irc->gsc, buf, len); } else { ret = write(irc->fd, buf, len); } return ret; }
static int http_connection_do_send(PurpleHTTPConnection *conn, const char *data, int len) { int ret; if (conn->psc) ret = purple_ssl_write(conn->psc, data, len); else ret = write(conn->fd, data, len); return ret; }
gssize purple_socket_write(PurpleSocket *ps, const guchar *buf, size_t len) { g_return_val_if_fail(ps != NULL, -1); g_return_val_if_fail(buf != NULL, -1); if (!purple_socket_check_state(ps, PURPLE_SOCKET_STATE_CONNECTED)) return -1; if (ps->is_tls) return purple_ssl_write(ps->tls_connection, buf, len); else return write(ps->fd, buf, len); }
static int http_connection_do_send(PurpleHTTPConnection *conn, const char *data, int len) { int ret; if (conn->psc) ret = purple_ssl_write(conn->psc, data, len); else ret = write(conn->fd, data, len); if (purple_debug_is_verbose()) purple_debug_misc("jabber", "BOSH (%p): wrote %d bytes\n", conn, ret); return ret; }
static void skypeweb_post_or_get_ssl_connect_cb(gpointer data, PurpleSslConnection *ssl, PurpleInputCondition cond) { SkypeWebConnection *skypewebcon; gssize len; skypewebcon = data; purple_debug_info("skypeweb", "post_or_get_ssl_connect_cb\n"); /* TODO: Check the return value of write() */ len = purple_ssl_write(skypewebcon->ssl_conn, skypewebcon->request->str, skypewebcon->request->len); purple_ssl_input_add(skypewebcon->ssl_conn, skypeweb_post_or_get_ssl_readdata_cb, skypewebcon); }
static void fb_post_or_get_ssl_connect_cb(gpointer data, PurpleSslConnection *ssl, PurpleInputCondition cond) { FacebookConnection *fbconn; ssize_t len; fbconn = data; purple_debug_info("facebook", "post_or_get_ssl_connect_cb\n"); /* TODO: Check the return value of write() */ len = purple_ssl_write(fbconn->ssl_conn, fbconn->request->str, fbconn->request->len); purple_ssl_input_add(fbconn->ssl_conn, fb_post_or_get_ssl_readdata_cb, fbconn); }
static void om_post_or_get_ssl_connect_cb(gpointer data, PurpleSslConnection *ssl, PurpleInputCondition cond) { OmegleConnection *omconn; ssize_t len; omconn = data; purple_debug_info("omegle", "post_or_get_ssl_connect_cb\n"); /* TODO: Check the return value of write() */ len = purple_ssl_write(omconn->ssl_conn, omconn->request->str, omconn->request->len); purple_ssl_input_add(omconn->ssl_conn, om_post_or_get_ssl_readdata_cb, omconn); }
static void sevencup_post_or_get_ssl_connect_cb(gpointer data, PurpleSslConnection *ssl, PurpleInputCondition cond) { SevenCupConnection *scon; gssize len; scon = data; purple_debug_info("7cups", "post_or_get_ssl_connect_cb\n"); /* TODO: Check the return value of write() */ len = purple_ssl_write(scon->ssl_conn, scon->request->str, scon->request->len); purple_ssl_input_add(scon->ssl_conn, sevencup_post_or_get_ssl_readdata_cb, scon); }
/** * @param source When this function is called as a callback source is * set to the fd that triggered the callback. But this function * is also called directly from flap_connection_send_byte_stream(), * in which case source will be -1. So don't use source--use * conn->gsc or conn->fd instead. */ static void send_cb(gpointer data, gint source, PurpleInputCondition cond) { FlapConnection *conn; int writelen, ret; const gchar *output = NULL; conn = data; writelen = purple_circular_buffer_get_max_read(conn->buffer_outgoing); output = purple_circular_buffer_get_output(conn->buffer_outgoing); if (writelen == 0) { purple_input_remove(conn->watcher_outgoing); conn->watcher_outgoing = 0; return; } if (conn->gsc) ret = purple_ssl_write(conn->gsc, output, writelen); else ret = send(conn->fd, output, writelen, 0); if (ret <= 0) { if (ret < 0 && (errno == EAGAIN || errno == EWOULDBLOCK)) /* No worries */ return; /* Error! */ purple_input_remove(conn->watcher_outgoing); conn->watcher_outgoing = 0; if (conn->gsc) { purple_ssl_close(conn->gsc); conn->gsc = NULL; } else { close(conn->fd); conn->fd = -1; } flap_connection_schedule_destroy(conn, OSCAR_DISCONNECT_LOST_CONNECTION, g_strerror(errno)); return; } purple_circular_buffer_mark_read(conn->buffer_outgoing, ret); }
static gboolean msn_soap_write_cb_internal(gpointer data, gint fd, PurpleInputCondition cond, gboolean initial) { MsnSoapConnection *conn = data; int written; if (cond != PURPLE_INPUT_WRITE) return TRUE; written = purple_ssl_write(conn->ssl, conn->buf->str + conn->handled_len, conn->buf->len - conn->handled_len); if (written < 0 && errno == EAGAIN) return TRUE; else if (written <= 0) { purple_ssl_close(conn->ssl); conn->ssl = NULL; if (!initial) msn_soap_connection_handle_next(conn); return FALSE; } conn->handled_len += written; if (conn->handled_len < conn->buf->len) return TRUE; /* we are done! */ g_string_free(conn->buf, TRUE); conn->buf = NULL; conn->handled_len = 0; conn->body_len = 0; conn->response_code = 0; conn->headers_done = FALSE; conn->close_when_done = FALSE; purple_input_remove(conn->event_handle); conn->event_handle = purple_input_add(conn->ssl->fd, PURPLE_INPUT_READ, msn_soap_read_cb, conn); return TRUE; }
static void fb_mqtt_cb_write(gpointer data, gint fd, PurpleInputCondition cond) { FbMqtt *mqtt = data; FbMqttPrivate *priv = mqtt->priv; gssize wize; wize = purple_ssl_write(priv->gsc, priv->wbuf->data, priv->wbuf->len); if (wize < 0) { fb_mqtt_error(mqtt, FB_MQTT_ERROR_GENERAL, _("Failed to write data")); return; } if (wize > 0) { g_byte_array_remove_range(priv->wbuf, 0, wize); } if (priv->wbuf->len < 1) { priv->wev = 0; } }
static void pb_socket_connected(gpointer userdata, PurpleSslConnection *conn, PurpleInputCondition cond) { PushBulletAccount *pba = userdata; gchar *websocket_header; const gchar *websocket_key = "15XF+ptKDhYVERXoGcdHTA=="; //TODO don't be lazy purple_ssl_input_add(pba->websocket, pb_socket_got_data, pba); websocket_header = g_strdup_printf("GET /subscribe/%s HTTP/1.1\r\n" "Host: stream.pushbullet.com\r\n" "Connection: Upgrade\r\n" "Pragma: no-cache\r\n" "Cache-Control: no-cache\r\n" "Upgrade: websocket\r\n" "Sec-WebSocket-Version: 13\r\n" "Sec-WebSocket-Key: %s\r\n" //"Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits\r\n" "\r\n", pba->access_token, websocket_key); purple_ssl_write(pba->websocket, websocket_header, strlen(websocket_header)); g_free(websocket_header); }
void campfire_ssl_handler(CampfireConn * campfire, PurpleSslConnection * gsc, PurpleInputCondition cond) { GList *first = g_list_first(campfire->queue); CampfireSslTransaction *xaction = NULL; gint status; gboolean close_ssl = FALSE; gboolean cleanup = TRUE; if (first) { xaction = first->data; } else { xaction = g_new0(CampfireSslTransaction, 1); campfire->num_xaction_malloc++; /* valgrind investigation */ purple_debug_info("campfire", "%s: xaction: %p, campfire->num_xaction_malloc:%d\n", __FUNCTION__, xaction, campfire->num_xaction_malloc); xaction->campfire = campfire; } purple_debug_info("campfire", "%s: first: %p\n", __FUNCTION__, first); status = campfire_http_response(gsc, xaction, cond, &(xaction->xml_response)); purple_debug_info("campfire", "http status: %d\n", status); if (status == 200 || status == 201) { xaction->xml_response = xmlnode_from_str(xaction->http_response.content->str, -1); if (xaction && xaction->response_cb) { purple_debug_info("campfire", "calling response_cb (%p)\n", xaction->response_cb); xaction->response_cb(xaction, gsc, cond); } cleanup = TRUE; } else if (status == 0) { /*received partial content */ cleanup = FALSE; } else { /*status < 0 or some other http status we don't expect */ close_ssl = TRUE; cleanup = TRUE; } if (close_ssl && campfire->gsc) { purple_debug_info("campfire", "closing ssl connection:%p (%p)\n", gsc, campfire->gsc); campfire->gsc = NULL; purple_ssl_close(gsc); cleanup = TRUE; } if (cleanup) { campfire_xaction_free(xaction); if (first) { purple_debug_info("campfire", "removing from queue: length: %d\n", g_list_length(campfire->queue)); campfire->queue = g_list_remove(campfire->queue, xaction); purple_debug_info("campfire", "removed from queue: length: %d\n", g_list_length(campfire->queue)); } first = g_list_first(campfire->queue); if (first) { xaction = first->data; purple_debug_info("campfire", "writing subsequent request on ssl connection\n"); purple_ssl_write(gsc, xaction->http_request->str, xaction->http_request->len); } } }
static void campfire_ssl_connect(CampfireConn * campfire, G_GNUC_UNUSED PurpleInputCondition cond, gboolean from_connection_callback) { GList *first = NULL; CampfireSslTransaction *xaction = NULL; purple_debug_info("campfire", "%s\n", __FUNCTION__); if (!campfire) { return; } else { first = g_list_first(campfire->queue); } if (!first) { return; } else { xaction = first->data; } if (!xaction) { return; } if (!campfire->gsc) { purple_debug_info("campfire", "new ssl connection\n"); campfire->gsc = purple_ssl_connect(campfire->account, campfire->hostname, 443, (PurpleSslInputFunction) (campfire_ssl_connect_cb), campfire_ssl_failure, campfire); purple_debug_info("campfire", "new ssl connection kicked off.\n"); } else { purple_debug_info("campfire", "previous ssl connection\n"); /* we want to write our http request to the ssl connection * WHENEVER this is called from the callback (meaning we've * JUST NOW established the connection). OR when the first * transaction is added to the queue on an OPEN ssl connection */ if (from_connection_callback || g_list_length(campfire->queue) == 1) { /* campfire_ssl_handler is the ONLY input handler we * EVER use So... if there is already an input handler * present (inpa > 0), then we DON"T want to add another * input handler. Quite a few hours spent chasing bugs * when multiple input handlers were added! */ if (campfire->gsc->inpa == 0) { purple_debug_info("campfire", "adding input\n"); purple_ssl_input_add(campfire->gsc, (PurpleSslInputFunction) (campfire_ssl_handler), campfire); } purple_debug_info("campfire", "writing first request on ssl connection\n"); purple_ssl_write(campfire->gsc, xaction->http_request->str, xaction->http_request->len); } } return; }