コード例 #1
0
ファイル: pn_node.c プロジェクト: hinablue/msn-pecan
static void
close_impl (PnNode *conn)
{
    g_return_if_fail (conn);

    if (conn->status == PN_NODE_STATUS_CLOSED) {
        pn_log ("already closed: %p", conn);
        return;
    }

    pn_log ("begin");

    pn_info ("closing '%s'", conn->name);
    pn_debug ("conn=%p,name=%s", conn, conn->name);

    conn->status = PN_NODE_STATUS_CLOSED;

    g_free (conn->hostname);
    conn->hostname = NULL;

    if (conn->next) {
        pn_node_close (conn->next);
        goto leave;
    }

#if defined(USE_GIO)
    if (conn->socket_conn) {
        g_object_unref(conn->socket_conn);
        conn->socket_conn = NULL;
    }
#else
#if defined(HAVE_LIBPURPLE)
    if (conn->connect_data) {
        purple_proxy_connect_cancel (conn->connect_data);
        conn->connect_data = NULL;
    }
#endif
    if (conn->read_watch)
    {
        g_source_remove (conn->read_watch);
        conn->read_watch = 0;
    }
#endif

    if (conn->stream)
    {
        pn_info ("stream shutdown: %p", conn->stream);
        pn_stream_free (conn->stream);
        conn->stream = NULL;
    }
    else
        pn_error ("not connected: conn=%p", conn);

leave:
    conn->status = PN_NODE_STATUS_CLOSED;

    pn_log ("end");
}
コード例 #2
0
ファイル: pn_node.c プロジェクト: allanfreitas/msn-pecan
static void
finalize (GObject *obj)
{
    PnNode *conn = PN_NODE (obj);

    pn_node_close (conn);

    g_free (conn->name);
    parent_class->finalize (obj);
}
コード例 #3
0
ファイル: session.c プロジェクト: mikecpt/msn-pecan
void
msn_session_disconnect (MsnSession *session)
{
    g_return_if_fail (session);
    g_return_if_fail (session->connected);

    session->connected = FALSE;

    g_hash_table_remove_all (session->conversations);
    g_hash_table_remove_all (session->chats);

    if (session->notification)
        msn_notification_close (session->notification);

    if (session->http_conn)
        pn_node_close (session->http_conn);
}
コード例 #4
0
ファイル: pn_node.c プロジェクト: felipec/msn-pecan
static void
connect_impl (PnNode *conn,
              const gchar *hostname,
              gint port)
{
    g_return_if_fail (conn);

    pn_log ("begin");

    pn_debug ("conn=%p,name=%s", conn, conn->name);
    pn_debug ("hostname=%s,port=%d", hostname, port);
    pn_debug ("next=%p", conn->next);

    g_free (conn->hostname);
    conn->hostname = g_strdup (hostname);
    conn->port = port;

    if (conn->next)
    {
        conn->status = PN_NODE_STATUS_CONNECTING;

        conn->next->prev = conn;
        pn_node_connect (conn->next, hostname, port);
        conn->next->prev = NULL;
    }
    else
    {
        pn_node_close (conn);

        conn->status = PN_NODE_STATUS_CONNECTING;

#if defined(USE_GIO)
        GSocketClient *client;
        client = g_socket_client_new();
        conn->socket_cancel = g_cancellable_new();
        g_socket_client_connect_to_host_async(client, hostname, port,
                                              conn->socket_cancel, connect_cb, conn);
#elif defined(HAVE_LIBPURPLE)
        conn->connect_data = purple_proxy_connect (NULL, msn_session_get_user_data (conn->session),
                             hostname, port, connect_cb, conn);
#endif
    }

    pn_log ("end");
}
コード例 #5
0
ファイル: pn_node.c プロジェクト: allanfreitas/msn-pecan
static void
close_cb (PnNode *next,
          gpointer data)
{
    PnNode *conn;

    conn = PN_NODE (data);

    pn_log ("begin");

    pn_node_close (conn);

    {
        PnNodeClass *class;
        class = g_type_class_peek (PN_NODE_TYPE);
        g_signal_emit (G_OBJECT (conn), class->close_sig, 0, conn);
    }

    pn_log ("end");
}
コード例 #6
0
ファイル: pn_roaming.c プロジェクト: dfiloni/msn-pecan
static void
read_cb (PnNode *conn,
         gpointer data)
{
    RoamingRequest *roaming_request;
    GIOStatus status = G_IO_STATUS_NORMAL;
    gchar *str = NULL;
    gboolean got_hostname = FALSE;

    roaming_request = data;

    while (roaming_request->parser_state == 0)
    {
        gsize terminator_pos;

        status = pn_parser_read_line (roaming_request->parser, &str, NULL, &terminator_pos, NULL);

        if (status == G_IO_STATUS_AGAIN)
            return;

        if (status != G_IO_STATUS_NORMAL)
            goto leave;

        if (str)
        {
            str[terminator_pos] = '\0';

            if (strncmp (str, "Content-Length: ", 16) == 0)
                roaming_request->content_size = atoi(str + 16);

            if (strncmp (str, "Location: ", 10) == 0)
                roaming_request->location = g_strdup (str + 10);

            /* now comes the content */
            if (str[0] == '\0') {
                roaming_request->parser_state++;
                break;
            }

            g_free (str);
        }
    }

    if (roaming_request->parser_state == 1)
    {
        gchar *body;

        status = pn_parser_read (roaming_request->parser, &body, roaming_request->content_size, NULL);

        if (status == G_IO_STATUS_AGAIN)
            return;

        if (status != G_IO_STATUS_NORMAL)
            goto leave;

        if (roaming_request->location != NULL)
        {
            gchar *cur;
            cur = strstr (roaming_request->location, "://") + 3;
            if (cur)
            {
                gchar *end = strchr (cur, '/');

                g_free (roaming_request->roaming_session->hostname);
                roaming_request->roaming_session->hostname = g_strndup (cur, end - cur);

                got_hostname = TRUE;
                goto leave;
            }
        }

        pn_debug ("%s", body);

        if (roaming_request->type == PN_GET_PROFILE)
        {
            char *cachekey;
            pn_parse_xml_tag (body, "CacheKey", &cachekey);
            if (cachekey)
            {
                g_free (roaming_request->roaming_session->cachekey);
                roaming_request->roaming_session->cachekey = cachekey;
            }
        }

        if (roaming_request->type == PN_GET_PROFILE)
            process_get_profile (roaming_request, body);
        /* else if (roaming_request->type == PN_UPDATE_PROFILE) */

        g_free(body);
    }

leave:
    pn_node_close (conn);
    next_request (roaming_request->roaming_session, got_hostname);
}