Esempio n. 1
0
void display_error_message(QWidget* host_window,
                           const QString& error_summary,
                           const QString& error_description) {
    QMessageBox::critical(host_window,
                          error_summary,
                          generate_error_message(error_description));
}
Esempio n. 2
0
/**
 * This function parses the given response from a clientLogin request
 * and extracts the useful information.
 *
 * @param gc           The PurpleConnection.  If the response data does
 *                     not indicate then purple_connection_error_reason()
 *                     will be called to close this connection.
 * @param response     The response data from the clientLogin request.
 * @param response_len The length of the above response, or -1 if
 *                     @response is NUL terminated.
 * @param token        If parsing was successful then this will be set to
 *                     a newly allocated string containing the token.  The
 *                     caller should g_free this string when it is finished
 *                     with it.  On failure this value will be untouched.
 * @param secret       If parsing was successful then this will be set to
 *                     a newly allocated string containing the secret.  The
 *                     caller should g_free this string when it is finished
 *                     with it.  On failure this value will be untouched.
 * @param hosttime     If parsing was successful then this will be set to
 *                     the time on the OpenAuth Server in seconds since the
 *                     Unix epoch.  On failure this value will be untouched.
 *
 * @return TRUE if the request was successful and we were able to
 *         extract all info we need.  Otherwise FALSE.
 */
