示例#1
0
/**
 * Processes the error of a #SteamApiReq.
 *
 * @param sata   The #SteamData.
 * @param req    The #SteamApiReq.
 * @param logout TRUE to logout, otherwise FALSE.
 *
 * @return TRUE if an error exists, otherwise FALSE.
 **/
static gboolean steam_req_error(SteamData *sata, SteamApiReq *req,
                                gboolean logout)
{
    if (req->err == NULL)
        return FALSE;

    if (g_error_matches(req->err, STEAM_API_ERROR, STEAM_API_ERROR_EXPRIED)) {
        STEAM_UTIL_DEBUGLN("Relogging on due to expired session");
        steam_http_free_reqs(req->api->http);
        req = steam_api_req_new(req->api, steam_cb_relogon, sata);
        steam_api_req_logon(req);
        return TRUE;
    }

    if (g_error_matches(req->err, STEAM_HTTP_ERROR, STEAM_HTTP_ERROR_CLOSED)) {
        STEAM_UTIL_DEBUGLN("Request (%p) forcefully closed", req->req);
        /* Ignore closed HTTP connections */
        return TRUE;
    }

    STEAM_UTIL_DEBUGLN("Error: %s", req->err->message);
    imcb_error(sata->ic, "%s", req->err->message);

    if (logout) {
        STEAM_UTIL_DEBUGLN("Reconnecting due to error");
        imc_logout(sata->ic, logout);
    }

    return TRUE;
}
示例#2
0
/**
 * Implemented #SteamApiFunc for #steam_api_req_logon() for relogging.
 *
 * @param req  The #SteamApiReq.
 * @param data The user defined data, which is #SteamData.
 **/
static void steam_cb_relogon(SteamApiReq *req, gpointer data)
{
    SteamData *sata = data;

    if (steam_req_error(sata, req, TRUE))
        return;

    STEAM_UTIL_DEBUGLN("Relogon completed");

    /* Update the friend list for good measures */
    req = steam_api_req_new(req->api, steam_cb_friends, sata);
    steam_api_req_friends(req);
}
示例#3
0
static void steam_http_req_debug(SteamHttpReq *req, gboolean response,
                                 const gchar *header, const gchar *body)
{
    const gchar  *act;
    const gchar  *type;
    const gchar  *prot;
    gchar        *str;
    gchar       **ls;
    guint         i;

    if (req->err != NULL)
        str = g_strdup_printf(" (%s)", req->err->message);
    else if (req->status != NULL)
        str = g_strdup_printf(" (%s)", req->status);
    else
        str = g_strdup("");

    act  = response ? "Response" : "Request";
    type = (req->flags & STEAM_HTTP_REQ_FLAG_POST) ? "POST"  : "GET";
    prot = (req->flags & STEAM_HTTP_REQ_FLAG_SSL)  ? "https" : "http";

    STEAM_UTIL_DEBUGLN("%s %s (%p): %s://%s:%d%s%s", type, act, req,
                       prot, req->host, req->port, req->path, str);
    g_free(str);

    if (req->rsc > 0)
        STEAM_UTIL_DEBUGLN("Reattempt: #%u", req->rsc);

    if ((header != NULL) && (strlen(header) > 0)) {
        ls = g_strsplit(header, "\n", 0);

        for (i = 0; ls[i] != NULL; i++)
            STEAM_UTIL_DEBUGLN("  %s", ls[i]);

        g_strfreev(ls);
    } else {
        STEAM_UTIL_DEBUGLN("  ** No header data **");
        STEAM_UTIL_DEBUGLN("");
    }

    if ((body != NULL) && (strlen(body) > 0)) {
        ls = g_strsplit(body, "\n", 0);

        for (i = 0; ls[i] != NULL; i++)
            STEAM_UTIL_DEBUGLN("  %s", ls[i]);

        g_strfreev(ls);
    } else {
        STEAM_UTIL_DEBUGLN("  ** No body data **");
    }
}
示例#4
0
/**
 * Processes a #SteamApiMsg.
 *
 * @param sata The #SteamData.
 * @param msg  The #SteamUserMsg.
 * @param time The timestamp (UTC) of the message, or 0 for now.
 **/
static void steam_user_msg(SteamData *sata, SteamUserMsg *msg, gint64 time)
{
    SteamUserInfo *info = msg->info;
    bee_user_t    *bu;
    gchar         *str;
    guint32        f;
    gchar          sid[STEAM_ID_STR_MAX];

    STEAM_ID_STR(info->id, sid);
    STEAM_UTIL_DEBUGLN("Incoming message from %s (Type: %u, Act: %u)",
                       sid, msg->type, info->act);

    switch (msg->type) {
    case STEAM_USER_MSG_TYPE_EMOTE:
    case STEAM_USER_MSG_TYPE_SAYTEXT:
        bu = imcb_buddy_by_handle(sata->ic, sid);

        if ((bu != NULL) && (bu->flags & OPT_TYPING))
            imcb_buddy_typing(sata->ic, sid, 0);

        if (msg->type == STEAM_USER_MSG_TYPE_EMOTE)
            str = g_strconcat("/me ", msg->text, NULL);
        else
            str = g_strdup(msg->text);

        imcb_buddy_msg(sata->ic, sid, str, 0, time);
        g_free(str);
        return;

    case STEAM_USER_MSG_TYPE_LEFT_CONV:
        imcb_buddy_typing(sata->ic, sid, 0);
        return;

    case STEAM_USER_MSG_TYPE_RELATIONSHIP:
        goto relationship;

    case STEAM_USER_MSG_TYPE_TYPING:
        bu = imcb_buddy_by_handle(sata->ic, sid);

        if (G_UNLIKELY(bu == NULL))
            return;

        f = (bu->flags & OPT_TYPING) ? 0 : OPT_TYPING;
        imcb_buddy_typing(sata->ic, sid, f);
        return;

    default:
        steam_user_status(sata, info, NULL);
        return;
    }

relationship:
    switch (info->act) {
    case STEAM_USER_ACT_REMOVE:
    case STEAM_USER_ACT_IGNORE:
        imcb_remove_buddy(sata->ic, sid, NULL);
        return;

    case STEAM_USER_ACT_REQUEST:
        imcb_ask_auth(sata->ic, sid, info->nick);
        return;

    case STEAM_USER_ACT_ADD:
        imcb_add_buddy(sata->ic, sid, NULL);
        imcb_buddy_nick_hint(sata->ic, sid, info->nick);
        imcb_rename_buddy(sata->ic, sid, info->fullname);
        steam_user_status(sata, info, NULL);
        return;

    default:
        return;
    }
}