gboolean connect_to_server(PurpleConnection *gc, gchar *server, gint port) { PurpleAccount *account ; qq_data *qd; g_return_val_if_fail(gc != NULL && gc->proto_data != NULL, FALSE); account = purple_connection_get_account(gc); qd = (qq_data *) gc->proto_data; if (server == NULL || server[0] == '\0' || port == 0) { purple_connection_error_reason(gc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, _("Invalid server or port")); return FALSE; } purple_connection_update_progress(gc, _("Connecting to server"), 1, QQ_CONNECT_STEPS); purple_debug_info("QQ", "Connect to %s:%d\n", server, port); if (qd->conn_data != NULL) { purple_proxy_connect_cancel(qd->conn_data); qd->conn_data = NULL; } #ifdef purple_proxy_connect_udp if (qd->use_tcp) { qd->conn_data = purple_proxy_connect(gc, account, server, port, connect_cb, gc); } else { qd->conn_data = purple_proxy_connect_udp(gc, account, server, port, connect_cb, gc); } if ( qd->conn_data == NULL ) { purple_debug_error("QQ", "Couldn't create socket\n"); return FALSE; } #else /* QQ connection via UDP/TCP. * Now use Purple proxy function to provide TCP proxy support, * and qq_udp_proxy.c to add UDP proxy support (thanks henry) */ if(qd->use_tcp) { qd->conn_data = purple_proxy_connect(gc, account, server, port, connect_cb, gc); if ( qd->conn_data == NULL ) { purple_debug_error("QQ", "Unable to connect.\n"); return FALSE; } return TRUE; } purple_debug_info("QQ", "UDP Connect to %s:%d\n", server, port); qd->udp_query_data = purple_dnsquery_a(server, port, udp_host_resolved, gc); if ( qd->udp_query_data == NULL ) { purple_debug_error("QQ", "Could not resolve hostname\n"); return FALSE; } #endif return TRUE; }
static void do_test1(PurpleSrvResponse *resp, int results, gpointer sdata) { const char *servername = sdata; int port = 3478; if(results) { servername = resp[0].hostname; port = resp[0].port; } purple_debug_info("stun", "got %d SRV responses, server: %s, port: %d\n", results, servername, port); purple_dnsquery_a(servername, port, hbn_cb, NULL); g_free(resp); }
void om_post_or_get(OmegleAccount *oma, OmegleMethod method, const gchar *host, const gchar *url, const gchar *postdata, OmegleProxyCallbackFunc callback_func, gpointer user_data, gboolean keepalive) { GString *request; gchar *cookies; OmegleConnection *omconn; gchar *real_url; gboolean is_proxy = FALSE; const gchar *user_agent; const gchar* const *languages; gchar *language_names; PurpleProxyInfo *proxy_info = NULL; gchar *proxy_auth; gchar *proxy_auth_base64; /* TODO: Fix keepalive and use it as much as possible */ keepalive = FALSE; if (host == NULL) host = purple_account_get_string(oma->account, "host", "bajor.omegle.com"); if (oma && oma->account && !(method & OM_METHOD_SSL)) { proxy_info = purple_proxy_get_setup(oma->account); if (purple_proxy_info_get_type(proxy_info) == PURPLE_PROXY_USE_GLOBAL) proxy_info = purple_global_proxy_get_info(); if (purple_proxy_info_get_type(proxy_info) == PURPLE_PROXY_HTTP) { is_proxy = TRUE; } } if (is_proxy == TRUE) { real_url = g_strdup_printf("http://%s%s", host, url); } else { real_url = g_strdup(url); } cookies = om_cookies_to_string(oma); user_agent = purple_account_get_string(oma->account, "user-agent", "Opera/9.50 (Windows NT 5.1; U; en-GB)"); if (method & OM_METHOD_POST && !postdata) postdata = ""; /* Build the request */ request = g_string_new(NULL); g_string_append_printf(request, "%s %s HTTP/1.0\r\n", (method & OM_METHOD_POST) ? "POST" : "GET", real_url); if (is_proxy == FALSE) g_string_append_printf(request, "Host: %s\r\n", host); g_string_append_printf(request, "Connection: %s\r\n", (keepalive ? "Keep-Alive" : "close")); g_string_append_printf(request, "User-Agent: %s\r\n", user_agent); if (method & OM_METHOD_POST) { g_string_append_printf(request, "Content-Type: application/x-www-form-urlencoded\r\n"); g_string_append_printf(request, "Content-length: %zu\r\n", strlen(postdata)); } g_string_append_printf(request, "Accept: application/json, text/html, */*\r\n"); g_string_append_printf(request, "Cookie: %s\r\n", cookies); g_string_append_printf(request, "Accept-Encoding: gzip\r\n"); if (is_proxy == TRUE) { if (purple_proxy_info_get_username(proxy_info) && purple_proxy_info_get_password(proxy_info)) { proxy_auth = g_strdup_printf("%s:%s", purple_proxy_info_get_username(proxy_info), purple_proxy_info_get_password(proxy_info)); proxy_auth_base64 = purple_base64_encode((guchar *)proxy_auth, strlen(proxy_auth)); g_string_append_printf(request, "Proxy-Authorization: Basic %s\r\n", proxy_auth_base64); g_free(proxy_auth_base64); g_free(proxy_auth); } } /* Tell the server what language we accept, so that we get error messages in our language (rather than our IP's) */ languages = g_get_language_names(); language_names = g_strjoinv(", ", (gchar **)languages); purple_util_chrreplace(language_names, '_', '-'); g_string_append_printf(request, "Accept-Language: %s\r\n", language_names); g_free(language_names); purple_debug_info("omegle", "getting url %s\n", url); g_string_append_printf(request, "\r\n"); if (method & OM_METHOD_POST) g_string_append_printf(request, "%s", postdata); /* If it needs to go over a SSL connection, we probably shouldn't print * it in the debug log. Without this condition a user's password is * printed in the debug log */ if (method == OM_METHOD_POST) purple_debug_info("omegle", "sending request data:\n%s\n", postdata); g_free(cookies); /* * Do a separate DNS lookup for the given host name and cache it * for next time. * * TODO: It would be better if we did this before we call * purple_proxy_connect(), so we could re-use the result. * Or even better: Use persistent HTTP connections for servers * that we access continually. * * TODO: This cache of the hostname<-->IP address does not respect * the TTL returned by the DNS server. We should expire things * from the cache after some amount of time. */ if (!is_proxy) { /* Don't do this for proxy connections, since proxies do the DNS lookup */ gchar *host_ip; host_ip = g_hash_table_lookup(oma->hostname_ip_cache, host); if (host_ip != NULL) { host = host_ip; } else if (oma->account && !oma->account->disconnecting) { GSList *host_lookup_list = NULL; PurpleDnsQueryData *query; host_lookup_list = g_slist_prepend( host_lookup_list, g_strdup(host)); host_lookup_list = g_slist_prepend( host_lookup_list, oma); query = purple_dnsquery_a(host, 80, om_host_lookup_cb, host_lookup_list); oma->dns_queries = g_slist_prepend(oma->dns_queries, query); host_lookup_list = g_slist_append(host_lookup_list, query); } } omconn = g_new0(OmegleConnection, 1); omconn->oma = oma; omconn->url = real_url; omconn->method = method; omconn->hostname = g_strdup(host); omconn->request = request; omconn->callback = callback_func; omconn->user_data = user_data; omconn->fd = -1; omconn->connection_keepalive = keepalive; omconn->request_time = time(NULL); oma->conns = g_slist_prepend(oma->conns, omconn); om_attempt_connection(omconn); }
void yahoo_process_filetrans_15(PurpleConnection *gc, struct yahoo_packet *pkt) { char *from = NULL; char *imv = NULL; long val_222 = 0L; PurpleXfer *xfer; YahooData *yd; struct yahoo_xfer_data *xfer_data; char *service = NULL; char *filename = NULL; char *xfer_peer_idstring = NULL; char *utf8_filename; GSList *l; GSList *filename_list = NULL; GSList *size_list = NULL; int nooffiles = 0; yd = purple_connection_get_protocol_data(gc); for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 4: if (g_utf8_validate(pair->value, -1, NULL)) { from = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 5: /* to */ break; case 265: if (g_utf8_validate(pair->value, -1, NULL)) { xfer_peer_idstring = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 27: filename_list = g_slist_prepend(filename_list, g_strdup(pair->value)); nooffiles++; break; case 28: if (g_utf8_validate(pair->value, -1, NULL)) { size_list = g_slist_prepend(size_list, g_strdup(pair->value)); } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 222: val_222 = atol(pair->value); /* 1=send, 2=cancel, 3=accept, 4=reject */ break; /* check for p2p and imviron .... not sure it comes by this service packet. Since it was bundled with filexfer in old ymsg version, still keeping it. */ case 49: if (g_utf8_validate(pair->value, -1, NULL)) { service = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; case 63: if (g_utf8_validate(pair->value, -1, NULL)) { imv = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_filetrans_15 " "got non-UTF-8 string for key %d\n", pair->key); } break; /* end check */ } } if(!xfer_peer_idstring) return; if(val_222 == 2 || val_222 == 4) { xfer = g_hash_table_lookup(yd->xfer_peer_idstring_map, xfer_peer_idstring); if(!xfer) return; purple_xfer_cancel_remote(xfer); return; } if(val_222 == 3) { PurpleAccount *account; struct yahoo_xfer_data *xd; xfer = g_hash_table_lookup(yd->xfer_peer_idstring_map, xfer_peer_idstring); if(!xfer) return; xd = purple_xfer_get_protocol_data(xfer); /* * In the file trans info packet that we must reply with, we are * supposed to mention the ip address... * purple connect does not give me a way of finding the ip address... * so, purple dnsquery is used... but retries, trying with next ip * address etc. is not implemented..TODO */ /* To send through p2p */ if( g_hash_table_lookup(yd->peers, from) ) { /* send p2p file transfer information */ purple_debug_error("yahoo", "p2p file transfers are not supported yet\n"); /*xd->is_relay = FALSE;*/ } xd->is_relay = TRUE; account = purple_connection_get_account(gc); if (yd->jp) { purple_dnsquery_a(account, YAHOOJP_XFER_RELAY_HOST, YAHOOJP_XFER_RELAY_PORT, yahoo_xfer_dns_connected_15, xfer); } else { purple_dnsquery_a(account, YAHOO_XFER_RELAY_HOST, YAHOO_XFER_RELAY_PORT, yahoo_xfer_dns_connected_15, xfer); } return; } /* processing for p2p and imviron .... not sure it comes by this service packet. Since it was bundled with filexfer in old ymsg version, still keeping it. */ /* * The remote user has changed their IMVironment. We * record it for later use. */ if (from && imv && service && (strcmp("IMVIRONMENT", service) == 0)) { g_hash_table_replace(yd->imvironments, g_strdup(from), g_strdup(imv)); return; } if (pkt->service == YAHOO_SERVICE_P2PFILEXFER) { if (service && (strcmp("FILEXFER", service) != 0)) { purple_debug_misc("yahoo", "unhandled service 0x%02x\n", pkt->service); return; } } /* end processing */ if(!filename_list) return; /* have to change list into order in which client at other end sends */ filename_list = g_slist_reverse(filename_list); size_list = g_slist_reverse(size_list); filename = filename_list->data; if(!from) return; xfer_data = g_new0(struct yahoo_xfer_data, 1); xfer_data->firstoflist = TRUE; xfer_data->gc = gc; xfer_data->xfer_peer_idstring = g_strdup(xfer_peer_idstring); xfer_data->filename_list = filename_list; xfer_data->size_list = size_list; /* Build the file transfer handle. */ xfer = yahoo_ft_new_xfer_struct(gc, PURPLE_XFER_TYPE_RECEIVE, from); /* Set the info about the incoming file. */ utf8_filename = yahoo_string_decode(gc, filename, TRUE); purple_xfer_set_filename(xfer, utf8_filename); g_free(utf8_filename); purple_xfer_set_protocol_data(xfer, xfer_data); g_hash_table_insert(yd->xfer_peer_idstring_map, xfer_data->xfer_peer_idstring, xfer); if(nooffiles > 1) { gchar* message; message = g_strdup_printf(_("%s is trying to send you a group of %d files.\n"), purple_xfer_get_remote_user(xfer), nooffiles); purple_xfer_conversation_write(xfer, message, FALSE); g_free(message); } /* Now perform the request */ purple_xfer_request(xfer); }
static void sevencup_attempt_connection(SevenCupConnection *scon) { gboolean is_proxy = FALSE; SevenCupAccount *sa = scon->sa; PurpleProxyInfo *proxy_info = NULL; if (sa && sa->account && !(scon->method & STEAM_METHOD_SSL)) { proxy_info = purple_proxy_get_setup(sa->account); if (purple_proxy_info_get_type(proxy_info) == PURPLE_PROXY_USE_GLOBAL) proxy_info = purple_global_proxy_get_info(); if (purple_proxy_info_get_type(proxy_info) == PURPLE_PROXY_HTTP) { is_proxy = TRUE; } } #if 0 /* Connection to attempt retries. This code doesn't work perfectly, but * remains here for future reference if needed */ if (time(NULL) - scon->request_time > 5) { /* We've continuously tried to remake this connection for a * bit now. It isn't happening, sadly. Time to die. */ purple_debug_error("7cups", "could not connect after retries\n"); sevencup_fatal_connection_cb(scon); return; } purple_debug_info("7cups", "making connection attempt\n"); /* TODO: If we're retrying the connection, consider clearing the cached * DNS value. This will require some juggling with the hostname param */ /* TODO/FIXME: This retries almost instantenously, which in some cases * runs at blinding speed. Slow it down. */ /* TODO/FIXME: this doesn't retry properly on non-ssl connections */ #endif sa->conns = g_slist_prepend(sa->conns, scon); /* * Do a separate DNS lookup for the given host name and cache it * for next time. * * TODO: It would be better if we did this before we call * purple_proxy_connect(), so we could re-use the result. * Or even better: Use persistent HTTP connections for servers * that we access continually. * * TODO: This cache of the hostname<-->IP address does not respect * the TTL returned by the DNS server. We should expire things * from the cache after some amount of time. */ if (!is_proxy && !(scon->method & STEAM_METHOD_SSL) && !g_hostname_is_ip_address(scon->hostname)) { /* Don't do this for proxy connections, since proxies do the DNS lookup */ gchar *host_ip; host_ip = g_hash_table_lookup(sa->hostname_ip_cache, scon->hostname); if (host_ip != NULL) { g_free(scon->hostname); scon->hostname = g_strdup(host_ip); } else if (sa->account && !sa->account->disconnecting) { GSList *host_lookup_list = NULL; PurpleDnsQueryData *query; host_lookup_list = g_slist_prepend( host_lookup_list, g_strdup(scon->hostname)); host_lookup_list = g_slist_prepend( host_lookup_list, sa); query = purple_dnsquery_a( #if PURPLE_VERSION_CHECK(3, 0, 0) scon->sa->account, #endif scon->hostname, 80, sevencup_host_lookup_cb, host_lookup_list); sa->dns_queries = g_slist_prepend(sa->dns_queries, query); host_lookup_list = g_slist_append(host_lookup_list, query); } } if (scon->method & STEAM_METHOD_SSL) { scon->ssl_conn = purple_ssl_connect(sa->account, scon->hostname, 443, sevencup_post_or_get_ssl_connect_cb, sevencup_ssl_connection_error, scon); } else { scon->connect_data = purple_proxy_connect(NULL, sa->account, scon->hostname, 80, sevencup_post_or_get_connect_cb, scon); } scon->timeout_watcher = purple_timeout_add_seconds(120, sevencup_connection_timedout, scon); return; }
void fb_post_or_get(FacebookAccount *fba, FacebookMethod method, const gchar *host, const gchar *url, const gchar *postdata, FacebookProxyCallbackFunc callback_func, gpointer user_data, gboolean keepalive) { GString *request; gchar *cookies; FacebookConnection *fbconn; gchar *real_url; gboolean is_proxy = FALSE; const gchar *user_agent; /* TODO: Fix keepalive and use it as much as possible */ keepalive = FALSE; if (host == NULL) host = "www.facebook.com"; if (fba && fba->account && fba->account->proxy_info && (fba->account->proxy_info->type == PURPLE_PROXY_HTTP || (fba->account->proxy_info->type == PURPLE_PROXY_USE_GLOBAL && purple_global_proxy_get_info() && purple_global_proxy_get_info()->type == PURPLE_PROXY_HTTP))) { real_url = g_strdup_printf("http://%s%s", host, url); is_proxy = TRUE; } else { real_url = g_strdup(url); } cookies = fb_cookies_to_string(fba); user_agent = purple_account_get_string(fba->account, "user-agent", "Opera/9.50 (Windows NT 5.1; U; en-GB)"); /* Build the request */ request = g_string_new(NULL); g_string_append_printf(request, "%s %s HTTP/1.0\r\n", (method & FB_METHOD_POST) ? "POST" : "GET", real_url); g_string_append_printf(request, "Host: %s\r\n", host); g_string_append_printf(request, "Connection: %s\r\n", (keepalive ? "Keep-Alive" : "close")); g_string_append_printf(request, "User-Agent: %s\r\n", user_agent); if (method & FB_METHOD_POST) { g_string_append_printf(request, "Content-Type: application/x-www-form-urlencoded\r\n"); g_string_append_printf(request, "Content-length: %zu\r\n", strlen(postdata)); } g_string_append_printf(request, "Accept: */*\r\n"); g_string_append_printf(request, "Cookie: isfbe=false;%s\r\n", cookies); #ifdef HAVE_ZLIB if (zlib_inflate != NULL) g_string_append_printf(request, "Accept-Encoding: gzip\r\n"); #endif purple_debug_misc("facebook", "sending request headers:\n%s\n", request->str); g_string_append_printf(request, "\r\n"); if (method & FB_METHOD_POST) g_string_append_printf(request, "%s", postdata); /* If it needs to go over a SSL connection, we probably shouldn't print * it in the debug log. Without this condition a user's password is * printed in the debug log */ if (method == FB_METHOD_POST) purple_debug_misc("facebook", "sending request data:\n%s\n", postdata); g_free(cookies); g_free(real_url); /* * Do a separate DNS lookup for the given host name and cache it * for next time. * * TODO: It would be better if we did this before we call * purple_proxy_connect(), so we could re-use the result. * Or even better: Use persistent HTTP connections for servers * that we access continually. * * TODO: This cache of the hostname<-->IP address does not respect * the TTL returned by the DNS server. We should expire things * from the cache after some amount of time. */ if (!is_proxy) { /* Don't do this for proxy connections, since proxies do the DNS lookup */ gchar *host_ip; host_ip = g_hash_table_lookup(fba->hostname_ip_cache, host); if (host_ip != NULL) { purple_debug_info("facebook", "swapping original host %s with cached value of %s\n", host, host_ip); host = host_ip; } else if (fba->account && !fba->account->disconnecting) { GSList *host_lookup_list = NULL; PurpleDnsQueryData *query; host_lookup_list = g_slist_prepend( host_lookup_list, g_strdup(host)); host_lookup_list = g_slist_prepend( host_lookup_list, fba); query = purple_dnsquery_a(host, 80, fb_host_lookup_cb, host_lookup_list); fba->dns_queries = g_slist_prepend(fba->dns_queries, query); host_lookup_list = g_slist_append(host_lookup_list, query); } } fbconn = g_new0(FacebookConnection, 1); fbconn->fba = fba; fbconn->method = method; fbconn->hostname = g_strdup(host); fbconn->request = request; fbconn->callback = callback_func; fbconn->user_data = user_data; fbconn->fd = -1; fbconn->connection_keepalive = keepalive; fbconn->request_time = time(NULL); fba->conns = g_slist_prepend(fba->conns, fbconn); fb_attempt_connection(fbconn); }