Author: ArcRiley Date: 2009-01-14 01:00:02 -0500 (Wed, 14 Jan 2009) New Revision: 1480
Modified: trunk/concordance/src/Session.c trunk/concordance/src/utils.c trunk/concordance/src/utils.h Log: fixed version string function, moved it's location into stream reply Modified: trunk/concordance/src/Session.c =================================================================== --- trunk/concordance/src/Session.c 2009-01-14 04:40:19 UTC (rev 1479) +++ trunk/concordance/src/Session.c 2009-01-14 06:00:02 UTC (rev 1480) @@ -30,6 +30,9 @@ static void concordSession_xmlEnd (gpointer, const XML_Char*); static void concordSession_xmlCharData (gpointer, const XML_Char*, gint); +static void concordSession_reply_streamError + (concordSession_Data*, + gchar*, gchar*); /*\ @@ -74,7 +77,7 @@ static void concordSession_dealloc(concordSession_Object* self) { /*\ cdef : \*/ - + if (self->data) { /* lock data mutex, clear ourselves from it, then unlock @@ -180,7 +183,7 @@ int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags); - + ret = getnameinfo(&addr, addrlen, session->host, 255, NULL, 0, 0); NOTE : this needs to be moved to a GMainLoop function so DNS lookups @@ -241,7 +244,7 @@ gpointer data, GMainContext* context) */ - concordAddWatch(session->chan, G_IO_OUT, + concordAddWatch(session->chan, G_IO_OUT, (GSourceFunc) concordSession_gioWrite, (gpointer) session, session->core->context); } @@ -359,10 +362,12 @@ # Element responses # */ static void - concordSession_reply_stream(concordSession_Data* session) { /*\ + concordSession_reply_stream(concordSession_Data* session, + gchar* version) { /*\ cdef : \*/ concordCore_Object* core = session->core; GString* buff; + gchar* error = NULL; /* initialize response buffer @@ -380,10 +385,26 @@ "<?xml version='1.0' encoding='UTF-8'?>" "<stream:stream xmlns='jabber:client'" " xmlns:stream='http://etherx.jabber.org/streams'" - " from='%s' id='%s'><stream:features><mechanisms" - " xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>", - "selket.apogean.org", "concordance-1"); + " from='%s' id='%s'%s>", + "selket.apogean.org", "concordance-1", + conSession_getVersion(version, &error)); + if (error) { + /* a stream error has taken place! + + send the <stream:stream> element we have so far, free the buffer, + then pass control over concordSession_reply_streamError for the rest. + */ + concordSession_send(session, buff->str, buff->len); + g_string_free(buff, TRUE); + concordSession_reply_streamError(session, error, ""); + return; + } + + /* open stream:features and mechanisms element */ + buff = g_string_append(buff, "<stream:features><mechanisms" + " xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>"); + /* add a <mechanism> element for each supported SASL mechanism int gsasl_server_support_p (Gsasl* ctx, @@ -410,7 +431,7 @@ static void - concordSession_reply_streamError(concordSession_Data* session, + concordSession_reply_streamError(concordSession_Data* session, gchar* err, gchar* txt) { /*\ cdef : \*/ GString* buff; @@ -534,13 +555,9 @@ in the concordCore_sessionRead just after the XMLParse call (above). */ if (g_ascii_strcasecmp(name, - "http://etherx.jabber.org/streams stream") == 0){ - int major, minor = 0; - /* need to test version and other important attributes - */ - conSession_getVersion(concordSearchAttributes(atts,"version"),&major,&minor); - printf("Major %d Minor %d\n",major,minor); - concordSession_reply_stream(session);} + "http://etherx.jabber.org/streams stream") == 0) + concordSession_reply_stream(session, + concordSearchAttributes(atts, "version")); else session->state = CONCORD_E_CLOSE; break; @@ -563,13 +580,13 @@ GString* g_string_assign (GString *string, const gchar *rval); */ - if (!(attr = concordSearchAttributes(atts, "to"))) + if (!(attr = concordSearchAttributes(atts, "to"))) attr = ""; session->eto = g_string_assign(session->eto, attr); - if (!(attr = concordSearchAttributes(atts, "from"))) + if (!(attr = concordSearchAttributes(atts, "from"))) attr = ""; session->efrom = g_string_assign(session->efrom, attr); - printf("--------- from: %s to: %s\n", + printf("--------- from: %s to: %s\n", session->efrom->str, session->eto->str); /* copy element and attributes to ebuff Modified: trunk/concordance/src/utils.c =================================================================== --- trunk/concordance/src/utils.c 2009-01-14 04:40:19 UTC (rev 1479) +++ trunk/concordance/src/utils.c 2009-01-14 06:00:02 UTC (rev 1480) @@ -142,7 +142,7 @@ /* return error now in case of empty string */ if (*string == 0) return FALSE; - + /* continue until hit end of string */ while (string[i] != 0) { /* shift existing value up by 10, ie total input "92": @@ -175,32 +175,51 @@ } -gchar* -conSession_getVersion(gchar* version, gint* major, gint* minor) { /*\ +gchar* +conSession_getVersion(gchar* version, gchar** error) { /*\ cdef : \*/ + guint major, minor; gchar** versions; - - if (g_strrstr(version, ".")!=NULL) { + + /* There are four possible outcomes to this function: + * NULL is passed, meaning the version attribute was not found, so: + * return is "" + * error is "<unsupported-version/>" + + * "1.*" is passed, meaning a version we support, so: + * return is " version='1.0'" + * error is NULL + + * "2.0" or greater is passed, meaning a version we do not support, so: + * return is " version='1.0'" + * error is "<unsupported-version/>" + + * something unparsable is passed, so: + * return is " version='1.0'" + * error is "<bad-format/>" + */ + + if (version == NULL) { + *error = "<unsupported-version/>"; + return ""; + } + + if (g_strrstr(version, ".") != NULL) { versions = g_strsplit(version, ".", 2); // Separate Major from minor - if (g_strv_length(versions) >= 2) { - printf("versions[0], %s, versions[1], %s\n", versions[0], versions[1]); - if (!concordStrToUI(versions[0], major)) { - printf("Error on major\n"); - return "version ='0.0'"; + if (g_strv_length(versions) == 2 && + concordStrToUI(versions[0], &major) && + concordStrToUI(versions[1], &minor)) { + g_strfreev(versions); + if (major == 1) + return " version='1.0'"; + else { + *error = "<unsupported-version/>"; + return " version='1.0'"; } - if (!concordStrToUI(versions[1], minor)) { - printf("Error on minor\n"); - return "version ='0.0'"; - } - if ((*major) < 1) // Unsupported version - return "version='0.0'"; - else if (((*major) == 1) && ((*minor) == 0)) // Only 1.0 is supported - return "version='1.0'"; } + g_strfreev(versions); } // else (because it should have returned above) - (*major) = 0; - (*minor) = 0; - g_strfreev(versions); - return "version = '0.0'"; + *error = "<bad-format/>"; + return " version='1.0'"; } Modified: trunk/concordance/src/utils.h =================================================================== --- trunk/concordance/src/utils.h 2009-01-14 04:40:19 UTC (rev 1479) +++ trunk/concordance/src/utils.h 2009-01-14 06:00:02 UTC (rev 1480) @@ -54,5 +54,6 @@ gchar* concordSearchAttributes (const gchar**, const gchar*); gchar* concordPyUnicodeToUTF8 (PyObject* unicode); gboolean concordStrToUI (const gchar* string, guint* result); +gchar* conSession_getVersion (gchar*, gchar**); #endif _______________________________________________ PySoy-SVN mailing list PySoy-SVN@pysoy.org http://www.pysoy.org/mailman/listinfo/pysoy-svn