static void irc_input_cb_ssl(gpointer data, PurpleSslConnection *gsc, PurpleInputCondition cond) { PurpleConnection *gc = data; struct irc_conn *irc = gc->proto_data; int len; if(!g_list_find(purple_connections_get_all(), gc)) { purple_ssl_close(gsc); return; } if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) { irc->inbuflen += IRC_INITIAL_BUFSIZE; irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen); } len = purple_ssl_read(gsc, irc->inbuf + irc->inbufused, IRC_INITIAL_BUFSIZE - 1); if (len < 0 && errno == EAGAIN) { /* Try again later */ return; } else if (len < 0) { purple_connection_error(gc, _("Read error")); return; } else if (len == 0) { purple_connection_error(gc, _("Server has disconnected")); return; } read_input(irc, len); }
static void skypeweb_login_did_auth(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message) { gchar *refresh_token; SkypeWebAccount *sa = user_data; if (url_text == NULL) { url_text = url_data->webdata; len = url_data->data_len; } refresh_token = skypeweb_string_get_chunk(url_text, len, "=\"skypetoken\" value=\"", "\""); if (refresh_token == NULL) { if (g_strstr_len(url_text, len, "recaptcha_response_field")) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Captcha required.\nTry logging into web.skype.com and try again.")); return; } else { purple_debug_info("skypeweb", "login response was %s\r\n", url_text); purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting Skype Token")); return; } } sa->skype_token = refresh_token; skypeweb_update_cookies(sa, url_text); skypeweb_do_all_the_things(sa); }
void jabber_auth_handle_challenge(JabberStream *js, PurpleXmlNode *packet) { const char *ns = purple_xmlnode_get_namespace(packet); if (!purple_strequal(ns, NS_XMPP_SASL)) { purple_connection_error(js->gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Invalid response from server")); return; } if (js->auth_mech && js->auth_mech->handle_challenge) { PurpleXmlNode *response = NULL; char *msg = NULL; JabberSaslState state = js->auth_mech->handle_challenge(js, packet, &response, &msg); if (state == JABBER_SASL_STATE_FAIL) { purple_connection_error(js->gc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, msg ? msg : _("Invalid challenge from server")); } else if (response) { jabber_send(js, response); purple_xmlnode_free(response); } g_free(msg); } else purple_debug_warning("jabber", "Received unexpected (and unhandled) <challenge/>\n"); }
void jabber_auth_handle_failure(JabberStream *js, PurpleXmlNode *packet) { PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; char *msg = NULL; if (js->auth_mech && js->auth_mech->handle_failure) { PurpleXmlNode *stanza = NULL; JabberSaslState state = js->auth_mech->handle_failure(js, packet, &stanza, &msg); if (state != JABBER_SASL_STATE_FAIL) { if (stanza) { jabber_send(js, stanza); purple_xmlnode_free(stanza); } return; } } if (!msg) msg = jabber_parse_error(js, packet, &reason); if (!msg) { purple_connection_error(js->gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Invalid response from server")); } else { purple_connection_error(js->gc, reason, msg); g_free(msg); } }
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; } } }
MrimPackage *mrim_package_read(MrimData *mrim) { ssize_t ret = 0; if (mrim->inp_package) { MrimPackage *pack = mrim->inp_package; gsize size = pack->data_size - pack->cur; ret = recv(mrim->fd, pack->data + pack->cur, size, 0); if (ret > 0) { if (ret < size) { pack->cur += ret; return NULL; } else { pack->cur = 0; mrim->inp_package = NULL; return pack; } } } else { MrimPackage *pack = g_new0(MrimPackage, 1); pack->header = read_header(mrim); if (pack->header == NULL) { g_free(pack); return NULL; } purple_debug_info("mrim-prpl", "[%s] seq = %u, type = 0x%x len = %u\n", __func__, pack->header->seq, pack->header->msg, pack->header->dlen); pack->data_size = pack->header->dlen; pack->data = g_new0(char, pack->data_size); pack->cur = 0; if (pack->data_size) { ret = recv(mrim->fd, pack->data, pack->data_size, 0); if ((ret < (pack->data_size)) && (ret > 0)) { pack->cur += ret; mrim->inp_package = pack; return NULL; } if (ret == pack->data_size) { return pack; } } else return pack; } if (ret < 0) { if (mrim->gc) purple_connection_error(mrim->gc, _("Read Error!") ); return NULL; } if (ret == 0) { if (mrim->gc) purple_connection_error(mrim->gc, _("Peer closed connection")); return NULL; } return NULL; }
/*------------------------------------------------------------------------ * Attempt to establish a connection to the MXit server. * * @param session The MXit session object */ static void mxit_login_connect( struct MXitSession* session ) { PurpleProxyConnectData* data = NULL; purple_debug_info( MXIT_PLUGIN_ID, "mxit_login_connect\n" ); purple_connection_update_progress( session->con, _( "Connecting..." ), 1, 4 ); /* * at this stage we have all the user's information we require * for logging into MXit. we will now create a new connection to * a MXit server. */ if ( !session->http ) { /* socket connection */ data = purple_proxy_connect( session->con, session->acc, session->server, session->port, mxit_cb_connect, session ); if ( !data ) { purple_connection_error( session->con, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _( "Unable to connect to the MXit server. Please check your server settings." ) ); return; } } else { /* http connection */ mxit_connected( session ); } }
static void hangouts_auth_get_session_cookies_uberauth_cb(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, gpointer user_data) { HangoutsAccount *ha = user_data; PurpleHttpRequest *request; const gchar *uberauth; uberauth = purple_http_response_get_data(response, NULL); if (purple_http_response_get_error(response) != NULL) { purple_connection_error(ha->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Auth error")); return; } purple_debug_misc("hangouts-prpl", "uberauth: %s", uberauth); request = purple_http_request_new(NULL); purple_http_request_set_url_printf(request, "https://accounts.google.com/MergeSession" "?service=mail&continue=http://www.google.com&uberauth=%s", purple_url_encode(uberauth)); purple_http_request_set_cookie_jar(request, ha->cookie_jar); purple_http_request_header_set_printf(request, "Authorization", "Bearer %s", ha->access_token); purple_http_request_set_max_redirects(request, 0); purple_http_request(ha->pc, request, hangouts_auth_get_session_cookies_got_cb, ha); purple_http_request_unref(request); }
void hangouts_auth_get_session_cookies_got_cb(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, gpointer user_data) { HangoutsAccount *ha = user_data; guint64 last_event_timestamp; gchar *sapisid_cookie = purple_http_cookie_jar_get(ha->cookie_jar, "SAPISID"); if (sapisid_cookie == NULL) { purple_connection_error(ha->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("SAPISID Cookie not received")); return; } //Restore the last_event_timestamp before it gets overridden by new events last_event_timestamp = purple_account_get_int(ha->account, "last_event_timestamp_high", 0); if (last_event_timestamp != 0) { last_event_timestamp = (last_event_timestamp << 32) | ((guint64) purple_account_get_int(ha->account, "last_event_timestamp_low", 0) & 0xFFFFFFFF); ha->last_event_timestamp = last_event_timestamp; } // SOUND THE TRUMPETS hangouts_fetch_channel_sid(ha); purple_connection_set_state(ha->pc, PURPLE_CONNECTION_CONNECTED); //TODO trigger event instead hangouts_get_self_info(ha); hangouts_get_conversation_list(ha); g_free(sapisid_cookie); }
void qq_process_request_login_token_reply(guint8 *buf, gint buf_len, PurpleConnection *gc) { qq_data *qd; gchar *hex_dump; g_return_if_fail(buf != NULL && buf_len != 0); qd = (qq_data *) gc->proto_data; if (buf[0] == QQ_REQUEST_LOGIN_TOKEN_REPLY_OK) { if (buf[1] != buf_len-2) { purple_debug(PURPLE_DEBUG_INFO, "QQ", "Malformed login token reply packet. Packet specifies length of %d, actual length is %d\n", buf[1], buf_len-2); purple_debug(PURPLE_DEBUG_INFO, "QQ", "Attempting to proceed with the actual packet length.\n"); } hex_dump = hex_dump_to_str(buf+2, buf_len-2); purple_debug(PURPLE_DEBUG_INFO, "QQ", "<<< got a token with %d bytes -> [default] decrypt and dump\n%s", buf_len-2, hex_dump); qq_send_packet_login(gc, buf_len-2, buf+2); } else { purple_debug(PURPLE_DEBUG_ERROR, "QQ", "Unknown request login token reply code : %d\n", buf[0]); hex_dump = hex_dump_to_str(buf, buf_len); purple_debug(PURPLE_DEBUG_WARNING, "QQ", ">>> %d bytes -> [default] decrypt and dump\n%s", buf_len, hex_dump); try_dump_as_gbk(buf, buf_len); purple_connection_error(gc, _("Error requesting login token")); } g_free(hex_dump); }
static void irc_send_cb(gpointer data, gint source, PurpleInputCondition cond) { struct irc_conn *irc = data; int ret, writelen; writelen = purple_circ_buffer_get_max_read(irc->outbuf); if (writelen == 0) { purple_input_remove(irc->writeh); irc->writeh = 0; return; } ret = do_send(irc, irc->outbuf->outptr, writelen); if (ret < 0 && errno == EAGAIN) return; else if (ret <= 0) { purple_connection_error(purple_account_get_connection(irc->account), _("Server has disconnected")); return; } purple_circ_buffer_mark_read(irc->outbuf, ret); #if 0 /* We *could* try to write more if we wrote it all */ if (ret == write_len) { irc_send_cb(data, source, cond); } #endif }
static void auth_old_result_cb(JabberStream *js, const char *from, JabberIqType type, const char *id, PurpleXmlNode *packet, gpointer data) { if (type == JABBER_IQ_RESULT) { jabber_stream_set_state(js, JABBER_STREAM_POST_AUTH); jabber_disco_items_server(js); } else { PurpleAccount *account; PurpleConnectionError reason = PURPLE_CONNECTION_ERROR_NETWORK_ERROR; char *msg = jabber_parse_error(js, packet, &reason); PurpleXmlNode *error; const char *err_code; account = purple_connection_get_account(js->gc); /* FIXME: Why is this not in jabber_parse_error? */ if((error = purple_xmlnode_get_child(packet, "error")) && (err_code = purple_xmlnode_get_attrib(error, "code")) && g_str_equal(err_code, "401")) { reason = PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED; /* Clear the pasword if it isn't being saved */ if (!purple_account_get_remember_password(account)) purple_account_set_password(account, NULL, NULL, NULL); } purple_connection_error(js->gc, reason, msg); g_free(msg); } }
/*------------------------------------------------------------------------ * Callback invoked once the connection has been established to the HTTP server, * or on connection failure. * * @param user_data The MXit session object * @param source The file-descriptor associated with the connection * @param error_message Message explaining why the connection failed */ static void mxit_cb_http_connect( gpointer user_data, gint source, const gchar* error_message ) { struct http_request* req = (struct http_request*) user_data; purple_debug_info( MXIT_PLUGIN_ID, "mxit_cb_http_connect\n" ); /* source is the file descriptor of the new connection */ if ( source < 0 ) { purple_debug_info( MXIT_PLUGIN_ID, "mxit_cb_http_connect failed: %s\n", error_message ); purple_connection_error( req->session->con, _( "Unable to connect to the MXit HTTP server. Please check your server settings." ) ); return; } /* we now have an open and active TCP connection to the mxit server */ req->session->fd = source; /* reset the receive buffer */ req->session->rx_state = RX_STATE_RLEN; req->session->rx_lbuf[0] = '\0'; req->session->rx_i = 0; req->session->rx_res = 0; /* start listening on the open connection for messages from the server (reference: "libpurple/eventloop.h") */ req->session->http_handler = purple_input_add( req->session->fd, PURPLE_INPUT_READ, mxit_cb_http_read, req->session ); /* actually send the request to the HTTP server */ mxit_http_raw_write( req->session->fd, req->data, req->datalen ); /* free up resources */ free_http_request( req ); req = NULL; }
void msn_session_set_error (MsnSession *session, MsnErrorType error, const char *info) { PurpleAccount *account; PurpleConnection *connection; char *msg; account = msn_session_get_user_data (session); connection = purple_account_get_connection (account); switch (error) { case MSN_ERROR_SERVCONN: msg = g_strdup (info); break; case MSN_ERROR_UNSUPPORTED_PROTOCOL: msg = g_strdup (_("Our protocol is not supported by the " "server.")); break; case MSN_ERROR_HTTP_MALFORMED: msg = g_strdup (_("Error parsing HTTP.")); break; case MSN_ERROR_SIGN_OTHER: connection->wants_to_die = TRUE; msg = g_strdup (_("You have signed on from another location.")); break; case MSN_ERROR_SERV_UNAVAILABLE: msg = g_strdup (_("The MSN servers are temporarily " "unavailable. Please wait and try " "again.")); break; case MSN_ERROR_SERV_DOWN: msg = g_strdup (_("The MSN servers are going down " "temporarily.")); break; case MSN_ERROR_AUTH: connection->wants_to_die = TRUE; msg = g_strdup_printf (_("Unable to authenticate: %s"), info ? info : _("Unknown error")); break; case MSN_ERROR_BAD_BLIST: msg = g_strdup (_("Your MSN buddy list is temporarily " "unavailable. Please wait and try " "again.")); break; default: msg = g_strdup (_("Unknown error.")); break; } msn_session_disconnect (session); purple_connection_error (connection, msg); g_free (msg); }
void jabber_auth_start_old(JabberStream *js) { PurpleAccount *account; JabberIq *iq; PurpleXmlNode *query, *username; account = purple_connection_get_account(js->gc); /* * We can end up here without encryption if the server doesn't support * <stream:features/> and we're not using old-style SSL. If the user * is requiring SSL/TLS, we need to enforce it. */ if (!jabber_stream_is_ssl(js) && g_str_equal("require_tls", purple_account_get_string(account, "connection_security", JABBER_DEFAULT_REQUIRE_TLS))) { purple_connection_error(js->gc, PURPLE_CONNECTION_ERROR_ENCRYPTION_ERROR, _("You require encryption, but it is not available on this server.")); return; } if (js->registration) { jabber_register_start(js); return; } /* * IQ Auth doesn't have support for resource binding, so we need to pick a * default resource so it will work properly. jabberd14 throws an error and * iChat server just fails silently. */ if (!js->user->resource || *js->user->resource == '\0') { g_free(js->user->resource); js->user->resource = g_strdup("Home"); } #ifdef HAVE_CYRUS_SASL /* If we have Cyrus SASL, then passwords will have been set * to OPTIONAL for this protocol. So, we need to do our own * password prompting here */ if (!purple_connection_get_password(js->gc)) { purple_account_request_password(account, G_CALLBACK(auth_old_pass_cb), G_CALLBACK(auth_no_pass_cb), js->gc); return; } #endif iq = jabber_iq_new_query(js, JABBER_IQ_GET, "jabber:iq:auth"); query = purple_xmlnode_get_child(iq->node, "query"); username = purple_xmlnode_new_child(query, "username"); purple_xmlnode_insert_data(username, js->user->node, -1); jabber_iq_set_callback(iq, auth_old_cb, NULL); jabber_iq_send(iq); }
static void irc_ssl_connect_failure(PurpleSslConnection *gsc, PurpleSslErrorType error, gpointer data) { PurpleConnection *gc = data; struct irc_conn *irc = gc->proto_data; irc->gsc = NULL; switch(error) { case PURPLE_SSL_CONNECT_FAILED: purple_connection_error(gc, _("Connection Failed")); break; case PURPLE_SSL_HANDSHAKE_FAILED: purple_connection_error(gc, _("SSL Handshake Failed")); break; } }
static void hangouts_oauth_with_code_cb(PurpleHttpConnection *http_conn, PurpleHttpResponse *response, gpointer user_data) { HangoutsAccount *ha = user_data; JsonObject *obj; const gchar *raw_response; gsize response_len; PurpleAccount *account = ha->account; raw_response = purple_http_response_get_data(response, &response_len); obj = json_decode_object(raw_response, response_len); if (purple_http_response_is_successful(response) && obj) { ha->access_token = g_strdup(json_object_get_string_member(obj, "access_token")); ha->refresh_token = g_strdup(json_object_get_string_member(obj, "refresh_token")); purple_account_set_remember_password(account, TRUE); hangouts_save_refresh_token_password(account, ha->refresh_token); hangouts_auth_get_session_cookies(ha); } else { if (obj != NULL) { if (json_object_has_member(obj, "error")) { if (g_strcmp0(json_object_get_string_member(obj, "error"), "invalid_grant") == 0) { hangouts_save_refresh_token_password(ha->account, NULL); purple_connection_error(ha->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, json_object_get_string_member(obj, "error_description")); } else { purple_connection_error(ha->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, json_object_get_string_member(obj, "error_description")); } } else { purple_connection_error(ha->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Invalid response")); } } purple_connection_error(ha->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Invalid response")); } json_object_unref(obj); }
static PurpleXmlNode * jabber_bosh_connection_parse(PurpleJabberBOSHConnection *conn, PurpleHttpResponse *response) { PurpleXmlNode *root; const gchar *data; size_t data_len; const gchar *type; g_return_val_if_fail(conn != NULL, NULL); g_return_val_if_fail(response != NULL, NULL); if (conn->is_terminating || purple_account_is_disconnecting( purple_connection_get_account(conn->js->gc))) { return NULL; } if (!purple_http_response_is_successful(response)) { purple_connection_error(conn->js->gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Unable to connect")); return NULL; } data = purple_http_response_get_data(response, &data_len); root = purple_xmlnode_from_str(data, data_len); type = purple_xmlnode_get_attrib(root, "type"); if (g_strcmp0(type, "terminate") == 0) { purple_connection_error(conn->js->gc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, _("The BOSH " "connection manager terminated your session.")); purple_xmlnode_free(root); return NULL; } return root; }
static void nap_login(PurpleAccount *account) { PurpleConnection *gc = purple_account_get_connection(account); purple_connection_update_progress(gc, _("Connecting"), 0, NAPSTER_CONNECT_STEPS); gc->proto_data = g_new0(struct nap_data, 1); if (purple_proxy_connect(gc, account, purple_account_get_string(account, "server", NAP_SERVER), purple_account_get_int(account, "port", NAP_PORT), nap_login_connect, gc) != 0) { purple_connection_error(gc, _("Unable to connect.")); } }
void jabber_auth_handle_success(JabberStream *js, PurpleXmlNode *packet) { const char *ns = purple_xmlnode_get_namespace(packet); if (!purple_strequal(ns, NS_XMPP_SASL)) { purple_connection_error(js->gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Invalid response from server")); return; } if (js->auth_mech && js->auth_mech->handle_success) { char *msg = NULL; JabberSaslState state = js->auth_mech->handle_success(js, packet, &msg); if (state == JABBER_SASL_STATE_FAIL) { purple_connection_error(js->gc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, msg ? msg : _("Invalid response from server")); return; } else if (state == JABBER_SASL_STATE_CONTINUE) { purple_connection_error(js->gc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_IMPOSSIBLE, msg ? msg : _("Server thinks authentication is complete, but client does not")); return; } g_free(msg); } /* * The stream will be reinitialized later in jabber_recv_cb_ssl() or * jabber_bosh_connection_send. */ js->reinit = TRUE; jabber_stream_set_state(js, JABBER_STREAM_POST_AUTH); }
static void irc_input_cb(gpointer data, gint source, PurpleInputCondition cond) { PurpleConnection *gc = data; struct irc_conn *irc = gc->proto_data; int len; if (irc->inbuflen < irc->inbufused + IRC_INITIAL_BUFSIZE) { irc->inbuflen += IRC_INITIAL_BUFSIZE; irc->inbuf = g_realloc(irc->inbuf, irc->inbuflen); } len = read(irc->fd, irc->inbuf + irc->inbufused, IRC_INITIAL_BUFSIZE - 1); if (len < 0 && errno == EAGAIN) { return; } else if (len < 0) { purple_connection_error(gc, _("Read error")); return; } else if (len == 0) { purple_connection_error(gc, _("Server has disconnected")); return; } read_input(irc, len); }
static void sevencup_fatal_connection_cb(SevenCupConnection *scon) { PurpleConnection *pc = scon->sa->pc; purple_debug_error("7cups", "fatal connection error\n"); sevencup_connection_destroy(scon); /* We died. Do not pass Go. Do not collect $200 */ /* In all seriousness, don't attempt to call the normal callback here. * That may lead to the wrong error message being displayed */ purple_connection_error(pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Server closed the connection.")); }
static void irc_login_cb(gpointer data, gint source, const gchar *error_message) { PurpleConnection *gc = data; struct irc_conn *irc = gc->proto_data; if (source < 0) { purple_connection_error(gc, _("Couldn't connect to host")); return; } irc->fd = source; if (do_login(gc)) { gc->inpa = purple_input_add(irc->fd, PURPLE_INPUT_READ, irc_input_cb, gc); } }
static void skypeweb_login_got_t(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message) { SkypeWebAccount *sa = user_data; const gchar *login_url = "https://" SKYPEWEB_LOGIN_HOST;// "/login/oauth?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com"; gchar *request; GString *postdata; gchar *magic_t_value; // T is for tasty sa->url_datas = g_slist_remove(sa->url_datas, url_data); // <input type="hidden" name="t" id="t" value="..."> magic_t_value = skypeweb_string_get_chunk(url_text, len, "=\"t\" value=\"", "\""); if (!magic_t_value) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting Magic T value")); return; } // postdata: t=...&oauthPartner=999&client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com postdata = g_string_new(""); g_string_append_printf(postdata, "t=%s&", purple_url_encode(magic_t_value)); g_string_append(postdata, "oauthPartner=999&"); g_string_append(postdata, "client_id=578134&"); g_string_append(postdata, "redirect_uri=https%3A%2F%2Fweb.skype.com"); // post the t to https://login.skype.com/login/oauth?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com request = g_strdup_printf("POST /login/microsoft?client_id=578134&redirect_uri=https%%3A%%2F%%2Fweb.skype.com HTTP/1.0\r\n" "Connection: close\r\n" "Accept: */*\r\n" "BehaviorOverride: redirectAs404\r\n" "Host: " SKYPEWEB_LOGIN_HOST "\r\n" "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s", strlen(postdata->str), postdata->str); skypeweb_fetch_url_request(sa, login_url, TRUE, NULL, FALSE, request, TRUE, 524288, skypeweb_login_did_auth, sa); g_string_free(postdata, TRUE); g_free(request); g_free(magic_t_value); purple_connection_update_progress(sa->pc, _("Verifying"), 3, 4); }
/*------------------------------------------------------------------------ * Callback invoked once the connection has been established to the MXit server, * or on connection failure. * * @param user_data The MXit session object * @param source The file-descriptor associated with the connection * @param error_message Message explaining why the connection failed */ static void mxit_cb_connect( gpointer user_data, gint source, const gchar* error_message ) { struct MXitSession* session = (struct MXitSession*) user_data; purple_debug_info( MXIT_PLUGIN_ID, "mxit_cb_connect\n" ); /* source is the file descriptor of the new connection */ if ( source < 0 ) { purple_debug_info( MXIT_PLUGIN_ID, "mxit_cb_connect failed: %s\n", error_message ); purple_connection_error( session->con, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _( "Unable to connect to the MXit server. Please check your server settings." ) ); return; } /* we now have an open and active TCP connection to the mxit server */ session->fd = source; /* start listening on the open connection for messages from the server (reference: "libpurple/eventloop.h") */ session->inpa = purple_input_add( session->fd, PURPLE_INPUT_READ, mxit_cb_rx, session ); mxit_connected( session ); }
static void skypeweb_login(PurpleAccount *account) { PurpleConnection *pc = purple_account_get_connection(account); SkypeWebAccount *sa = g_new0(SkypeWebAccount, 1); PurpleConnectionFlags flags; purple_connection_set_protocol_data(pc, sa); if (!purple_ssl_is_supported()) { purple_connection_error (pc, PURPLE_CONNECTION_ERROR_NO_SSL_SUPPORT, _("Server requires TLS/SSL for login. No TLS/SSL support found.")); return; } flags = purple_connection_get_flags(pc); flags |= PURPLE_CONNECTION_FLAG_HTML | PURPLE_CONNECTION_FLAG_NO_BGCOLOR | PURPLE_CONNECTION_FLAG_NO_FONTSIZE; purple_connection_set_flags(pc, flags); if (!SKYPEWEB_BUDDY_IS_MSN(purple_account_get_username(account))) { sa->username = g_ascii_strdown(purple_account_get_username(account), -1); } sa->account = account; sa->pc = pc; sa->cookie_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); sa->hostname_ip_cache = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); sa->sent_messages_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); sa->waiting_conns = g_queue_new(); sa->messages_host = g_strdup(SKYPEWEB_DEFAULT_MESSAGES_HOST); if(strchr(purple_account_get_username(account), '@')) { //Has an email address for a username, probably a microsoft account? skypeweb_begin_oauth_login(sa); } else { skypeweb_begin_web_login(sa); } purple_signal_connect(purple_conversations_get_handle(), "conversation-updated", pc, PURPLE_CALLBACK(skypeweb_mark_conv_seen), NULL); }
int irc_send(struct irc_conn *irc, const char *buf) { int ret, buflen; char *tosend= g_strdup(buf); purple_signal_emit(_irc_plugin, "irc-sending-text", purple_account_get_connection(irc->account), &tosend); if (tosend == NULL) return 0; buflen = strlen(tosend); /* If we're not buffering writes, try to send immediately */ if (!irc->writeh) ret = do_send(irc, tosend, buflen); else { ret = -1; errno = EAGAIN; } /* purple_debug(PURPLE_DEBUG_MISC, "irc", "sent%s: %s", irc->gsc ? " (ssl)" : "", tosend); */ if (ret <= 0 && errno != EAGAIN) { purple_connection_error(purple_account_get_connection(irc->account), _("Server has disconnected")); } else if (ret < buflen) { if (ret < 0) ret = 0; if (!irc->writeh) irc->writeh = purple_input_add( irc->gsc ? irc->gsc->fd : irc->fd, PURPLE_INPUT_WRITE, irc_send_cb, irc); purple_circ_buffer_append(irc->outbuf, tosend + ret, buflen - ret); } g_free(tosend); return ret; }
/* 002 - MSG_CLIENT_LOGIN */ static void nap_login_connect(gpointer data, gint source, const gchar *error_message) { PurpleConnection *gc = data; struct nap_data *ndata = (struct nap_data *)gc->proto_data; gchar *buf; if (!g_list_find(purple_connections_get_all(), gc)) { close(source); return; } if (source < 0) { purple_connection_error(gc, _("Unable to connect.")); return; } /* Clear the nonblocking flag This protocol should be updated to support nonblocking I/O if anyone is going to actually use it */ fcntl(source, F_SETFL, 0); ndata->fd = source; /* Update the login progress status display */ buf = g_strdup_printf("Logging in: %s", purple_account_get_username(gc->account)); purple_connection_update_progress(gc, buf, 1, NAPSTER_CONNECT_STEPS); g_free(buf); /* Write our signon data */ nap_write_packet(gc, 2, "%s %s 0 \"purple %s\" 0", purple_account_get_username(gc->account), purple_connection_get_password(gc), PP_VERSION); /* And set up the input watcher */ gc->inpa = purple_input_add(ndata->fd, PURPLE_INPUT_READ, nap_callback, gc); }
static void skypeweb_login_got_pie(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message) { SkypeWebAccount *sa = user_data; PurpleAccount *account = sa->account; gchar *pie; gchar *etm; const gchar *login_url = "https://" SKYPEWEB_LOGIN_HOST;// "/login?client_id=578134&redirect_uri=https%3A%2F%2Fweb.skype.com"; GString *postdata; gchar *request; struct timeval tv; struct timezone tz; guint tzhours, tzminutes; if (error_message && *error_message) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, error_message); return; } gettimeofday(&tv, &tz); (void) tv; tzminutes = tz.tz_minuteswest; if (tzminutes < 0) tzminutes = -tzminutes; tzhours = tzminutes / 60; tzminutes -= tzhours * 60; pie = skypeweb_string_get_chunk(url_text, len, "=\"pie\" value=\"", "\""); if (!pie) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting PIE value")); return; } etm = skypeweb_string_get_chunk(url_text, len, "=\"etm\" value=\"", "\""); if (!etm) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting ETM value")); return; } postdata = g_string_new(""); g_string_append_printf(postdata, "username=%s&", purple_url_encode(purple_account_get_username(account))); g_string_append_printf(postdata, "password=%s&", purple_url_encode(purple_account_get_password(account))); g_string_append_printf(postdata, "timezone_field=%c|%d|%d&", (tz.tz_minuteswest < 0 ? '+' : '-'), tzhours, tzminutes); g_string_append_printf(postdata, "pie=%s&", purple_url_encode(pie)); g_string_append_printf(postdata, "etm=%s&", purple_url_encode(etm)); g_string_append_printf(postdata, "js_time=%" G_GINT64_FORMAT "&", skypeweb_get_js_time()); g_string_append(postdata, "client_id=578134&"); g_string_append(postdata, "redirect_uri=https://web.skype.com/"); request = g_strdup_printf("POST /login?client_id=578134&redirect_uri=https%%3A%%2F%%2Fweb.skype.com HTTP/1.0\r\n" "Connection: close\r\n" "Accept: */*\r\n" "BehaviorOverride: redirectAs404\r\n" "Host: " SKYPEWEB_LOGIN_HOST "\r\n" "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s", strlen(postdata->str), postdata->str); purple_util_fetch_url_request(sa->account, login_url, TRUE, NULL, FALSE, request, TRUE, 524288, skypeweb_login_did_auth, sa); g_string_free(postdata, TRUE); g_free(request); g_free(pie); g_free(etm); purple_connection_update_progress(sa->pc, _("Authenticating"), 2, 4); }
static void skypeweb_login_got_ppft(PurpleUtilFetchUrlData *url_data, gpointer user_data, const gchar *url_text, gsize len, const gchar *error_message) { SkypeWebAccount *sa = user_data; const gchar *live_login_url = "https://login.live.com";// "/ppsecure/post.srf?wa=wsignin1.0&wreply=https%3A%2F%2Fsecure.skype.com%2Flogin%2Foauth%2Fproxy%3Fclient_id%3D578134%26redirect_uri%3Dhttps%253A%252F%252Fweb.skype.com"; gchar *msprequ_cookie; gchar *mspok_cookie; gchar *cktst_cookie; gchar *ppft; GString *postdata; gchar *request; // grab PPFT and cookies (MSPRequ, MSPOK) msprequ_cookie = skypeweb_string_get_chunk(url_text, len, "Set-Cookie: MSPRequ=", ";"); if (!msprequ_cookie) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting MSPRequ cookie")); return; } mspok_cookie = skypeweb_string_get_chunk(url_text, len, "Set-Cookie: MSPOK=", ";"); if (!mspok_cookie) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting MSPOK cookie")); return; } // <input type="hidden" name="PPFT" id="i0327" value="..."/> ppft = skypeweb_string_get_chunk(url_text, len, "name=\"PPFT\" id=\"i0327\" value=\"", "\""); if (!ppft) { purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED, _("Failed getting PPFT value")); return; } // CkTst=G + timestamp e.g. G1422309314913 cktst_cookie = g_strdup_printf("G%" G_GINT64_FORMAT, skypeweb_get_js_time()); // postdata: login={username}&passwd={password}&PPFT={ppft value} postdata = g_string_new(""); g_string_append_printf(postdata, "login=%s&", purple_url_encode(purple_account_get_username(sa->account))); g_string_append_printf(postdata, "passwd=%s&", purple_url_encode(purple_account_get_password(sa->account))); g_string_append_printf(postdata, "PPFT=%s&", purple_url_encode(ppft)); // POST to https://login.live.com/ppsecure/post.srf?wa=wsignin1.0&wreply=https%3A%2F%2Fsecure.skype.com%2Flogin%2Foauth%2Fproxy%3Fclient_id%3D578134%26redirect_uri%3Dhttps%253A%252F%252Fweb.skype.com request = g_strdup_printf("POST /ppsecure/post.srf?wa=wsignin1.0&wp=MBI_SSL&wreply=https%%3A%%2F%%2Fsecure.skype.com%%2Flogin%%2Foauth%%2Fproxy%%3Fclient_id%%3D578134%%26redirect_uri%%3Dhttps%%253A%%252F%%252Fweb.skype.com HTTP/1.0\r\n" "Connection: close\r\n" "Accept: */*\r\n" "Host: login.live.com\r\n" "Content-Type: application/x-www-form-urlencoded; charset=UTF-8\r\n" "Cookie: MSPRequ=%s;MSPOK=%s;CkTst=%s;\r\n" "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s", msprequ_cookie, mspok_cookie, cktst_cookie, strlen(postdata->str), postdata->str); purple_util_fetch_url_request(sa->account, live_login_url, TRUE, NULL, FALSE, request, FALSE, 524288, skypeweb_login_got_t, sa); g_string_free(postdata, TRUE); g_free(request); g_free(msprequ_cookie); g_free(mspok_cookie); g_free(cktst_cookie); g_free(ppft); purple_connection_update_progress(sa->pc, _("Authenticating"), 2, 4); }