static gboolean parse_client_login_response(PurpleConnection *gc, const gchar *response, gsize response_len, char **token, char **secret, time_t *hosttime)
{
    xmlnode *response_node, *tmp_node, *data_node;
    xmlnode *secret_node = NULL, *hosttime_node = NULL, *token_node = NULL, *tokena_node = NULL;
    char *tmp;

    /* Parse the response as XML */
    response_node = xmlnode_from_str(response, response_len);
    if (response_node == NULL)
    {
        char *msg;
        purple_debug_error("oscar", "clientLogin could not parse "
                           "response as XML: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_CLIENT_LOGIN);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        return FALSE;
    }

    /* Grab the necessary XML nodes */
    tmp_node = xmlnode_get_child(response_node, "statusCode");
    data_node = xmlnode_get_child(response_node, "data");
    if (data_node != NULL) {
        secret_node = xmlnode_get_child(data_node, "sessionSecret");
        hosttime_node = xmlnode_get_child(data_node, "hostTime");
        token_node = xmlnode_get_child(data_node, "token");
        if (token_node != NULL)
            tokena_node = xmlnode_get_child(token_node, "a");
    }

    /* Make sure we have a status code */
    if (tmp_node == NULL || (tmp = xmlnode_get_data_unescaped(tmp_node)) == NULL) {
        char *msg;
        purple_debug_error("oscar", "clientLogin response was "
                           "missing statusCode: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_CLIENT_LOGIN);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        xmlnode_free(response_node);
        return FALSE;
    }

    /* Make sure the status code was 200 */
    if (strcmp(tmp, "200") != 0)
    {
        int status_code, status_detail_code = 0;

        status_code = atoi(tmp);
        g_free(tmp);
        tmp_node = xmlnode_get_child(response_node, "statusDetailCode");
        if (tmp_node != NULL && (tmp = xmlnode_get_data_unescaped(tmp_node)) != NULL) {
            status_detail_code = atoi(tmp);
            g_free(tmp);
        }

        purple_debug_error("oscar", "clientLogin response statusCode "
                           "was %d (%d): %s\n", status_code, status_detail_code, response);

        if (status_code == 330 && status_detail_code == 3011) {
            PurpleAccount *account = purple_connection_get_account(gc);
            if (!purple_account_get_remember_password(account))
                purple_account_set_password(account, NULL);
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
                                           _("Incorrect password"));
        } else if (status_code == 330 && status_detail_code == 3015) {
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_AUTHENTICATION_FAILED,
                                           _("Server requested that you fill out a CAPTCHA in order to "
                                             "sign in, but this client does not currently support CAPTCHAs."));
        } else if (status_code == 401 && status_detail_code == 3019) {
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_OTHER_ERROR,
                                           _("AOL does not allow your screen name to authenticate here"));
        } else {
            char *msg;
            msg = generate_error_message(response_node,
                                         URL_CLIENT_LOGIN);
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_OTHER_ERROR, msg);
            g_free(msg);
        }

        xmlnode_free(response_node);
        return FALSE;
    }
    g_free(tmp);

    /* Make sure we have everything else */
    if (data_node == NULL || secret_node == NULL ||
            token_node == NULL || tokena_node == NULL)
    {
        char *msg;
        purple_debug_error("oscar", "clientLogin response was missing "
                           "something: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_CLIENT_LOGIN);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        xmlnode_free(response_node);
        return FALSE;
    }

    /* Extract data from the XML */
    *token = xmlnode_get_data_unescaped(tokena_node);
    *secret = xmlnode_get_data_unescaped(secret_node);
    tmp = xmlnode_get_data_unescaped(hosttime_node);
    if (*token == NULL || **token == '\0' || *secret == NULL || **secret == '\0' || tmp == NULL || *tmp == '\0')
    {
        char *msg;
        purple_debug_error("oscar", "clientLogin response was missing "
                           "something: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_CLIENT_LOGIN);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        g_free(*token);
        g_free(*secret);
        g_free(tmp);
        xmlnode_free(response_node);
        return FALSE;
    }

    *hosttime = strtol(tmp, NULL, 10);
    g_free(tmp);

    xmlnode_free(response_node);

    return TRUE;
}
Esempio n. 3
0
static gboolean parse_start_oscar_session_response(PurpleConnection *gc, const gchar *response, gsize response_len, char **host, unsigned short *port, char **cookie, char **tls_certname)
{
    xmlnode *response_node, *tmp_node, *data_node;
    xmlnode *host_node = NULL, *port_node = NULL, *cookie_node = NULL, *tls_node = NULL;
    gboolean use_tls;
    char *tmp;
    guint code;

    use_tls = purple_account_get_bool(purple_connection_get_account(gc), "use_ssl", OSCAR_DEFAULT_USE_SSL);

    /* Parse the response as XML */
    response_node = xmlnode_from_str(response, response_len);
    if (response_node == NULL)
    {
        char *msg;
        purple_debug_error("oscar", "startOSCARSession could not parse "
                           "response as XML: %s\n", response);
        /* Note to translators: %s in this string is a URL */
        msg = generate_error_message(response_node,
                                     URL_START_OSCAR_SESSION);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        return FALSE;
    }

    /* Grab the necessary XML nodes */
    tmp_node = xmlnode_get_child(response_node, "statusCode");
    data_node = xmlnode_get_child(response_node, "data");
    if (data_node != NULL) {
        host_node = xmlnode_get_child(data_node, "host");
        port_node = xmlnode_get_child(data_node, "port");
        cookie_node = xmlnode_get_child(data_node, "cookie");
        tls_node = xmlnode_get_child(data_node, "tlsCertName");
    }

    /* Make sure we have a status code */
    if (tmp_node == NULL || (tmp = xmlnode_get_data_unescaped(tmp_node)) == NULL) {
        char *msg;
        purple_debug_error("oscar", "startOSCARSession response was "
                           "missing statusCode: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_START_OSCAR_SESSION);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        xmlnode_free(response_node);
        return FALSE;
    }

    /* Make sure the status code was 200 */
    code = atoi(tmp);
    if (code != 200)
    {
        xmlnode *status_detail_node;
        guint status_detail = 0;

        status_detail_node = xmlnode_get_child(response_node,
                                               "statusDetailCode");
        if (status_detail_node) {
            gchar *data = xmlnode_get_data(status_detail_node);
            if (data) {
                status_detail = atoi(data);
                g_free(data);
            }
        }

        purple_debug_error("oscar", "startOSCARSession response statusCode "
                           "was %s: %s\n", tmp, response);

        if ((code == 401 && status_detail != 1014) || code == 607)
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_OTHER_ERROR,
                                           _("You have been connecting and disconnecting too "
                                             "frequently. Wait ten minutes and try again. If "
                                             "you continue to try, you will need to wait even "
                                             "longer."));
        else {
            char *msg;
            msg = generate_error_message(response_node,
                                         URL_START_OSCAR_SESSION);
            purple_connection_error_reason(gc,
                                           PURPLE_CONNECTION_ERROR_OTHER_ERROR, msg);
            g_free(msg);
        }

        g_free(tmp);
        xmlnode_free(response_node);
        return FALSE;
    }
    g_free(tmp);

    /* Make sure we have everything else */
    if (data_node == NULL || host_node == NULL ||
            port_node == NULL || cookie_node == NULL ||
            (use_tls && tls_node == NULL))
    {
        char *msg;
        purple_debug_error("oscar", "startOSCARSession response was missing "
                           "something: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_START_OSCAR_SESSION);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        xmlnode_free(response_node);
        return FALSE;
    }

    /* Extract data from the XML */
    *host = xmlnode_get_data_unescaped(host_node);
    tmp = xmlnode_get_data_unescaped(port_node);
    *cookie = xmlnode_get_data_unescaped(cookie_node);

    if (use_tls)
        *tls_certname = xmlnode_get_data_unescaped(tls_node);

    if (*host == NULL || **host == '\0' || tmp == NULL || *tmp == '\0' || *cookie == NULL || **cookie == '\0' ||
            (use_tls && (*tls_certname == NULL || **tls_certname == '\0')))
    {
        char *msg;
        purple_debug_error("oscar", "startOSCARSession response was missing "
                           "something: %s\n", response);
        msg = generate_error_message(response_node,
                                     URL_START_OSCAR_SESSION);
        purple_connection_error_reason(gc,
                                       PURPLE_CONNECTION_ERROR_NETWORK_ERROR, msg);
        g_free(msg);
        g_free(*host);
        g_free(tmp);
        g_free(*cookie);
        xmlnode_free(response_node);
        return FALSE;
    }

    *port = atoi(tmp);
    g_free(tmp);

    return TRUE;
}