# HG changeset patch # User Nicolas Cornu # Date 1282578268 -7200 # Node ID 653fa009fea32d28a952c3ef3e3360a534a4eccf # Parent 35e603b584a3be91cab39dad07366419d8f97e37 Rename ->check() to newfrommessage and call it only on session-initiate. Use handle() instead for session-accept and other actions. diff -r 35e603b584a3 -r 653fa009fea3 jingle-ft/filetransfer.c --- a/jingle-ft/filetransfer.c Sat Aug 21 14:44:03 2010 +0200 +++ b/jingle-ft/filetransfer.c Mon Aug 23 17:44:28 2010 +0200 @@ -42,8 +42,9 @@ #include "filetransfer.h" -static gconstpointer check(JingleContent *cn, GError **err); -static gboolean handle(JingleAction action, gconstpointer data, LmMessageNode *node); +static gconstpointer newfrommessage(JingleContent *cn, GError **err); +static JingleHandleStatus handle(JingleAction action, gconstpointer data, + LmMessageNode *node, GError **err); static void tomessage(gconstpointer data, LmMessageNode *node); static gboolean handle_data(gconstpointer data, const gchar *data2, guint len); static void start(session_content *sc); @@ -79,14 +80,14 @@ }; static JingleAppFuncs funcs = { - .check = check, - .handle = handle, - .tomessage = tomessage, - .handle_data = handle_data, - .start = start, - .send = send, - .stop = stop, - .info = info + .newfrommessage = newfrommessage, + .handle = handle, + .tomessage = tomessage, + .handle_data = handle_data, + .start = start, + .send = send, + .stop = stop, + .info = info }; module_info_t info_jingle_ft = { @@ -108,7 +109,7 @@ * @param err contain an error of the domain JINGLE_CHECK_ERROR * @return a gconstpointer, which is a new allocated JingleFT */ -static gconstpointer check(JingleContent *cn, GError **err) +static gconstpointer newfrommessage(JingleContent *cn, GError **err) { JingleFT *ft = NULL; LmMessageNode *node; @@ -205,19 +206,19 @@ * @param node The node himself * @return TRUE if the action was handled, FALSE otherwise */ -static gboolean handle(JingleAction action, gconstpointer data, - LmMessageNode *node) +static JingleHandleStatus handle(JingleAction action, gconstpointer data, + LmMessageNode *node, GError **err) { if (action == JINGLE_SESSION_INFO) { if (!g_strcmp0(lm_message_node_get_attribute(node, "xmlns"), NS_JINGLE_APP_FT_INFO) && !g_strcmp0(node->name, "hash")) { ((JingleFT *)data)->hash = g_strdup(lm_message_node_get_value(node)); - return TRUE; + return JINGLE_STATUS_HANDLED; } - return FALSE; + return JINGLE_STATUS_NOT_HANDLED; } - return FALSE; + return JINGLE_STATUS_NOT_HANDLED; } static gboolean _is_md5_hash(const gchar *hash) @@ -258,10 +259,10 @@ //TODO: propagate the GError ? g_error_free(err); return FALSE; - } - jft->state = JINGLE_FT_STARTING; - status = g_io_channel_set_encoding(jft->outfile, NULL, &err); - if (status != G_IO_STATUS_NORMAL || err != NULL) { + } + jft->state = JINGLE_FT_STARTING; + status = g_io_channel_set_encoding(jft->outfile, NULL, &err); + if (status != G_IO_STATUS_NORMAL || err != NULL) { scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: %s %s", err->message, jft->name); g_error_free(err); @@ -270,7 +271,7 @@ } jft->state = JINGLE_FT_STARTING; - + status = g_io_channel_write_chars(jft->outfile, data, (gssize) len, &bytes_written, &err); if (status != G_IO_STATUS_NORMAL || err != NULL) { @@ -706,11 +707,11 @@ scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: File corrupt (%s)", jft->name); } else { - scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: transfer finished (%s)" + scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: Transfer finished (%s)" " and verified", jft->name); } } else { - scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: transfer finished (%s)" + scr_LogPrint(LPRINT_LOGNORM, "Jingle File Transfer: Transfer finished (%s)" " but not verified", jft->name); } } diff -r 35e603b584a3 -r 653fa009fea3 jingle-ibb/ibb.c --- a/jingle-ibb/ibb.c Sat Aug 21 14:44:03 2010 +0200 +++ b/jingle-ibb/ibb.c Mon Aug 23 17:44:28 2010 +0200 @@ -40,11 +40,13 @@ static LmMessageHandler* jingle_ibb_handler = NULL; -static gconstpointer check(JingleContent *cn, GError **err); +static gconstpointer newfrommessage(JingleContent *cn, GError **err); +static JingleHandleStatus handle(JingleAction action, gconstpointer data, + LmMessageNode *node, GError **err); static void tomessage(gconstpointer data, LmMessageNode *node); static gconstpointer new(void); static void send(session_content *sc, gconstpointer data, gchar *buf, gsize size); -static void init(session_content *sc, gconstpointer data); +static void init(session_content *sc); static void end(session_content *sc, gconstpointer data); static gchar *info(gconstpointer data); @@ -61,13 +63,14 @@ const gchar *deps[] = { "jingle", NULL }; static JingleTransportFuncs funcs = { - .check = check, - .tomessage = tomessage, - .new = new, - .send = send, - .init = init, - .end = end, - .info = info + .newfrommessage = newfrommessage, + .handle = handle, + .tomessage = tomessage, + .new = new, + .send = send, + .init = init, + .end = end, + .info = info }; module_info_t info_jingle_ibb = { @@ -84,7 +87,7 @@ /* Hash-Table of all emited JingleIBB struct */ static GHashTable *JingleIBBs = NULL; -static gconstpointer check(JingleContent *cn, GError **err) +static gconstpointer newfrommessage(JingleContent *cn, GError **err) { JingleIBB *ibb = NULL; LmMessageNode *node = cn->transport; @@ -121,6 +124,28 @@ return (gconstpointer) ibb; } +static JingleHandleStatus handle(JingleAction action, gconstpointer data, + LmMessageNode *node, GError **err) +{ + JingleIBB *jibb = (JingleIBB *)data; + const gchar *blocksizestr; + guint64 blocksize; + + if (action == JINGLE_SESSION_ACCEPT) { + const gchar *xmlns = lm_message_node_get_attribute(node, "xmlns"); + if (!g_strcmp0(xmlns, NS_JINGLE_TRANSPORT_IBB)) { + /* If the responder wishes to use a smaller block-size, the responder can + * specify that in the session-accept by returning a different value for + * the 'block-size' attribute. */ + blocksizestr = lm_message_node_get_attribute(node, "block-size"); + blocksize = g_ascii_strtoll(blocksizestr, NULL, 10); + jibb->blocksize = (blocksize < jibb->blocksize) ? blocksize : jibb->blocksize; + return JINGLE_STATUS_HANDLED; + } + } + return JINGLE_STATUS_NOT_HANDLED; +} + LmHandlerResult jingle_ibb_handle_iq(LmMessageHandler *handler, LmConnection *connection, LmMessage *message, gpointer user_data) @@ -311,14 +336,9 @@ } } -static void init(session_content *sc, gconstpointer data) +static void init(session_content *sc) { - JingleIBB *jibb = (JingleIBB*)data; - JingleSession *sess = session_find_by_sid(sc->sid, sc->from); - SessionContent *sc2 = session_find_sessioncontent(sess, sc->name); - JingleIBB *jibb2 = (JingleIBB*)sc2->transport; - - jibb2->blocksize = (jibb->blocksize < jibb2->blocksize)?jibb->blocksize:jibb2->blocksize; + return; } static void end(session_content *sc, gconstpointer data) diff -r 35e603b584a3 -r 653fa009fea3 jingle-s5b/socks5.c --- a/jingle-s5b/socks5.c Sat Aug 21 14:44:03 2010 +0200 +++ b/jingle-s5b/socks5.c Mon Aug 23 17:44:28 2010 +0200 @@ -42,10 +42,10 @@ #include "socks5.h" -static gconstpointer check(JingleContent *cn, GError **err); +static gconstpointer newfrommessage(JingleContent *cn, GError **err); static void tomessage(gconstpointer data, LmMessageNode *node); // static void _send(session_content *sc, gconstpointer data, gchar *buf, gsize size); -static void init(session_content *sc, gconstpointer data); +static void init(session_content *sc); static void end(session_content *sc, gconstpointer data); static void handle_sock_io(GSocket *sock, GIOCondition cond, gpointer data); @@ -57,12 +57,12 @@ const gchar *deps[] = { "jingle", NULL }; static JingleTransportFuncs funcs = { - .check = check, - .tomessage = tomessage, - .new = NULL, - .send = NULL, - .init = init, - .end = end + .newfrommessage = newfrommessage, + .tomessage = tomessage, + .new = NULL, + .send = NULL, + .init = init, + .end = end }; module_info_t info_jingle_s5b = { @@ -119,7 +119,7 @@ } } -static gconstpointer check(JingleContent *cn, GError **err) +static gconstpointer newfrommessage(JingleContent *cn, GError **err) { JingleS5B *js5b; LmMessageNode *node = cn->transport, *node2; @@ -207,16 +207,16 @@ } } -static void init(session_content *sc, gconstpointer data) +static void init(session_content *sc) { - JingleS5B *js5 = (JingleS5B *)data; + JingleS5B *js5 = NULL; GInetAddress *addr; GSocketAddress *saddr; GSource *socksource; GError *err = NULL; g_assert(js5->sock == NULL); - addr = g_inet_address_new_from_string(((S5BCandidate *)js5->candidates->data)->host); + addr = g_inet_address_new_from_string("127.0.0.1"); js5->sock = g_socket_new(g_inet_address_get_family(addr), G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_TCP, &err); if (js5->sock == NULL) { @@ -296,7 +296,7 @@ g_object_unref(thisaddr); continue; }/* else if (g_inset_address_get_is_site_local(thisaddr)) { - // TODO: should we offer a way the offer of LAN ips ? + // TODO: should we offer a way to filter the offer of LAN ips ? } */ addresses = g_slist_prepend(addresses, thisaddr); } diff -r 35e603b584a3 -r 653fa009fea3 jingle/action-handlers.c --- a/jingle/action-handlers.c Sat Aug 21 14:44:03 2010 +0200 +++ b/jingle/action-handlers.c Mon Aug 23 17:44:28 2010 +0200 @@ -196,7 +196,7 @@ continue; if (sc->appfuncs->handle(JINGLE_SESSION_INFO, sc->description, - jn->node->children)) { + jn->node->children, NULL)) { jingle_ack_iq(jn->message); return; } @@ -234,7 +234,7 @@ } jingle_ack_iq(jn->message); - + sc2->sid = sess->sid; sc2->from = (sess->origin == JINGLE_SESSION_INCOMING) ? sess->from : sess->to; @@ -245,9 +245,10 @@ sc = session_find_sessioncontent(sess, jc->name); session_changestate_sessioncontent(sess, jc->name, JINGLE_SESSION_STATE_ACTIVE); - sc->transfuncs->init(sc2, sc->transfuncs->check(jc, NULL)); + sc->transfuncs->handle(JINGLE_SESSION_ACCEPT, sc->transport, jn->node, NULL); + sc->transfuncs->init(sc2); } - + // We delete content who haven't been accepted for (el = sess->content; el; el = el->next) { sc = (SessionContent*) el->data; @@ -256,7 +257,7 @@ session_remove_sessioncontent(sess, sc->name); } } - + // Go go go! We start jobs! for (el = sess->content; el; el = el->next) { sc = (SessionContent*)el->data; diff -r 35e603b584a3 -r 653fa009fea3 jingle/register.h --- a/jingle/register.h Sat Aug 21 14:44:03 2010 +0200 +++ b/jingle/register.h Mon Aug 23 17:44:28 2010 +0200 @@ -48,8 +48,17 @@ JINGLE_TRANSPORT_PRIO_HIGH } JingleTransportPriority; -typedef gconstpointer (*JingleAppCheck) (JingleContent *cn, GError **err); -typedef gboolean (*JingleAppHandle) (JingleAction action, gconstpointer data, LmMessageNode *node); +/** + * @brief Type returned by JingleAppFuncs and JingleTransportFuncs ->handle + */ +typedef enum { + JINGLE_STATUS_HANDLED, + JINGLE_STATUS_NOT_HANDLED, + JINGLE_STATUS_HANDLE_ERROR +} JingleHandleStatus; + +typedef gconstpointer (*JingleAppNewFromMsg) (JingleContent *cn, GError **err); +typedef JingleHandleStatus (*JingleAppHandle) (JingleAction action, gconstpointer data, LmMessageNode *node, GError **err); typedef void (*JingleAppToMessage) (gconstpointer data, LmMessageNode *node); typedef gboolean (*JingleAppHandleData) (gconstpointer data, const gchar *data2, guint len); typedef void (*JingleAppStart) (session_content *sc); @@ -57,11 +66,12 @@ typedef void (*JingleAppStop) (gconstpointer data); typedef gchar* (*JingleAppInfo) (gconstpointer data); -typedef gconstpointer (*JingleTransportCheck) (JingleContent *cn, GError **err); +typedef gconstpointer (*JingleTransportNewFromMsg) (JingleContent *cn, GError **err); +typedef JingleHandleStatus (*JingleTransportHandle) (JingleAction action, gconstpointer data, LmMessageNode *node, GError **err); typedef void (*JingleTransportToMessage) (gconstpointer data, LmMessageNode *node); typedef gconstpointer (*JingleTransportNew) (void); typedef void (*JingleTransportSend) (session_content *sc, gconstpointer data, gchar *buf, gsize size); -typedef void (*JingleTransportInit) (session_content *sc, gconstpointer data); +typedef void (*JingleTransportInit) (session_content *sc); typedef void (*JingleTransportEnd) (session_content *sc, gconstpointer data); typedef gchar* (*JingleTransportInfo) (gconstpointer data); @@ -70,9 +80,14 @@ */ typedef struct { /** - * @brief Check if the description node of a JingleContent is correct + * @brief Check a description node, store its content in an internal + * struct, then return it as a gconstpointer + * + * This function will only called when receiving a session-initiate. + * It should store the content of the node into an + * internal struct and return this struct as a gconstpointer. */ - JingleAppCheck check; + JingleAppNewFromMsg newfrommessage; /** * @brief Handle an incoming jingle message (session-info, description-info...) @@ -88,7 +103,13 @@ JingleAppToMessage tomessage; /** - * @brief Handle incoming data + * @brief Handle incoming Jingle IQs. + * + * e.g.: decription-info, content-info... etc + * The first argument is the IQ type (a JingleAction). If the function + * doesn't want to handle the IQ, it simply returns JINGLE_NOT_HANDLED, + * if it has handled the IQ, it returns JINGLE_HANDLED, if it has handled + * the IQ and an error happened, it returns JINGLE_HANDLE_ERROR. */ JingleAppHandleData handle_data; @@ -104,9 +125,15 @@ typedef struct { /** - * @brief Check if the transport node of a JingleContent is correct + * @brief Check a transport node, store its content in an internal + * struct, then return it as a gconstpointer + * + * It basically does the same thins as a JingleAppNewFroMsg function, + * but for a node. */ - JingleTransportCheck check; + JingleTransportNewFromMsg newfrommessage; + + JingleTransportHandle handle; /** * @brief Insert data from the gconstpointer to the node given as an argument diff -r 35e603b584a3 -r 653fa009fea3 jingle/send.c --- a/jingle/send.c Sat Aug 21 14:44:03 2010 +0200 +++ b/jingle/send.c Mon Aug 23 17:44:28 2010 +0200 @@ -97,8 +97,6 @@ LmMessage *mess; JingleAckHandle *ackhandle; - - mess = lm_message_from_jinglesession(js, JINGLE_SESSION_ACCEPT); if (mess) { diff -r 35e603b584a3 -r 653fa009fea3 jingle/sessions.c --- a/jingle/sessions.c Sat Aug 21 14:44:03 2010 +0200 +++ b/jingle/sessions.c Mon Aug 23 17:44:28 2010 +0200 @@ -138,7 +138,7 @@ { xmlns = lm_message_node_get_attribute(cn->description, "xmlns"); appfuncs = jingle_get_appfuncs(xmlns); - data = appfuncs->check(cn, &error); + data = appfuncs->newfrommessage(cn, &error); if (data == NULL || error != NULL) { g_propagate_error(err, error); sess->content = g_slist_remove(sess->content, sc); @@ -151,7 +151,7 @@ { xmlns = lm_message_node_get_attribute(cn->transport, "xmlns"); transfuncs = jingle_get_transportfuncs(xmlns); - data = transfuncs->check(cn, &error); + data = transfuncs->newfrommessage(cn, &error); if (data == NULL || error != NULL) { g_propagate_error(err, error); g_free(sc->xmlns_desc);