Esempio n. 1
0
static void
rea_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd)
{
    MsnSession *session;
    const char *who;
    const char *alias;

    session = cmdproc->session;
    who = cmd->params[2];
    alias = purple_url_decode(cmd->params[3]);

    if (strcmp(who, purple_account_get_username (session->account)) == 0)
    {
        /* This is for us. */
        PurpleConnection *gc;
        gc = session->account->gc;
        purple_connection_set_display_name(gc, alias);
    }
    else
    {
        /* This is for a buddy. */
        PecanContact *user;
        user = pecan_contactlist_find_contact(session->contactlist, who);
        if (user)
        {
            pecan_contact_set_store_name(user, alias);
        }
        else
        {
            pecan_error ("unknown user: who=[%s]", who);
            return;
        }
    }
}
Esempio n. 2
0
static void
pb_oauth_set_access_token_cb(gpointer data, const gchar *access_token)
{
	PurpleAccount *account = data;
	gchar *real_access_token;
	const gchar *access_token_start;
	const gchar *access_token_end;
	gchar *strtmp;
	
	if (!access_token || !(*access_token)) {
		return;
	}
	
	if((access_token_start = strstr(access_token, "access_token=")))
	{
		access_token_start += 13;
		access_token_end = strchr(access_token_start, '&');
		if (access_token_end)
			real_access_token = g_strndup(access_token_start, access_token_end - access_token_start);
		else
			real_access_token = g_strdup(access_token_start);
		
		strtmp = g_strdup(purple_url_decode(real_access_token));
		g_free(real_access_token);
		real_access_token = strtmp;
	} else {
		real_access_token = g_strdup(access_token);
	}
	
	if (real_access_token && *real_access_token) {
		purple_account_set_remember_password(account, TRUE);
		purple_account_set_password(account, real_access_token);
		
		purple_account_set_enabled(account, purple_core_get_ui(), TRUE);
		purple_account_connect(account);
	}
	
	g_free(real_access_token);
}
Esempio n. 3
0
void
msn_parse_format(const char *mime, char **pre_ret, char **post_ret)
{
    char *cur;
    GString *pre  = g_string_new(NULL);
    GString *post = g_string_new(NULL);
    unsigned int colors[3];

    if (pre_ret  != NULL) *pre_ret  = NULL;
    if (post_ret != NULL) *post_ret = NULL;

    cur = strstr(mime, "FN=");

    if (cur && (*(cur = cur + 3) != ';'))
    {
        pre = g_string_append(pre, "<FONT FACE=\"");

        while (*cur && *cur != ';')
        {
            pre = g_string_append_c(pre, *cur);
            cur++;
        }

        pre = g_string_append(pre, "\">");
        post = g_string_prepend(post, "</FONT>");
    }

    cur = strstr(mime, "EF=");

    if (cur && (*(cur = cur + 3) != ';'))
    {
        while (*cur && *cur != ';')
        {
            pre = g_string_append_c(pre, '<');
            pre = g_string_append_c(pre, *cur);
            pre = g_string_append_c(pre, '>');
            post = g_string_prepend_c(post, '>');
            post = g_string_prepend_c(post, *cur);
            post = g_string_prepend_c(post, '/');
            post = g_string_prepend_c(post, '<');
            cur++;
        }
    }

    cur = strstr(mime, "CO=");

    if (cur && (*(cur = cur + 3) != ';'))
    {
        int i;

        i = sscanf(cur, "%02x%02x%02x;", &colors[0], &colors[1], &colors[2]);

        if (i > 0)
        {
            char tag[64];

            if (i == 1)
            {
                colors[1] = 0;
                colors[2] = 0;
            }
            else if (i == 2)
            {
                unsigned int temp = colors[0];

                colors[0] = colors[1];
                colors[1] = temp;
                colors[2] = 0;
            }
            else if (i == 3)
            {
                unsigned int temp = colors[2];

                colors[2] = colors[0];
                colors[0] = temp;
            }

            g_snprintf(tag, sizeof(tag),
                       "<FONT COLOR=\"#%02x%02x%02x\">",
                       colors[0] & 0xFF, colors[1] & 0xFF,
                       colors[2] & 0xFF);

            pre = g_string_append(pre, tag);
            post = g_string_prepend(post, "</FONT>");
        }
    }

    cur = strstr(mime, "RL=");

    if (cur && (*(cur = cur + 3) != ';'))
    {
        if (*cur == '1')
        {
            /* RTL text was received */
            pre = g_string_append(pre, "<SPAN style=\"direction:rtl;text-align:right;\">");
            post = g_string_prepend(post, "</SPAN>");
        }
    }

    cur = g_strdup(purple_url_decode(pre->str));
    g_string_free(pre, TRUE);

    if (pre_ret != NULL)
        *pre_ret = cur;
    else
        g_free(cur);

    cur = g_strdup(purple_url_decode(post->str));
    g_string_free(post, TRUE);

    if (post_ret != NULL)
        *post_ret = cur;
    else
        g_free(cur);
}
Esempio n. 4
0
static void
msn_soap_process(MsnSoapConnection *conn)
{
	gboolean handled = FALSE;
	char *cursor;
	char *linebreak;

	cursor = conn->buf->str + conn->handled_len;

	if (!conn->headers_done) {
		while ((linebreak = strstr(cursor, "\r\n"))	!= NULL) {
			conn->handled_len = linebreak - conn->buf->str + 2;

			if (conn->response_code == 0) {
				if (sscanf(cursor, "HTTP/1.1 %d", &conn->response_code) != 1) {
					/* something horribly wrong */
					purple_ssl_close(conn->ssl);
					conn->ssl = NULL;
					handled = TRUE;
					break;
				} else if (conn->response_code == 503 && conn->session->login_step < MSN_LOGIN_STEP_END) {
					msn_soap_connection_sanitize(conn, TRUE);
					msn_session_set_error(conn->session, MSN_ERROR_SERV_UNAVAILABLE, NULL);
					return;
				}
			} else if (cursor == linebreak) {
				/* blank line */
				conn->headers_done = TRUE;
				cursor = conn->buf->str + conn->handled_len;
				break;
			} else {
				char *line = g_strndup(cursor, linebreak - cursor);
				char *sep = strstr(line, ": ");
				char *key = line;
				char *value;

				if (sep == NULL) {
					purple_debug_info("soap", "ignoring malformed line: %s\n", line);
					g_free(line);
					goto loop_end;
				}

				value = sep + 2;
				*sep = '\0';
				msn_soap_message_add_header(conn->message, key, value);

				if ((conn->response_code == 301 || conn->response_code == 300)
					&& strcmp(key, "Location") == 0) {

					msn_soap_handle_redirect(conn, value);

					handled = TRUE;
					g_free(line);
					break;
				} else if (conn->response_code == 401 &&
					strcmp(key, "WWW-Authenticate") == 0) {
					char *error = strstr(value, "cbtxt=");

					if (error) {
						error += strlen("cbtxt=");
					}

					msn_soap_connection_sanitize(conn, TRUE);
					msn_session_set_error(conn->session, MSN_ERROR_AUTH,
						error ? purple_url_decode(error) : NULL);

					g_free(line);
					return;
				} else if (strcmp(key, "Content-Length") == 0) {
					if (sscanf(value, "%" G_GSIZE_FORMAT, &(conn->body_len)) != 1)
						purple_debug_error("soap", "Unable to parse Content-Length\n");
				} else if (strcmp(key, "Connection") == 0) {
					if (strcmp(value, "close") == 0) {
						conn->close_when_done = TRUE;
					}
				}
				g_free(line);
			}

		loop_end:
			cursor = conn->buf->str + conn->handled_len;
		}
	}

	if (!handled && conn->headers_done) {
		if (conn->buf->len - conn->handled_len >=
			conn->body_len) {
			xmlnode *node = xmlnode_from_str(cursor, conn->body_len);

			if (node == NULL) {
				purple_debug_info("soap", "Malformed SOAP response: %s\n",
					cursor);
			} else {
				MsnSoapMessage *message = conn->message;
				conn->message = NULL;
				message->xml = node;

				if (!msn_soap_handle_body(conn, message)) {
					return;
				}
			}

			msn_soap_connection_handle_next(conn);
		}

		return;
	}

	if (handled) {
		msn_soap_connection_handle_next(conn);
	}
}
Esempio n. 5
0
void msn_emoticon_msg(MsnCmdProc *cmdproc, MsnMessage *msg)
{
	MsnSession *session;
	MsnSlpLink *slplink;
	MsnSwitchBoard *swboard;
	MsnObject *obj;
	char **tokens;
	char *smile, *body_str;
	const char *body, *who, *sha1;
	guint tok;
	size_t body_len;

	PurpleConversation *conv;

	session = cmdproc->servconn->session;

	if (!purple_account_get_bool(session->account, "custom_smileys", TRUE))
		return;

	swboard = cmdproc->data;
	conv = swboard->conv;

	body = msn_message_get_bin_data(msg, &body_len);
	if (!body || !body_len)
		return;
	body_str = g_strndup(body, body_len);

	/* MSN Messenger 7 may send more than one MSNObject in a single message...
	 * Maybe 10 tokens is a reasonable max value. */
	tokens = g_strsplit(body_str, "\t", 10);

	g_free(body_str);

	for (tok = 0; tok < 9; tok += 2) {
		if (tokens[tok] == NULL || tokens[tok + 1] == NULL) {
			break;
		}

		smile = tokens[tok];
		obj = msn_object_new_from_string(purple_url_decode(tokens[tok + 1]));

		if (obj == NULL)
			break;

		who = msn_object_get_creator(obj);
		sha1 = msn_object_get_sha1(obj);

		slplink = msn_session_get_slplink(session, who);
		if (slplink->swboard != swboard) {
			if (slplink->swboard != NULL)
				/*
				 * Apparently we're using a different switchboard now or
				 * something?  I don't know if this is normal, but it
				 * definitely happens.  So make sure the old switchboard
				 * doesn't still have a reference to us.
				 */
				slplink->swboard->slplinks = g_list_remove(slplink->swboard->slplinks, slplink);
			slplink->swboard = swboard;
			slplink->swboard->slplinks = g_list_prepend(slplink->swboard->slplinks, slplink);
		}

		/* If the conversation doesn't exist then this is a custom smiley
		 * used in the first message in a MSN conversation: we need to create
		 * the conversation now, otherwise the custom smiley won't be shown.
		 * This happens because every GtkIMHtml has its own smiley tree: if
		 * the conversation doesn't exist then we cannot associate the new
		 * smiley with its GtkIMHtml widget. */
		if (!conv) {
			conv = PURPLE_CONVERSATION(purple_im_conversation_new(session->account, who));
		}

		if (purple_conversation_custom_smiley_add(conv, smile, "sha1", sha1, TRUE)) {
			msn_slplink_request_object(slplink, smile, got_emoticon, NULL, obj);
		}

		msn_object_destroy(obj, FALSE);
		obj =   NULL;
		who =   NULL;
		sha1 = NULL;
	}
	g_strfreev(tokens);
}
Esempio n. 6
0
static void
nexus_login_written_cb(gpointer data, gint source, PurpleInputCondition cond)
{
	MsnNexus *nexus = data;
	MsnSession *session;
	int len;

	session = nexus->session;
	g_return_if_fail(session != NULL);

	if (nexus->input_handler == 0)
		/* TODO: Use purple_ssl_input_add()? */
		nexus->input_handler = purple_input_add(nexus->gsc->fd,
			PURPLE_INPUT_READ, nexus_login_written_cb, nexus);


	len = msn_ssl_read(nexus);

	if (len < 0 && errno == EAGAIN)
		return;
	else if (len < 0) {
		purple_input_remove(nexus->input_handler);
		nexus->input_handler = 0;
		g_free(nexus->read_buf);
		nexus->read_buf = NULL;
		nexus->read_len = 0;
		/* TODO: error handling */
		return;
	}

	if (g_strstr_len(nexus->read_buf, nexus->read_len,
			"\r\n\r\n") == NULL)
		return;

	purple_input_remove(nexus->input_handler);
	nexus->input_handler = 0;

	purple_ssl_close(nexus->gsc);
	nexus->gsc = NULL;

	pecan_log ("ssl buffer: [%s]", nexus->read_buf);

	if (strstr(nexus->read_buf, "HTTP/1.1 302") != NULL)
	{
		/* Redirect. */
		char *location, *c;

		location = strstr(nexus->read_buf, "Location: ");
		if (location == NULL)
		{
			g_free(nexus->read_buf);
			nexus->read_buf = NULL;
			nexus->read_len = 0;

			return;
		}
		location = strchr(location, ' ') + 1;

		if ((c = strchr(location, '\r')) != NULL)
			*c = '\0';

		/* Skip the http:// */
		if ((c = strchr(location, '/')) != NULL)
			location = c + 2;

		if ((c = strchr(location, '/')) != NULL)
		{
			g_free(nexus->login_path);
			nexus->login_path = g_strdup(c);

			*c = '\0';
		}

		g_free(nexus->login_host);
		nexus->login_host = g_strdup(location);

		nexus->gsc = purple_ssl_connect(session->account,
				nexus->login_host, PURPLE_SSL_DEFAULT_PORT,
				login_connect_cb, login_error_cb, nexus);
	}
	else if (strstr(nexus->read_buf, "HTTP/1.1 401 Unauthorized") != NULL)
	{
		const char *error;

		if ((error = strstr(nexus->read_buf, "WWW-Authenticate")) != NULL)
		{
			if ((error = strstr(error, "cbtxt=")) != NULL)
			{
				const char *c;
				char *temp;

				error += strlen("cbtxt=");

				if ((c = strchr(error, '\n')) == NULL)
					c = error + strlen(error);

				temp = g_strndup(error, c - error);
				error = purple_url_decode(temp);
				g_free(temp);
				if ((temp = strstr(error, " Do one of the following or try again:")) != NULL)
					*temp = '\0';
			}
		}

		msn_session_set_error(session, MSN_ERROR_AUTH, error);
	}
	else if (strstr(nexus->read_buf, "HTTP/1.1 503 Service Unavailable"))
	{
		msn_session_set_error(session, MSN_ERROR_SERV_UNAVAILABLE, NULL);
	}
	else if (strstr(nexus->read_buf, "HTTP/1.1 200 OK"))
	{
		char *base, *c;
		char *login_params;

#if 0
		/* All your base are belong to us. */
		base = buffer;

		/* For great cookie! */
		while ((base = strstr(base, "Set-Cookie: ")) != NULL)
		{
			base += strlen("Set-Cookie: ");

			c = strchr(base, ';');

			session->login_cookies =
				g_list_append(session->login_cookies,
							  g_strndup(base, c - base));
		}
#endif

		base  = strstr(nexus->read_buf, "Authentication-Info: ");

		g_return_if_fail(base != NULL);

		base  = strstr(base, "from-PP='");
		base += strlen("from-PP='");
		c     = strchr(base, '\'');

		login_params = g_strndup(base, c - base);

		msn_got_login_params(session, login_params);

		g_free(login_params);

		msn_nexus_destroy(nexus);
		session->nexus = NULL;
		return;
	}

	g_free(nexus->read_buf);
	nexus->read_buf = NULL;
	nexus->read_len = 0;

}
Esempio n. 7
0
static void glst_cmd(NateonCmdProc *cmdproc, NateonCommand *cmd)
{
	NateonSession *session = cmdproc->session;

	if (cmd->param_count < 6) return;

	/* Group */
	if (!strcmp(cmd->params[3], "Y"))
	{
		NateonGroup *group;
		const char *name;
		int group_id;

		group_id = atoi(cmd->params[4]);
		name = purple_url_decode(cmd->params[5]);

		group = nateon_group_new(session->userlist, group_id, name);

//		/* HACK */
//		if (group_id == 0)
//		{
//			/* Group of ungroupped buddies */
//			g_free(group->name);
//			group->name = g_strdup("");
//		}

		if (purple_find_group(name) == NULL)
		{
			PurpleGroup *g = purple_group_new(name);
			purple_blist_add_group(g, NULL);
		}

	}
	/* User's group info */
	else
	{
		NateonUser *user;
		char *user_id = NULL;
		int group_id;

		user_id = cmd->params[4];
		group_id = atoi(cmd->params[5]);

		user = nateon_userlist_find_user_with_id(session->userlist, user_id);
		if (user == NULL)
		{
			user = nateon_user_new(session->userlist, "", "", user_id);
			user->group_ids = NULL;

			nateon_userlist_add_user(session->userlist, user);
		}

		user->group_ids = g_list_append(user->group_ids, GINT_TO_POINTER(group_id));
	}

	//session->sync->num_groups++;

	/* end of group list */
	if (atoi(cmd->params[1])+1 == atoi(cmd->params[2]))
	{
		nateon_cmdproc_send(cmdproc, "LIST", NULL);
	}
}