Ejemplo n.º 1
0
static PurpleUtilFetchUrlData *
np_util_post_url2(const gchar *url, const gchar *postdata,gchar *cookies,gboolean include_headers, PurpleUtilFetchUrlCallback callback, gpointer data)
{
	PurpleUtilFetchUrlData *urldata;
	gchar *host, *path, *request;
	int port;
    
    gchar *formatted_cookie;
    if (cookies && strlen(cookies)) {
        formatted_cookie = g_strdup_printf("Cookie: %s",cookies);
    } else {
        formatted_cookie = g_strdup_printf("");
    }
    
	purple_url_parse(url, &host, &port, &path, NULL, NULL);
	request = g_strdup_printf("POST /%s HTTP/1.1\r\n"
                              "Connection: close\r\n"
                              "Host: %s\r\n"
                              "Accept: */*\r\n"
                              "%s"
                              "Content-Type: application/x-www-form-urlencoded\r\n"
                              "Content-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s",
                              path, host,formatted_cookie ,strlen(postdata), postdata);
	
	urldata = purple_util_fetch_url_request(url, TRUE, NULL, TRUE, request, include_headers, callback, data);
	
	g_free(formatted_cookie);
    g_free(host);
	g_free(path);
	g_free(request);
	
	return urldata;
}
Ejemplo n.º 2
0
void
yahoo_fetch_aliases(PurpleConnection *gc)
{
	YahooData *yd = gc->proto_data;
	const char *url;
	gchar *request, *webpage, *webaddress;
	PurpleUtilFetchUrlData *url_data;

	/* use whole URL if using HTTP Proxy */
	gboolean use_whole_url = yahoo_account_use_http_proxy(gc);

	/*  Build all the info to make the web request */
	url = yd->jp ? YAHOOJP_ALIAS_FETCH_URL : YAHOO_ALIAS_FETCH_URL;
	purple_url_parse(url, &webaddress, NULL, &webpage, NULL, NULL);
	request = g_strdup_printf("GET %s%s/%s HTTP/1.1\r\n"
				 "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
				 "Cookie: T=%s; Y=%s\r\n"
				 "Host: %s\r\n"
				 "Cache-Control: no-cache\r\n\r\n",
				  use_whole_url ? "http://" : "", use_whole_url ? webaddress : "", webpage,
				  yd->cookie_t, yd->cookie_y,
				  webaddress);

	/* We have a URL and some header information, let's connect and get some aliases  */
	url_data = purple_util_fetch_url_request_len_with_account(purple_connection_get_account(gc),
				url, use_whole_url, NULL, TRUE, request, FALSE, -1,
				yahoo_fetch_aliases_cb, gc);
	if (url_data != NULL)
		yd->url_datas = g_slist_prepend(yd->url_datas, url_data);

	g_free(webaddress);
	g_free(webpage);
	g_free(request);
}
Ejemplo n.º 3
0
static void
lookup_internal_ip()
{
	gchar* addressOfControl;
	int port = 0;

	if(!purple_url_parse(control_info.control_url, &addressOfControl, &port,
			NULL, NULL, NULL)) {
		purple_debug_error("upnp",
			"lookup_internal_ip(): Failed In Parse URL\n");
		return;
	}
	if(port == 0 || port == -1) {
		port = DEFAULT_HTTP_PORT;
	}

	if(purple_proxy_connect(NULL, NULL, addressOfControl, port,
			looked_up_internal_ip_cb, NULL) == NULL)
	{
		purple_debug_error("upnp", "Get Local IP Connect Failed: Address: %s @@@ Port %d\n",
			addressOfControl, port);
	}

	g_free(addressOfControl);
}
Ejemplo n.º 4
0
PurpleUtilFetchUrlData* spin_vfetch_post_request
(SpinData* spin,const gchar* url,
 PurpleUtilFetchUrlCallback callback,gpointer userdata,
 va_list args)
{
  gchar *host,*path,*user,*passwd,*req,*cookie_header=NULL;
  gint port;
  GString* post_data;
  PurpleAccount* account;

  g_return_val_if_fail(spin,NULL);
  g_return_val_if_fail(url,NULL);
  g_return_val_if_fail(callback,NULL);
  
  if(!purple_url_parse(url,&host,&port,&path,&user,&passwd))
    return NULL;

  account = purple_connection_get_account(spin->gc);

  post_data = spin_vcollect_params(args);

  if(spin->session)
    cookie_header = g_strdup_printf("Cookie:session=%s;session2=%s\r\n",
				    spin->session,spin->session);

  req = g_strdup_printf("POST /%s HTTP/1.0\r\n"
			"Host:%s\r\n"
			"Content-Type:application/x-www-form-urlencoded\r\n"
			"Content-Length:%" G_GSIZE_FORMAT "\r\n"
			"Connection:close\r\n"
			"%s"
			"\r\n%s",
			path ? path : "",host,post_data->len,
			cookie_header ? cookie_header : "",
			post_data->str);


  PurpleUtilFetchUrlData* url_data =
    purple_util_fetch_url_request_len
    (url,
     TRUE, /* full url */
     NULL, /* user agent */
     FALSE, /* http 1.1 */
     req, /* request */
     FALSE, /* include headers */
     -1, /* max len */
     callback, /* callback */
     userdata);

  g_free(req); 
  g_free(cookie_header);
  g_string_free(post_data,TRUE);
  g_free(host);
  g_free(path);
  g_free(user);
  g_free(passwd);

  return url_data;
}
Ejemplo n.º 5
0
static void
pb_fetch_url(PushBulletAccount *pba, const gchar *url, const gchar *postdata, PushBulletProxyCallbackFunc callback, gpointer user_data)
{
	PurpleAccount *account;
	GString *headers;
    gchar *host = NULL, *path = NULL, *user = NULL, *password = NULL;
    int port;
	PushBulletProxyConnection *conn;
	
	account = pba->account;
	if (purple_account_is_disconnected(account)) return;
	
	conn = g_new0(PushBulletProxyConnection, 1);
	conn->pba = pba;
	conn->callback = callback;
	conn->user_data = user_data;
    
    purple_url_parse(url, &host, &port, &path, &user, &password);
	purple_debug_info("pushbullet", "Fetching url %s\n", url);
	
	headers = g_string_new(NULL);
	
	//Use the full 'url' until libpurple can handle path's longer than 256 chars
	g_string_append_printf(headers, "%s /%s HTTP/1.0\r\n", (postdata ? "POST" : "GET"), path);
	//g_string_append_printf(headers, "%s %s HTTP/1.0\r\n", (postdata ? "POST" : "GET"), url);
    g_string_append_printf(headers, "Connection: close\r\n");
    g_string_append_printf(headers, "Host: %s\r\n", host);
    g_string_append_printf(headers, "Accept: */*\r\n");
	g_string_append_printf(headers, "User-Agent: Pidgin\r\n");
    
    if(pba->access_token && *(pba->access_token)) {
        g_string_append_printf(headers, "Authorization: Bearer %s\r\n", pba->access_token);
    }
    
    if(postdata) {
		purple_debug_info("mightytext", "With postdata %s\n", postdata);
		
		if (postdata[0] == '{') {
			g_string_append(headers, "Content-Type: application/json\r\n");
		} else {
			g_string_append(headers, "Content-Type: application/x-www-form-urlencoded\r\n");
		}
        g_string_append_printf(headers, "Content-Length: %d\r\n", strlen(postdata));
        g_string_append(headers, "\r\n");
        
        g_string_append(headers, postdata);
    } else {
        g_string_append(headers, "\r\n");
    }
    
    g_free(host);
    g_free(path);
    g_free(user);
    g_free(password);
    
    purple_util_fetch_url_request_len_with_account(pba->account, url, FALSE, "Pidgin", TRUE, headers->str, FALSE, 6553500, pb_response_callback, conn);
	
	g_string_free(headers, TRUE);
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
Archivo: oob.c Proyecto: dylex/pidgin
void jabber_oob_parse(JabberStream *js, const char *from, JabberIqType type,
                      const char *id, xmlnode *querynode) {
	JabberOOBXfer *jox;
	PurpleXfer *xfer;
	char *filename;
	char *url;
	xmlnode *urlnode;

	if(type != JABBER_IQ_SET)
		return;

	if(!from)
		return;

	if(!(urlnode = xmlnode_get_child(querynode, "url")))
		return;

	url = xmlnode_get_data(urlnode);

	jox = g_new0(JabberOOBXfer, 1);
	if (!purple_url_parse(url, &jox->address, &jox->port, &jox->page, NULL, NULL)) {
		g_free(url);
		return;
	}
	g_free(url);
	jox->js = js;
	jox->headers = g_string_new("");
	jox->iq_id = g_strdup(id);

	xfer = purple_xfer_new(js->gc->account, PURPLE_XFER_RECEIVE, from);
	if (xfer)
	{
		xfer->data = jox;

		if(!(filename = g_strdup(g_strrstr(jox->page, "/"))))
			filename = g_strdup(jox->page);

		purple_xfer_set_filename(xfer, filename);

		g_free(filename);

		purple_xfer_set_init_fnc(xfer,   jabber_oob_xfer_init);
		purple_xfer_set_end_fnc(xfer,    jabber_oob_xfer_end);
		purple_xfer_set_request_denied_fnc(xfer, jabber_oob_xfer_recv_denied);
		purple_xfer_set_cancel_recv_fnc(xfer, jabber_oob_xfer_recv_cancelled);
		purple_xfer_set_read_fnc(xfer,   jabber_oob_xfer_read);
		purple_xfer_set_start_fnc(xfer,  jabber_oob_xfer_start);

		js->oob_file_transfers = g_list_append(js->oob_file_transfers, xfer);

		purple_xfer_request(xfer);
	}
}
Ejemplo n.º 8
0
Archivo: oob.c Proyecto: bf4/pidgin-mac
void jabber_oob_parse(JabberStream *js, xmlnode *packet) {
	JabberOOBXfer *jox;
	PurpleXfer *xfer;
	char *filename;
	char *url;
	const char *type;
	xmlnode *querynode, *urlnode;

	if(!(type = xmlnode_get_attrib(packet, "type")) || strcmp(type, "set"))
		return;

	if(!(querynode = xmlnode_get_child(packet, "query")))
		return;

	if(!(urlnode = xmlnode_get_child(querynode, "url")))
		return;

	url = xmlnode_get_data(urlnode);

	jox = g_new0(JabberOOBXfer, 1);
	purple_url_parse(url, &jox->address, &jox->port, &jox->page, NULL, NULL);
	g_free(url);
	jox->js = js;
	jox->headers = g_string_new("");
	jox->iq_id = g_strdup(xmlnode_get_attrib(packet, "id"));

	xfer = purple_xfer_new(js->gc->account, PURPLE_XFER_RECEIVE,
			xmlnode_get_attrib(packet, "from"));
	if (xfer)
	{
		xfer->data = jox;

		if(!(filename = g_strdup(g_strrstr(jox->page, "/"))))
			filename = g_strdup(jox->page);

		purple_xfer_set_filename(xfer, filename);

		g_free(filename);

		purple_xfer_set_init_fnc(xfer,   jabber_oob_xfer_init);
		purple_xfer_set_end_fnc(xfer,    jabber_oob_xfer_end);
		purple_xfer_set_request_denied_fnc(xfer, jabber_oob_xfer_recv_denied);
		purple_xfer_set_cancel_recv_fnc(xfer, jabber_oob_xfer_recv_canceled);
		purple_xfer_set_read_fnc(xfer,   jabber_oob_xfer_read);
		purple_xfer_set_start_fnc(xfer,  jabber_oob_xfer_start);

		js->oob_file_transfers = g_list_append(js->oob_file_transfers, xfer);

		purple_xfer_request(xfer);
	}
}
Ejemplo n.º 9
0
PurpleUtilFetchUrlData* spin_fetch_url_request
(SpinData* spin,const gchar* url,
 PurpleUtilFetchUrlCallback callback,gpointer userdata)
{
  gchar *host,*path,*user,*passwd,*req,*cookie_header=NULL;
  gint port;
  PurpleAccount* account;

  g_return_val_if_fail(spin,NULL);
  g_return_val_if_fail(url,NULL);
  g_return_val_if_fail(callback,NULL);
  
  if(!purple_url_parse(url,&host,&port,&path,&user,&passwd))
    return NULL;

  account = purple_connection_get_account(spin->gc);

  if(spin->session)
    cookie_header = g_strdup_printf("Cookie:session=%s;session2=%s\r\n",
				    spin->session,spin->session);

  req = g_strdup_printf("GET /%s HTTP/1.0\r\n"
			"Host:%s\r\n"
			"Connection:close\r\n"
			"%s"
			"\r\n",
			path ? path : "",host,
			cookie_header ? cookie_header : "");

  PurpleUtilFetchUrlData* url_data =
    purple_util_fetch_url_request_len
    (url,
     TRUE, /* full url */
     NULL, /* user agent */
     FALSE, /* http 1.1 */
     req, /* request */
     FALSE, /* include headers */
     -1, /* max len */
     callback, /* callback */
     userdata);

  g_free(req); 
  g_free(cookie_header);
  g_free(host);
  g_free(path);
  g_free(user);
  g_free(passwd);

  return url_data;
}
Ejemplo n.º 10
0
//mostly shamelessly stolen from pidgin's "util.c"
gchar *http_request(const gchar *url, gboolean http11, gboolean post, const gchar *user_agent, GHashTable *req_table, GHashTable *cookie_table) {
    GString *request_str = g_string_new(NULL);
    gchar *address = NULL, *page = NULL, *user = NULL, *password = NULL;
    int port;
    
    purple_url_parse(url, &address, &port, &page, &user, &password);
    
    g_string_append_printf(request_str, "%s /%s%s", (post ? "POST" : "GET"), page, (!post && req_table ? "?" : ""));
    if(req_table && !post) g_string_append_cgi(request_str, req_table);
    g_string_append_printf(request_str, " HTTP/%s\r\n", (http11 ? "1.1" : "1.0"));
    g_string_append_printf(request_str, "Connection: close\r\n");
    if(user_agent) g_string_append_printf(request_str, "User-Agent: %s\r\n", user_agent);
    g_string_append_printf(request_str, "Accept: */*\r\n");
    g_string_append_printf(request_str, "Host: %s\r\n", address);
    
    if(cookie_table) {
        g_string_append(request_str, "Cookie: ");
        g_string_append_cookies(request_str, cookie_table);
        g_string_append(request_str, "\r\n");
    }
    
    if(post) {
        GString *post_str = g_string_new(NULL);
        gchar *post = NULL;
        
        if(req_table) g_string_append_cgi(post_str, req_table);
        
        post = g_string_free(post_str, FALSE);
        
        purple_debug_info("flist", "posting (len: %d): %s\n", strlen(post), post);

        g_string_append(request_str, "Content-Type: application/x-www-form-urlencoded\r\n");
        g_string_append_printf(request_str, "Content-Length: %d\r\n", strlen(post));
        g_string_append(request_str, "\r\n");
        
        g_string_append(request_str, post);
        
        g_free(post);
    } else {
        g_string_append(request_str, "\r\n");
    }
    
    if(address) g_free(address);
    if(page) g_free(page);
    if(user) g_free(user);
    if(password) g_free(password);
    
    return g_string_free(request_str, FALSE);
}
Ejemplo n.º 11
0
static PurpleUtilFetchUrlData*
purple_upnp_generate_action_message_and_send(const gchar* actionName,
		const gchar* actionParams, PurpleUtilFetchUrlCallback cb,
		gpointer cb_data)
{
	PurpleUtilFetchUrlData* gfud;
	gchar* soapMessage;
	gchar* totalSendMessage;
	gchar* pathOfControl;
	gchar* addressOfControl;
	int port = 0;

	/* parse the url into address, port, path variables */
	if(!purple_url_parse(control_info.control_url, &addressOfControl,
			&port, &pathOfControl, NULL, NULL)) {
		purple_debug_error("upnp",
			"generate_action_message_and_send(): Failed In Parse URL\n");
		/* XXX: This should probably be async */
		if(cb)
			cb(NULL, cb_data, NULL, 0, NULL);
		return NULL;
	}
	if(port == 0 || port == -1) {
		port = DEFAULT_HTTP_PORT;
	}

	/* set the soap message */
	soapMessage = g_strdup_printf(SOAP_ACTION, actionName,
		control_info.service_type, actionParams, actionName);

	/* set the HTTP Header, and append the body to it */
	totalSendMessage = g_strdup_printf(HTTP_HEADER_ACTION "%s",
		pathOfControl, addressOfControl, port,
		control_info.service_type, actionName,
		strlen(soapMessage), soapMessage);
	g_free(pathOfControl);
	g_free(soapMessage);

	gfud = purple_util_fetch_url_request_len(control_info.control_url, FALSE, NULL, TRUE,
				totalSendMessage, TRUE, MAX_UPNP_DOWNLOAD, cb, cb_data);

	g_free(totalSendMessage);
	g_free(addressOfControl);

	return gfud;
}
Ejemplo n.º 12
0
static void
purple_upnp_parse_description(const gchar* descriptionURL, UPnPDiscoveryData *dd)
{
	gchar* httpRequest;
	gchar* descriptionXMLAddress;
	gchar* descriptionAddress;
	int port = 0;

	/* parse the 4 above variables out of the descriptionURL
	   example description URL: http://192.168.1.1:5678/rootDesc.xml */

	/* parse the url into address, port, path variables */
	if(!purple_url_parse(descriptionURL, &descriptionAddress,
			&port, &descriptionXMLAddress, NULL, NULL)) {
		return;
	}
	if(port == 0 || port == -1) {
		port = DEFAULT_HTTP_PORT;
	}

	/* for example...
	   GET /rootDesc.xml HTTP/1.1\r\nHost: 192.168.1.1:5678\r\n\r\n */
	httpRequest = g_strdup_printf(
		"GET /%s HTTP/1.1\r\n"
		"Connection: close\r\n"
		"Host: %s:%d\r\n\r\n",
		descriptionXMLAddress, descriptionAddress, port);

	g_free(descriptionXMLAddress);

	dd->full_url = g_strdup_printf("http://%s:%d",
			descriptionAddress, port);
	g_free(descriptionAddress);

	/* Remove the timeout because everything it is waiting for has
	 * successfully completed */
	purple_timeout_remove(dd->tima);
	dd->tima = 0;

	purple_util_fetch_url_request_len(descriptionURL, TRUE, NULL, TRUE, httpRequest,
			TRUE, MAX_UPNP_DOWNLOAD, upnp_parse_description_cb, dd);

	g_free(httpRequest);

}
Ejemplo n.º 13
0
void
skypeweb_download_uri_to_conv(SkypeWebAccount *sa, const gchar *uri, PurpleConversation *conv)
{
	gchar *headers;
	gchar *path, *host;
	
	purple_url_parse(uri, &host, NULL, &path, NULL, NULL);
	headers = g_strdup_printf("GET /%s HTTP/1.0\r\n"
			"Connection: close\r\n"
			"Accept: image/*\r\n"
			"Cookie: skypetoken_asm=%s\r\n"
			"Host: %s\r\n"
			"\r\n\r\n",
			path, sa->skype_token, host);
	
	purple_util_fetch_url_request(sa->account, uri, TRUE, NULL, FALSE, headers, FALSE, -1, skypeweb_got_imagemessage, conv);
	
	g_free(headers);
	g_free(host);
	g_free(path);
}
Ejemplo n.º 14
0
static gboolean
msn_soap_handle_redirect(MsnSoapConnection *conn, const char *url)
{
	char *host;
	char *path;

	if (purple_url_parse(url, &host, NULL, &path, NULL, NULL)) {
		msn_soap_message_send_internal(conn->session, conn->current_request->message,
			host, path, conn->current_request->secure,
			conn->current_request->cb, conn->current_request->cb_data, TRUE);

		msn_soap_request_destroy(conn->current_request, TRUE);
		conn->current_request = NULL;

		g_free(host);
		g_free(path);

		return TRUE;
	}

	return FALSE;
}
Ejemplo n.º 15
0
void yahoo_process_filetransfer(PurpleConnection *gc, struct yahoo_packet *pkt)
{
	char *from = NULL;
	char *to = NULL;
	char *msg = NULL;
	char *url = NULL;
	char *imv = NULL;
	long expires = 0;
	PurpleXfer *xfer;
	struct yahoo_data *yd;
	struct yahoo_xfer_data *xfer_data;
	char *service = NULL;
	char *filename = NULL;
	unsigned long filesize = 0L;
	GSList *l;

	yd = gc->proto_data;

	for (l = pkt->hash; l; l = l->next) {
		struct yahoo_pair *pair = l->data;

		if (pair->key == 4)
			from = pair->value;
		if (pair->key == 5)
			to = pair->value;
		if (pair->key == 14)
			msg = pair->value;
		if (pair->key == 20)
			url = pair->value;
		if (pair->key == 38)
			expires = strtol(pair->value, NULL, 10);
		if (pair->key == 27)
			filename = pair->value;
		if (pair->key == 28)
			filesize = atol(pair->value);
		if (pair->key == 49)
			service = pair->value;
		if (pair->key == 63)
			imv = pair->value;
	}

	/*
	 * 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;
		}
	}

	if (msg) {
		char *tmp;
		tmp = strchr(msg, '\006');
		if (tmp)
			*tmp = '\0';
	}

	if (!url || !from)
		return;

	/* Setup the Yahoo-specific file transfer data */
	xfer_data = g_new0(struct yahoo_xfer_data, 1);
	xfer_data->gc = gc;
	if (!purple_url_parse(url, &(xfer_data->host), &(xfer_data->port), &(xfer_data->path), NULL, NULL)) {
		g_free(xfer_data);
		return;
	}

	purple_debug_misc("yahoo_filexfer", "Host is %s, port is %d, path is %s, and the full url was %s.\n",
	                xfer_data->host, xfer_data->port, xfer_data->path, url);

	/* Build the file transfer handle. */
	xfer = purple_xfer_new(gc->account, PURPLE_XFER_RECEIVE, from);
	if (xfer)
	{
		xfer->data = xfer_data;

		/* Set the info about the incoming file. */
		if (filename) {
			char *utf8_filename = yahoo_string_decode(gc, filename, TRUE);
			purple_xfer_set_filename(xfer, utf8_filename);
			g_free(utf8_filename);
		} else {
			gchar *start, *end;
			start = g_strrstr(xfer_data->path, "/");
			if (start)
				start++;
			end = g_strrstr(xfer_data->path, "?");
			if (start && *start && end) {
				char *utf8_filename;
				filename = g_strndup(start, end - start);
				utf8_filename = yahoo_string_decode(gc, filename, TRUE);
				g_free(filename);
				purple_xfer_set_filename(xfer, utf8_filename);
				g_free(utf8_filename);
				filename = NULL;
			}
		}

		purple_xfer_set_size(xfer, filesize);

		/* Setup our I/O op functions */
		purple_xfer_set_init_fnc(xfer,        yahoo_xfer_init);
		purple_xfer_set_start_fnc(xfer,       yahoo_xfer_start);
		purple_xfer_set_end_fnc(xfer,         yahoo_xfer_end);
		purple_xfer_set_cancel_send_fnc(xfer, yahoo_xfer_cancel_send);
		purple_xfer_set_cancel_recv_fnc(xfer, yahoo_xfer_cancel_recv);
		purple_xfer_set_read_fnc(xfer,        yahoo_xfer_read);
		purple_xfer_set_write_fnc(xfer,       yahoo_xfer_write);

		/* Now perform the request */
		purple_xfer_request(xfer);
	}
}
Ejemplo n.º 16
0
static void
yahoo_set_userinfo_cb(PurpleConnection *gc, PurpleRequestFields *fields)
{
	xmlnode *node = xmlnode_new("ab");
	xmlnode *ct = xmlnode_new_child(node, "ct");
	YahooData *yd = purple_connection_get_protocol_data(gc);
	PurpleAccount *account;
	PurpleUtilFetchUrlData *url_data;
	char *webaddress, *webpage;
	char *request, *content;
	int len;
	int i;
	char * yfields[] = { "fn", "ln", "nn", "mn", "hp", "wp", "mo", NULL };

	account = purple_connection_get_account(gc);

	xmlnode_set_attrib(node, "k", purple_connection_get_display_name(gc));
	xmlnode_set_attrib(node, "cc", "1");		/* XXX: ? */

	xmlnode_set_attrib(ct, "e", "1");
	xmlnode_set_attrib(ct, "yi", purple_request_fields_get_string(fields, "yname"));
	xmlnode_set_attrib(ct, "id", purple_request_fields_get_string(fields, "yid"));
	xmlnode_set_attrib(ct, "pr", "0");

	for (i = 0; yfields[i]; i++) {
		const char *v = purple_request_fields_get_string(fields, yfields[i]);
		xmlnode_set_attrib(ct, yfields[i], v ? v : "");
	}

	content = xmlnode_to_formatted_str(node, &len);
	xmlnode_free(node);
	purple_url_parse(yd->jp ? YAHOOJP_USERINFO_URL : YAHOO_USERINFO_URL, &webaddress, NULL, &webpage, NULL, NULL);

	request = g_strdup_printf("POST %s HTTP/1.1\r\n"
				  "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
				  "Cookie: T=%s; path=/; domain=.yahoo.com; Y=%s;\r\n"
				  "Host: %s\r\n"
				  "Content-Length: %d\r\n"
				  "Cache-Control: no-cache\r\n\r\n"
				  "%s\r\n\r\n",
				  webpage,
				  yd->cookie_t, yd->cookie_y,
				  webaddress,
				  len + 4,
				  content);

#if 0
	{
		/* This is if we wanted to send our contact details to everyone
		 * in the buddylist. But this cannot be done now, because in the
		 * official messenger, doing this pops a conversation window at
		 * the receiver's end, which is stupid, and thus not really
		 * surprising. */
		struct yahoo_userinfo *ui = g_new(struct yahoo_userinfo, 1);
		node = xmlnode_new("contact");

		for (i = 0; yfields[i]; i++) {
			const char *v = purple_request_fields_get_string(fields, yfields[i]);
			if (v) {
				xmlnode *nd = xmlnode_new_child(node, yfields[i]);
				xmlnode_insert_data(nd, v, -1);
			}
		}

		ui->yd = yd;
		ui->xml = xmlnode_to_str(node, NULL);
		xmlnode_free(node);
	}
#endif

	url_data = purple_util_fetch_url_request_len_with_account(account, webaddress, FALSE,
			YAHOO_CLIENT_USERAGENT, TRUE, request, FALSE, -1,
			yahoo_fetch_aliases_cb, gc);
	if (url_data != NULL)
		yd->url_datas = g_slist_prepend(yd->url_datas, url_data);

	g_free(webaddress);
	g_free(webpage);
	g_free(content);
	g_free(request);
}
Ejemplo n.º 17
0
void
yahoo_update_alias(PurpleConnection *gc, const char *who, const char *alias)
{
	YahooData *yd;
	const char *url;
	gchar *content, *request, *webpage, *webaddress;
	struct callback_data *cb;
	PurpleUtilFetchUrlData *url_data;
	YahooFriend *f;
	/* use whole URL if using HTTP Proxy */
	gboolean use_whole_url = yahoo_account_use_http_proxy(gc);

	g_return_if_fail(who != NULL);
	g_return_if_fail(gc != NULL);

	if (alias == NULL)
		alias = "";

	f = yahoo_friend_find(gc, who);
	if (f == NULL) {
		purple_debug_error("yahoo", "Missing YahooFriend. Unable to set server alias.\n");
		return;
	}

	yd = gc->proto_data;

	/* Using callback_data so I have access to gc in the callback function */
	cb = g_new0(struct callback_data, 1);
	cb->who = g_strdup(who);
	cb->id = g_strdup(yahoo_friend_get_alias_id(f));
	cb->gc = gc;

	/*  Build all the info to make the web request */
	url = yd->jp ? YAHOOJP_ALIAS_UPDATE_URL: YAHOO_ALIAS_UPDATE_URL;
	purple_url_parse(url, &webaddress, NULL, &webpage, NULL, NULL);

	if (cb->id == NULL) {
		/* No id for this buddy, so create an address book entry */
		purple_debug_info("yahoo", "Creating '%s' as new alias for user '%s'\n", alias, who);

		if (yd->jp) {
			gchar *alias_jp = g_convert(alias, -1, "EUC-JP", "UTF-8", NULL, NULL, NULL);
			gchar *converted_alias_jp = yahoo_convert_to_numeric(alias_jp);
			content = g_strdup_printf("<ab k=\"%s\" cc=\"9\">\n"
						  "<ct a=\"1\" yi='%s' nn='%s' />\n</ab>\r\n",
						  purple_account_get_username(gc->account),
						  who, converted_alias_jp);
			g_free(converted_alias_jp);
			g_free(alias_jp);
		} else {
			gchar *escaped_alias = g_markup_escape_text(alias, -1);
			content = g_strdup_printf("<?xml version=\"1.0\" encoding=\"utf-8\"?><ab k=\"%s\" cc=\"9\">\n"
						  "<ct a=\"1\" yi='%s' nn='%s' />\n</ab>\r\n",
						  purple_account_get_username(gc->account),
						  who, escaped_alias);
			g_free(escaped_alias);
		}
	} else {
		purple_debug_info("yahoo", "Updating '%s' as new alias for user '%s'\n", alias, who);

		if (yd->jp) {
			gchar *alias_jp = g_convert(alias, -1, "EUC-JP", "UTF-8", NULL, NULL, NULL);
			gchar *converted_alias_jp = yahoo_convert_to_numeric(alias_jp);
			content = g_strdup_printf("<ab k=\"%s\" cc=\"1\">\n"
						  "<ct e=\"1\"  yi='%s' id='%s' nn='%s' pr='0' />\n</ab>\r\n",
						  purple_account_get_username(gc->account),
						  who, cb->id, converted_alias_jp);
			g_free(converted_alias_jp);
			g_free(alias_jp);
		} else {
			gchar *escaped_alias = g_markup_escape_text(alias, -1);
			content = g_strdup_printf("<?xml version=\"1.0\" encoding=\"utf-8\"?><ab k=\"%s\" cc=\"1\">\n"
						  "<ct e=\"1\"  yi='%s' id='%s' nn='%s' pr='0' />\n</ab>\r\n",
						  purple_account_get_username(gc->account),
						  who, cb->id, escaped_alias);
			g_free(escaped_alias);
		}
	}

	request = g_strdup_printf("POST %s%s/%s HTTP/1.1\r\n"
				  "User-Agent: " YAHOO_CLIENT_USERAGENT "\r\n"
				  "Cookie: T=%s; Y=%s\r\n"
				  "Host: %s\r\n"
				  "Content-Length: %" G_GSIZE_FORMAT "\r\n"
				  "Cache-Control: no-cache\r\n\r\n"
				  "%s",
				  use_whole_url ? "http://" : "", use_whole_url ? webaddress : "", webpage,
				  yd->cookie_t, yd->cookie_y,
				  webaddress,
				  strlen(content),
				  content);

	/* We have a URL and some header information, let's connect and update the alias  */
	url_data = purple_util_fetch_url_request_len_with_account(
			purple_connection_get_account(gc), url, use_whole_url, NULL, TRUE,
			request, FALSE, -1, yahoo_update_alias_cb, cb);
	if (url_data != NULL)
		yd->url_datas = g_slist_prepend(yd->url_datas, url_data);

	g_free(webpage);
	g_free(webaddress);
	g_free(content);
	g_free(request);
}