Example #1
0
void
pn_http_server_free (PnHttpServer *http_conn)
{
    pn_log ("begin");
    g_object_unref (http_conn);
    pn_log ("end");
}
Example #2
0
void
pn_node_free (PnNode *conn)
{
    g_return_if_fail (conn != NULL);
    pn_log ("begin");
    g_object_unref (conn);
    pn_log ("end");
}
Example #3
0
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");
}
Example #4
0
static void
connect_cb (gpointer data,
            gint source,
            const gchar *error_message)
{
    PnNode *conn;

    pn_log ("begin");

    conn = PN_NODE (data);
    conn->connect_data = NULL;

    g_object_ref (conn);

    if (source >= 0)
    {
        GIOChannel *channel;

        conn->stream = pn_stream_new (source);
        channel = conn->stream->channel;

        PN_NODE_GET_CLASS (conn)->channel_setup (conn, channel);

        conn->status = PN_NODE_STATUS_OPEN;

        pn_info ("connected: conn=%p,channel=%p", conn, channel);
        conn->read_watch = g_io_add_watch (channel, G_IO_IN, read_cb, conn);
#if 0
        g_io_add_watch (channel, G_IO_ERR | G_IO_HUP | G_IO_NVAL, close_cb, conn);
#endif
    }
    else
    {
        /* pn_error ("connection error: conn=%p,msg=[%s]", conn, error_message); */
        conn->error = g_error_new_literal (PN_NODE_ERROR, PN_NODE_ERROR_OPEN,
                                           error_message ? error_message : "Unable to connect");

        pn_node_error (conn);
    }

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

    g_object_unref (conn);

    pn_log ("end");
}
Example #5
0
static gboolean
read_cb (GIOChannel *source,
         GIOCondition condition,
         gpointer data)
{
    PnNode *conn;
    gchar buf[PN_BUF_LEN + 1];
    gsize bytes_read;

    pn_log ("begin");

    conn = PN_NODE (data);

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

    g_object_ref (conn);

    {
        GIOStatus status = G_IO_STATUS_NORMAL;

        status = pn_node_read (conn, buf, PN_BUF_LEN, &bytes_read, NULL);

        if (status == G_IO_STATUS_AGAIN)
        {
            g_object_unref (conn);
            return TRUE;
        }

        if (status == G_IO_STATUS_EOF)
        {
            conn->error = g_error_new (PN_NODE_ERROR, PN_NODE_ERROR_OPEN, "End of stream");
        }

        if (conn->error)
        {
            pn_node_error (conn);
            g_object_unref (conn);
            return FALSE;
        }
    }

    pn_node_parse (conn, buf, bytes_read);

    g_object_unref (conn);

    pn_log ("end");

    return TRUE;
}
Example #6
0
void
pn_peer_call_free(struct pn_peer_call *call)
{
    MsnSession *session;

    if (!call)
	    return;

    pn_log("call=%p", call);

    if (call->timer)
        g_source_remove(call->timer);

    g_free(call->id);
    g_free(call->branch);
    g_free(call->data_info);

    session = pn_peer_link_get_session(call->link);

    if (call->end_cb)
        call->end_cb(call, session);

    pn_peer_link_remove_call(call->link, call);

    if (call->xfer)
        purple_xfer_unref(call->xfer);

    if (call->swboard)
        call->swboard->calls = g_list_remove(call->swboard->calls, call);

    g_free(call);
}
Example #7
0
PnNode *
pn_node_new (gchar *name,
             PnNodeType type)
{
    PnNode *conn;

    pn_log ("begin");

    conn = PN_NODE (g_type_create_instance (PN_NODE_TYPE));

    conn->name = g_strdup (name);
    conn->type = type;

    pn_log ("end");

    return conn;
}
Example #8
0
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");
}
Example #9
0
static void
open_cb (PnNode *conn,
         RoamingRequest *roaming_request)
{
    g_return_if_fail (conn);

    pn_log ("begin");

    g_signal_handler_disconnect (conn, roaming_request->open_sig_handler);
    roaming_request->open_sig_handler = 0;

    if (roaming_request->type == PN_GET_PROFILE)
        send_get_profile_request (conn, roaming_request);
    else if (roaming_request->type == PN_UPDATE_PROFILE)
        send_update_profile_request (conn, roaming_request);

    pn_log ("end");
}
Example #10
0
void camera_spawn_thread(Camera *camera, const Modules *modules)
{
    camera->thread_alive = true;
    if (pthread_create(&camera->camera_thread, NULL, camera_thread, (void *)modules))
    {
        pn_log("Failed to create camera thread");
        camera->thread_alive = false;
    }
}
Example #11
0
PnHttpServer *
pn_http_server_new (const gchar *name)
{
    PnHttpServer *http_conn;

    pn_log ("begin");

    http_conn = PN_HTTP_SERVER (g_type_create_instance (PN_HTTP_SERVER_TYPE));

    {
        PnNode *tmp = PN_NODE (http_conn);
        tmp->name = g_strdup (name);
        tmp->type = PN_NODE_HTTP;
    }

    pn_log ("end");

    return http_conn;
}
Example #12
0
void pn_preference_set_int(PNPreferenceType key, int val)
{
    if (prefs[key].type != INT)
    {
        pn_log("ERROR: Attempting to set invalid int pref %d", key);
        return;
    }

    pn_preference_set(key, &val);
}
Example #13
0
void pn_preference_set_string(PNPreferenceType key, const char *val)
{
    if (prefs[key].type != STRING)
    {
        pn_log("ERROR: Attempting to set invalid string pref %d", key);
        return;
    }

    pn_preference_set(key, &val);
}
Example #14
0
void pn_preference_set_char(PNPreferenceType key, unsigned char val)
{
    if (prefs[key].type != CHAR)
    {
        pn_log("ERROR: Attempting to set invalid char pref %d", key);
        return;
    }

    pn_preference_set(key, &val);
}
Example #15
0
static void
dispose (GObject *obj)
{
    PnNode *conn = PN_NODE (obj);

    pn_log ("begin");

    if (conn->next)
    {
        g_signal_handler_disconnect (conn->next, conn->open_sig_handler);
        g_signal_handler_disconnect (conn->next, conn->close_sig_handler);
        g_signal_handler_disconnect (conn->next, conn->error_sig_handler);
        pn_node_free (conn->next);
        conn->next = NULL;
    }

    parent_class->dispose (obj);

    pn_log ("end");
}
Example #16
0
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");
}
Example #17
0
char *pn_preference_string(PNPreferenceType key)
{
    if (prefs[key].type == STRING)
    {
        pthread_mutex_lock(&access_mutex);
        char *ret = strdup(prefs[key].value.s);
        pthread_mutex_unlock(&access_mutex);
        return ret;
    }

    pn_log("ERROR: Attempting to access preference %d as a string", key);
    return strdup("Invalid key");
}
Example #18
0
unsigned char pn_preference_char(PNPreferenceType key)
{
    if (prefs[key].type == CHAR)
    {
        pthread_mutex_lock(&access_mutex);
        unsigned char ret = prefs[key].value.c;
        pthread_mutex_unlock(&access_mutex);
        return ret;
    }

    pn_log("ERROR: Attempting to access preference %d as a char", key);
    return 0;
}
Example #19
0
int pn_preference_int(PNPreferenceType key)
{
    if (prefs[key].type == INT)
    {
        pthread_mutex_lock(&access_mutex);
        int ret = prefs[key].value.i;
        pthread_mutex_unlock(&access_mutex);
        return ret;
    }

    pn_log("ERROR: Attempting to access preference %d as an int", key);
    return 0;
}
Example #20
0
MsnMessage *
msn_message_ref(MsnMessage *msg)
{
    g_return_val_if_fail(msg != NULL, NULL);

    msg->ref_count++;

#ifdef PECAN_DEBUG_MSG
    pn_log ("msg=%p,ref_count=%d", msg, msg->ref_count);
#endif

    return msg;
}
Example #21
0
static void
open_cb (PnNode *next,
         gpointer data)
{
    PnNode *conn;

    conn = PN_NODE (data);

    pn_log ("begin");

    conn->status = PN_NODE_STATUS_OPEN;

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

    g_signal_handler_disconnect (next, conn->open_sig_handler);
    conn->open_sig_handler = 0;

    pn_log ("end");
}
Example #22
0
static void
error_cb (PnNode *next,
          gpointer data)
{
    PnNode *conn;

    conn = PN_NODE (data);

    pn_log ("begin");

    if (next->error)
    {
        g_propagate_error (&conn->error, next->error);
        next->error = NULL;
    }

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

    pn_log ("end");
}
Example #23
0
static gboolean
timeout(gpointer data)
{
    struct pn_peer_call *call;

    call = data;

    pn_log("call=%p", call);

    if (!call->pending) {
        pn_peer_call_unref(call);
        return FALSE;
    }

    return TRUE;
}
Example #24
0
static GIOStatus
read_impl (PnNode *conn,
           gchar *buf,
           gsize count,
           gsize *ret_bytes_read,
           GError **error)
{
    GIOStatus status = G_IO_STATUS_NORMAL;

    pn_debug ("name=%s", conn->name);

    if (conn->next)
    {
        pn_error ("whaaat");
        conn->next->prev = conn;
        status = pn_node_read (conn->next, buf, count, ret_bytes_read, error);
        conn->next->prev = NULL;
    }
    else
    {
        GError *tmp_error = NULL;
        gsize bytes_read = 0;

        pn_debug ("stream=%p", conn->stream);

        status = pn_stream_read (conn->stream, buf, count, &bytes_read, &tmp_error);

        if (status != G_IO_STATUS_NORMAL)
        {
            pn_info ("not normal: status=%d (%s)",
                     status, status_to_str (status));
        }

        pn_log ("bytes_read=%zu", bytes_read);

        if (ret_bytes_read)
            *ret_bytes_read = bytes_read;

        if (tmp_error)
        {
            conn->error = g_error_copy (tmp_error);
            g_propagate_error (error, tmp_error);
        }
    }

    return status;
}
Example #25
0
void
msn_message_destroy(MsnMessage *msg)
{
    if (!msg)
        return;

#ifdef PECAN_DEBUG_MSG
    pn_log ("msg=%p", msg);
#endif

    if (msg->nak_cb)
        msg->nak_cb(msg, msg->ack_data);

    /** @todo this is ugly, but we really need to kill the pending
     * transactions to avoid further ack/nak handling . */
    {
        MsnTransaction *trans;

        trans = msg->trans;

        if (trans)
        {
            trans->error_cb = NULL;

            if (trans->callbacks && trans->has_custom_callbacks)
                g_hash_table_destroy (trans->callbacks);

            trans->callbacks = NULL;

            msn_transaction_unref (trans);

            msg->trans = NULL;
        }
    }

    g_free(msg->remote_user);
    g_free(msg->body);
    g_free(msg->content_type);
    g_free(msg->charset);

    g_hash_table_destroy(msg->attr_table);
    g_list_free(msg->attr_list);

    g_free(msg);
}
Example #26
0
MsnMessage *
msn_message_new(MsnMsgType type)
{
    MsnMessage *msg;

    msg = g_new0(MsnMessage, 1);
    msg->type = type;

#ifdef PECAN_DEBUG_MSG
    pn_log ("msg=%p,type=%d", msg, type);
#endif

    msg->attr_table = g_hash_table_new_full(g_str_hash, g_str_equal,
                                            g_free, g_free);

    msn_message_ref(msg);

    return msg;
}
Example #27
0
struct pn_peer_call *
pn_peer_call_new(struct pn_peer_link *link)
{
    struct pn_peer_call *call;

    call = g_new0(struct pn_peer_call, 1);

    pn_log("call=%p", call);

    call->link = link;

    pn_peer_link_add_call(link, call);

    /* The official client seems to timeout calls after 5 minutes */
    call->timer = g_timeout_add_seconds (5 * 60, timeout, call);

    call->ref_count++;

    return call;
}
Example #28
0
MsnMessage *
msn_message_unref(MsnMessage *msg)
{
    g_return_val_if_fail(msg != NULL, NULL);
    g_return_val_if_fail(msg->ref_count > 0, NULL);

    msg->ref_count--;

#ifdef PECAN_DEBUG_MSG
    pn_log ("msg=%p,ref_count=%d", msg, msg->ref_count);
#endif

    if (msg->ref_count == 0)
    {
        msn_message_destroy(msg);

        return NULL;
    }

    return msg;
}
Example #29
0
static GIOStatus
write_impl (PnNode *conn,
            const gchar *buf,
            gsize count,
            gsize *ret_bytes_written,
            GError **error)
{
    GIOStatus status = G_IO_STATUS_NORMAL;

    pn_debug ("name=%s", conn->name);

    if (conn->next)
    {
        PnNode *next;

        next = conn->next;

        /* conn->next has already a ref from conn, but let's just be sure and
         * ref anyway */
        g_object_ref (next);
        next->prev = conn;
        status = pn_node_write (next, buf, count, ret_bytes_written, error);
        next->prev = NULL;
        g_object_unref (next);
    }
    else
    {
        GError *tmp_error = NULL;
        gsize bytes_written = 0;

        pn_debug ("stream=%p", conn->stream);

        status = pn_stream_write_full (conn->stream, buf, count, &bytes_written, &tmp_error);

        pn_log ("bytes_written=%zu", bytes_written);

        if (status == G_IO_STATUS_NORMAL)
        {
            if (bytes_written < count)
            {
                /* This shouldn't happen, right? */
                /* It doesn't seem to happen, but keep checking for now. */
                pn_error ("write check: %zu < %zu", bytes_written, count);
            }
        }
        else
        {
            pn_warning ("not normal: status=%d (%s)",
                        status, status_to_str (status));
        }

        if (ret_bytes_written)
            *ret_bytes_written = bytes_written;

        if (tmp_error)
        {
            conn->error = g_error_copy (tmp_error);
            g_propagate_error (error, tmp_error);
        }
    }

    return status;
}
Example #30
0
static inline void
send_update_profile_request (PnNode *conn,
                             RoamingRequest *roaming_request)
{
    gchar *body;
    gchar *header;
    gsize body_len;
    PnAuth *auth = roaming_request->roaming_session->session->auth;
    gchar *friendly = roaming_request->value;
    gchar *psm = roaming_request->extra_value;

    pn_log ("begin");

    body = g_strdup_printf ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"
                            "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n"
                            "<soap:Header>\r\n"
                            "<AffinityCacheHeader xmlns=\"http://www.msn.com/webservices/storage/w10\">\r\n"
                            "<CacheKey>%s</CacheKey>\r\n"
                            "</AffinityCacheHeader>\r\n"
                            "<StorageApplicationHeader xmlns=\"http://www.msn.com/webservices/storage/w10\">\r\n"
                            "<ApplicationID>Messenger Client 8.5</ApplicationID>\r\n"
                            "<Scenario>RoamingIdentityChanged</Scenario>\r\n"
                            "</StorageApplicationHeader>\r\n"
                            "<StorageUserHeader xmlns=\"http://www.msn.com/webservices/storage/w10\">\r\n"
                            "<Puid>0</Puid>\r\n"
                            "<TicketToken>%s</TicketToken>\r\n"
                            "</StorageUserHeader>\r\n"
                            "</soap:Header>\r\n"
                            "<soap:Body>\r\n"
                            "<UpdateProfile xmlns=\"http://www.msn.com/webservices/storage/w10\">\r\n"
                            "<profile>\r\n"
                            "<ResourceID>%s</ResourceID>\r\n"
                            "<ExpressionProfile>\r\n"
                            "<FreeText>Update</FreeText>\r\n"
                            "%s%s%s\r\n"
                            "%s%s%s"
                            "<Flags>0</Flags>\r\n"
                            "</ExpressionProfile>\r\n"
                            "</profile>\r\n"
                            "</UpdateProfile>\r\n"
                            "</soap:Body>\r\n"
                            "</soap:Envelope>",
                            roaming_request->roaming_session->cachekey,
                            auth->security_token.storage_msn_com,
                            roaming_request->roaming_session->resource_id,
                            friendly ? "<DisplayName>" : "",
                            friendly ? friendly : "",
                            friendly ? "</DisplayName>\r\n" : "",
                            psm ? "<PersonalStatus>" : "",
                            psm ? psm : "",
                            psm ? "</PersonalStatus>\r\n" : "");

    body_len = strlen (body);

    header = g_strdup_printf ("POST /storageservice/SchematizedStore.asmx HTTP/1.1\r\n"
                              "Accept: */*\r\n"
                              "SOAPAction: \"http://www.msn.com/webservices/storage/w10/UpdateProfile\"\r\n"
                              "Content-Type: text/xml; charset=utf-8\r\n"
                              "Content-Length: %zu\r\n"
                              "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)\r\n"
                              "Host: %s\r\n"
                              "Connection: Keep-Alive\r\n"
                              "Cache-Control: no-cache\r\n"
                              "\r\n%s",
                              body_len,
                              roaming_request->roaming_session->hostname ? roaming_request->roaming_session->hostname : "storage.msn.com",
                              body);

    g_free (body);

    pn_debug ("header=[%s]", header);

    {
        gsize len;
        pn_node_write (conn, header, strlen (header), &len, NULL);
        pn_debug ("write_len=%zu", len);
    }

    g_free (header);

    pn_log ("end");
}