Ejemplo n.º 1
0
static void
prp_cmd (MsnCmdProc *cmdproc,
         MsnCommand *cmd)
{
    MsnSession *session = cmdproc->session;
    const gchar *type, *value;
    struct pn_contact *user;

    type  = cmd->params[0];
    value = cmd->params[1];
    user = msn_session_get_contact (session);

    if (cmd->param_count == 2)
    {
        gchar *tmp;
        tmp = pn_url_decode (value);
        if (strcmp (type, "PHH") == 0)
            pn_contact_set_home_phone (user, tmp);
        else if (strcmp (type, "PHW") == 0)
            pn_contact_set_work_phone (user, tmp);
        else if (strcmp (type, "PHM") == 0)
            pn_contact_set_mobile_phone (user, tmp);
        else if (strcmp (type, "MFN") == 0)
        {
            PurpleAccount *account;
            PurpleConnection *connection;
            const gchar* friendly_name;
            account = msn_session_get_user_data (session);
            connection = purple_account_get_connection (account);

            friendly_name = purple_account_get_string (account, "friendly_name", NULL);

            /*
             * The server doesn't seem to store the friendly name anymore,
             * store it in account opts.
             */
            if (friendly_name)
                msn_session_set_public_alias (session, friendly_name);
            else
                purple_account_set_string (account, "friendly_name", tmp);

            purple_connection_set_display_name (connection, friendly_name);
        }
        g_free (tmp);
    }
    else
    {
        if (strcmp (type, "PHH") == 0)
            pn_contact_set_home_phone (user, NULL);
        else if (strcmp (type, "PHW") == 0)
            pn_contact_set_work_phone (user, NULL);
        else if (strcmp (type, "PHM") == 0)
            pn_contact_set_mobile_phone (user, NULL);
    }
}
Ejemplo n.º 2
0
static void
lsg_cmd (MsnCmdProc *cmdproc,
         MsnCommand *cmd)
{
    MsnSession *session = cmdproc->session;
    char *name;
    const gchar *group_guid;

    name = pn_url_decode (cmd->params[0]);
    group_guid = cmd->params[1];

    if (strcmp(name, MSN_NULL_GROUP_NAME) == 0) {
        pn_error("Invalid group name, ignoring");
        goto leave;
    }

    pn_group_new (session->contactlist, name, group_guid);

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

    /* Group of ungroupped buddies */
    if (!group_guid)
    {
        if (session->sync->total_users == 0)
        {
            cmdproc->cbs_table = session->sync->old_cbs_table;

            msn_session_finish_login (session);

            msn_sync_destroy (session->sync);
            session->sync = NULL;
        }
    }
leave:
    g_free (name);
}
Ejemplo n.º 3
0
static void
bpr_cmd (MsnCmdProc *cmdproc,
         MsnCommand *cmd)
{
    MsnSync *sync = cmdproc->session->sync;
    const char *type, *value;
    struct pn_contact *user;

    user = sync->last_user;

    g_return_if_fail (user);

    type = cmd->params[0];
    value = cmd->params[1];

    if (value)
    {
        if (strcmp(type, "MOB") == 0)
        {
            if (strcmp (value, "Y") == 0)
                user->mobile = TRUE;
        }
        else
        {
            gchar *tmp;
            tmp = pn_url_decode (value);
            if (strcmp(type, "PHH") == 0)
                pn_contact_set_home_phone (user, tmp);
            else if (strcmp(type, "PHW") == 0)
                pn_contact_set_work_phone (user, tmp);
            else if (strcmp (type, "PHM") == 0)
                pn_contact_set_mobile_phone (user, tmp);
            g_free (tmp);
        }
    }
}
Ejemplo n.º 4
0
static void
lsg_cmd (MsnCmdProc *cmdproc,
         MsnCommand *cmd)
{
    MsnSession *session = cmdproc->session;
    char *name;
    const gchar *group_guid;

    name = pn_url_decode (cmd->params[0]);
    group_guid = cmd->params[1];

    pn_group_new (session->contactlist, name, group_guid);

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

    g_free (name);

    /* Group of ungroupped buddies */
    if (!group_guid)
    {
        if (session->sync->total_users == 0)
        {
            cmdproc->cbs_table = session->sync->old_cbs_table;

            msn_session_finish_login (session);

            msn_sync_destroy (session->sync);
            session->sync = NULL;
        }
        return;
    }
}
Ejemplo n.º 5
0
static void
got_header(MsnNexus *nexus,
           const gchar *header)
{
    MsnSession *session = nexus->session;

    if (strstr(header, "HTTP/1.1 200 OK")) {
        char *base, *c;
        char *login_params;

        base  = strstr(header, "Authentication-Info: ");

        if (!base)
            goto parse_error;

        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;
    }
    else if (strstr(header, "HTTP/1.1 302")) {
        /* Redirect. */
        char *location, *c;

        location = strstr(header, "Location: ");
        if (!location)
            goto parse_error;
        location = strchr(location, ' ') + 1;

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

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

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

            *c = '\0';
        }

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

        pn_info("reconnecting to '%s'", nexus->login_host);
        pn_parser_reset(nexus->parser);
        nexus->parser_state = 0;

        nexus->open_handler = g_signal_connect(nexus->conn, "open", G_CALLBACK(login_open_cb), nexus);
        pn_node_connect(nexus->conn, nexus->login_host, 443);
        return;
    }
    else if (strstr(header, "HTTP/1.1 401 Unauthorized")) {
        const char *tmp;
        gchar *error = NULL;

        if ((tmp = strstr(header, "WWW-Authenticate"))) {
            if ((tmp = strstr(tmp, "cbtxt="))) {
                const char *c;
                char *tmp2;

                tmp += strlen("cbtxt=");

                c = strchr(tmp, '\n');
                if (!c)
                    c = tmp + strlen(tmp);

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

        msn_session_set_error(session, MSN_ERROR_AUTH, error);
        g_free(error);
        return;
    }
    else if (strstr(header, "HTTP/1.1 503 Service Unavailable")) {
        msn_session_set_error(session, MSN_ERROR_SERV_UNAVAILABLE, NULL);
        return;
    }

parse_error:
    msn_session_set_error(session, MSN_ERROR_AUTH, _("nexus parse error"));
}
Ejemplo n.º 6
0
static void
lst_cmd (MsnCmdProc *cmdproc,
         MsnCommand *cmd)
{
    MsnSession *session = cmdproc->session;
    const gchar *passport = NULL;
    struct pn_contact *user;
    gchar *friendly = NULL;
    const gchar *user_guid = NULL;
    int list_op = -1;
    gint type;
    guint i;

    for (i = 0; i < cmd->param_count; i++)
    {
        const char *chopped_str;

        chopped_str = cmd->params[i] + 2;

        /* Check for Name/email. */
        if (strncmp (cmd->params[i], "N=", 2) == 0)
            passport = chopped_str;
        /* Check for Friendlyname. */
        else if (strncmp (cmd->params[i], "F=", 2) == 0)
            friendly = pn_url_decode (chopped_str);
        /* Check for Contact GUID. */
        else if (strncmp (cmd->params[i], "C=", 2) == 0)
            user_guid = chopped_str;
        else
            break;
    }

    list_op = g_ascii_strtod (cmd->params[i++], NULL);
    type = g_ascii_strtod (cmd->params[i++], NULL);

    user = pn_contact_new (session->contactlist);
    pn_contact_set_passport (user, passport);
    pn_contact_set_guid (user, user_guid);

    session->sync->last_user = user;

    /* TODO: This can be improved */

    if (list_op & MSN_LIST_FL_OP)
    {
        if (cmd->params[i])
        {
            gchar **c;
            gchar **tokens;
            const gchar *group_guids;
            GSList *group_ids;

            group_guids = cmd->params[i];

            group_ids = NULL;

            tokens = g_strsplit (group_guids, ",", -1);

            for (c = tokens; *c; c++)
            {
                group_ids = g_slist_append (group_ids, g_strdup (*c));
            }

            g_strfreev (tokens);

            msn_got_lst_contact (session, user, friendly, list_op, group_ids);

            g_slist_foreach (group_ids, (GFunc) g_free, NULL);
            g_slist_free (group_ids);
        }
        else
        {
            msn_got_lst_contact (session, user, friendly, list_op, NULL);
        }
    }
    else
    {
        msn_got_lst_contact (session, user, friendly, list_op, NULL);
    }

    g_free (friendly);

    session->sync->num_users++;

    if (session->sync->num_users == session->sync->total_users)
    {
        cmdproc->cbs_table = session->sync->old_cbs_table;

        msn_session_finish_login (session);

        msn_sync_destroy (session->sync);
        session->sync = NULL;
    }
}