From: <svn...@op...> - 2009-07-09 11:57:53
|
Author: bellmich Date: Thu Jul 9 13:57:42 2009 New Revision: 1165 URL: http://libsyncml.opensync.org/changeset/1165 Log: migrated transports/http_server from SmlError to GError Modified: trunk/libsyncml/transports/http_server.c Modified: trunk/libsyncml/transports/http_server.c ============================================================================== --- trunk/libsyncml/transports/http_server.c Thu Jul 9 13:57:21 2009 (r1164) +++ trunk/libsyncml/transports/http_server.c Thu Jul 9 13:57:42 2009 (r1165) @@ -40,7 +40,7 @@ SmlTransportHttpServerEnv *env = data; SmlLinkHttpServerEnv *linkenv = NULL; SmlLink *link_ = NULL; - SmlError *error = NULL; + GError *error = NULL; char *path = soup_uri_to_string (soup_message_get_uri(msg), TRUE); smlTrace(TRACE_INTERNAL, "%s: %s %s HTTP/1.%d", @@ -59,7 +59,7 @@ * SECURITY: This is a potential attack. * FALSE POSITIVE: Session with a timeout. */ - smlErrorSet(&error, SML_ERROR_INTERNAL_FILE_NOT_FOUND, + g_set_error(&error, SML_ERROR, SML_ERROR_INTERNAL_FILE_NOT_FOUND, "Not Found (%s).", path); soup_message_set_status(msg, SOUP_STATUS_NOT_FOUND); smlSafeCFree(&path); @@ -70,13 +70,13 @@ smlSafeCFree(&path); if (soup_message_get_http_version(msg) != 1) { - smlErrorSet(&error, SML_ERROR_NOT_IMPLEMENTED, "Wrong http version"); + g_set_error(&error, SML_ERROR, SML_ERROR_NOT_IMPLEMENTED, "Wrong http version"); soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED); goto error; } if (soup_method_get_id(msg->method) != SOUP_METHOD_ID_POST) { - smlErrorSet(&error, SML_ERROR_NOT_IMPLEMENTED, "Wrong method"); + g_set_error(&error, SML_ERROR, SML_ERROR_NOT_IMPLEMENTED, "Wrong method"); soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED); goto error; } @@ -89,11 +89,11 @@ else if(header && !g_strncasecmp(header, SML_ELEMENT_SAN, strlen(SML_ELEMENT_SAN))) mimetype = SML_MIMETYPE_SAN; else if (header) { - smlErrorSet(&error, SML_ERROR_GENERIC, "Unknown mimetype"); + g_set_error(&error, SML_ERROR, SML_ERROR_GENERIC, "Unknown mimetype"); soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST); goto error; } else { - smlErrorSet(&error, SML_ERROR_GENERIC, "Faulty mimetype"); + g_set_error(&error, SML_ERROR, SML_ERROR_GENERIC, "Faulty mimetype"); soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST); goto error; } @@ -169,8 +169,8 @@ error: soup_server_message_set_encoding (SOUP_SERVER_MESSAGE (msg), SOUP_TRANSFER_CONTENT_LENGTH); soup_message_io_unpause(msg); - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(&error)); - smlErrorDeref(&error); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, error->message); + g_error_free(error); } #else /* !HAVE_LIBSOUP22 == libsoup 2.4 */ @@ -189,13 +189,13 @@ SmlTransportHttpServerEnv *env = data; SmlLinkHttpServerEnv *linkenv = NULL; SmlLink *link_ = NULL; - SmlError *error = NULL; + GError *error = NULL; smlTrace(TRACE_INTERNAL, "%s: %s %s HTTP/1.%d", __func__, VA_STRING(msg->method), VA_STRING(path), soup_message_get_http_version(msg)); if (msg->method != SOUP_METHOD_POST) { - smlErrorSet(&error, SML_ERROR_NOT_IMPLEMENTED, "Wrong method"); + g_set_error(&error, SML_ERROR, SML_ERROR_NOT_IMPLEMENTED, "Wrong method"); soup_message_set_status(msg, SOUP_STATUS_NOT_IMPLEMENTED); goto error; } @@ -212,7 +212,7 @@ * SECURITY: This is a potential attack. * FALSE POSITIVE: Session with a timeout. */ - smlErrorSet(&error, SML_ERROR_INTERNAL_FILE_NOT_FOUND, + g_set_error(&error, SML_ERROR, SML_ERROR_INTERNAL_FILE_NOT_FOUND, "Not Found (%s).", fullpath); soup_message_set_status(msg, SOUP_STATUS_NOT_FOUND); smlSafeCFree(&fullpath); @@ -230,11 +230,11 @@ else if(header && !g_strncasecmp(header, SML_ELEMENT_SAN, strlen(SML_ELEMENT_SAN))) mimetype = SML_MIMETYPE_SAN; else if (header) { - smlErrorSet(&error, SML_ERROR_GENERIC, "Unknown mimetype"); + g_set_error(&error, SML_ERROR, SML_ERROR_GENERIC, "Unknown mimetype"); soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST); goto error; } else { - smlErrorSet(&error, SML_ERROR_GENERIC, "Faulty mimetype"); + g_set_error(&error, SML_ERROR, SML_ERROR_GENERIC, "Faulty mimetype"); soup_message_set_status (msg, SOUP_STATUS_BAD_REQUEST); goto error; } @@ -311,17 +311,17 @@ error_unref_msg: smlLinkDeref(link_); error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(&error)); - smlErrorDeref(&error); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, error->message); + g_error_free(error); } #endif /* HAVE_LIBSOUP22 */ -static SmlBool smlTransportHttpServerSetConfigOption( - SmlTransport *tsp, - const char *name, - const char *value, - SmlError **error) +static gboolean +smlTransportHttpServerSetConfigOption (SmlTransport *tsp, + const gchar *name, + const gchar *value, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %s, %s, %p)", __func__, tsp, VA_STRING(name), VA_STRING(value), error); CHECK_ERROR_REF @@ -332,8 +332,8 @@ if (!strcmp(name, SML_TRANSPORT_CONFIG_PORT)) { env->port = atoi(value); if (!(env->port > 0 && env->port < 65535)) { - smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, "specified port was wrong"); - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_MISCONFIGURATION, "specified port was wrong"); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return FALSE; } smlTrace(TRACE_INTERNAL, "%s: Port %i detected", __func__, env->port); @@ -347,8 +347,8 @@ env->ssl_cert = g_strdup(value); smlTrace(TRACE_INTERNAL, "%s: SSL server certificate %s detected", __func__, VA_STRING(env->ssl_cert)); } else { - smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, "Unknown parameter %s found.", name); - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_MISCONFIGURATION, "Unknown parameter %s found.", name); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return FALSE; } @@ -356,7 +356,9 @@ return TRUE; } -static SmlBool smlTransportHttpServerInit(SmlTransport *tsp, SmlError **error) +static gboolean +smlTransportHttpServerInit (SmlTransport *tsp, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, tsp, error); CHECK_ERROR_REF @@ -367,9 +369,9 @@ if (!env->port) { - smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_MISCONFIGURATION, "The HTTP server needs a port where it has to run."); - goto error_free_env; + goto error; } if (!env->url) @@ -395,8 +397,8 @@ NULL); } if (!env->server) { - smlErrorSet(error, SML_ERROR_INTERNAL_MISCONFIGURATION, "Unable to spawn server"); - goto error_free_env; + g_set_error(error, SML_ERROR, SML_ERROR_INTERNAL_MISCONFIGURATION, "Unable to spawn server"); + goto error; } #ifdef HAVE_LIBSOUP22 @@ -409,14 +411,11 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; - -error_free_env: +error: if (env->url) smlSafeCFree(&(env->url)); - smlSafeFree((gpointer *)&env); -// error: - smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s: %s", __func__, (*error)->message); return FALSE; } @@ -526,9 +525,9 @@ return TRUE; } -static SmlBool smlTransportHttpServerCleanupSocket( - gpointer data, - SmlError **error) +static gboolean +smlTransportHttpServerCleanupSocket (gpointer data, + GError **error) { smlTrace(TRACE_ENTRY, "%s", __func__); CHECK_ERROR_REF @@ -543,7 +542,9 @@ return TRUE; } -static SmlBool smlTransportHttpServerFinalize(void *data, SmlError **error) +static gboolean +smlTransportHttpServerFinalize (void *data, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, data, error); CHECK_ERROR_REF @@ -581,7 +582,7 @@ env); if (count != removed) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The glib function g_hash_table_foreach_steal could " \ "not remove all key/value pairs from uriToLink (%u of %u).", removed, count); @@ -600,7 +601,7 @@ env); if (count != removed) { - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The glib function g_hash_table_foreach_steal could not " \ "remove all key/value pairs from sessionToUri. (%u of %u)", removed, count); @@ -615,11 +616,15 @@ smlTrace(TRACE_EXIT, "%s", __func__); return TRUE; error: - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return FALSE; } -static void smlTransportHttpServerSend(void *userdata, void *linkdata, SmlTransportData *data, SmlError *error) +static void +smlTransportHttpServerSend (void *userdata, + void *linkdata, + SmlTransportData *data, + GError *error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p, %p)", __func__, userdata, linkdata, data, error); // smlAssert(userdata); @@ -652,7 +657,7 @@ content_type = SML_ELEMENT_SAN; break; default: - smlErrorSet(&error, SML_ERROR_GENERIC, "Unknown Mimetype"); + g_set_error(&error, SML_ERROR, SML_ERROR_GENERIC, "Unknown Mimetype"); goto error_free_message; } @@ -676,9 +681,9 @@ error_free_message: if (smlErrorGetClass(&error) <= SML_ERRORCLASS_RETRY) - soup_message_set_status_full(msg, SOUP_STATUS_BAD_REQUEST, smlErrorPrint(&error)); + soup_message_set_status_full(msg, SOUP_STATUS_BAD_REQUEST, error->message); else - soup_message_set_status_full(msg, SOUP_STATUS_INTERNAL_SERVER_ERROR, smlErrorPrint(&error)); + soup_message_set_status_full(msg, SOUP_STATUS_INTERNAL_SERVER_ERROR, error->message); #ifdef HAVE_LIBSOUP22 soup_server_message_set_encoding (SOUP_SERVER_MESSAGE (msg), SOUP_TRANSFER_CONTENT_LENGTH); @@ -687,12 +692,15 @@ soup_server_unpause_message(linkenv->env->server, msg); #endif - smlErrorDeref(&error); + g_error_free(error); smlTrace(TRACE_EXIT, "%s: Sent Error", __func__); return; } -char * smlTransportHttpServerGetResponseURI(SmlLink *link_, SmlSession *session, SmlError **error) +gchar* +smlTransportHttpServerGetResponseURI (SmlLink *link_, + SmlSession *session, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, link_, session, error); /* Do not change the assertion to simple return FALSE stuff @@ -729,7 +737,7 @@ if (strcmp(env->url, soupURI)) { /* SECURITY: This can be an attack. */ - smlErrorSet(error, SML_ERROR_RETRY_LATER, + g_set_error(error, SML_ERROR, SML_ERROR_RETRY_LATER, "A new session with a configured HTTP session was detected."); smlSafeCFree(&soupURI); goto error; @@ -761,7 +769,7 @@ if (g_hash_table_lookup(env->uriToLink, responseURI)) { /* SECURITY: This can be an insecure random number generator. */ - smlErrorSet(error, SML_ERROR_RETRY_LATER, + g_set_error(error, SML_ERROR, SML_ERROR_RETRY_LATER, "A fresh random session ID is already in use."); goto error; } @@ -790,7 +798,7 @@ if (strcmp(soupURI, sessionURI)) { /* SECURITY: This is a potential attack. */ - smlErrorSet(error, SML_ERROR_RETRY_LATER, + g_set_error(error, SML_ERROR, SML_ERROR_RETRY_LATER, "Another session (%s) re-used an already existing HTTP session (%s).", soupURI, sessionURI); smlSafeCFree(&soupURI); @@ -801,7 +809,7 @@ if (!cachedLink) { /* SECURITY: This is an internal bug. */ - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "Cannot find link for used URL."); smlSafeCFree(&soupURI); goto error; @@ -809,7 +817,7 @@ if (cachedLink != link_) { /* SECURITY: This is an internal bug. */ - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The link objects mismatch."); smlSafeCFree(&soupURI); goto error; @@ -817,7 +825,7 @@ if (strcmp(linkenv->url, soupURI)) { /* SECURITY: This can be an attack. */ - smlErrorSet(error, SML_ERROR_GENERIC, + g_set_error(error, SML_ERROR, SML_ERROR_GENERIC, "The URL of the link object is wrong."); smlSafeCFree(&soupURI); goto error; @@ -828,11 +836,13 @@ smlTrace(TRACE_EXIT, "%s - %s", __func__, VA_STRING(responseURI)); return responseURI; error: - smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, smlErrorPrint(error)); + smlTrace(TRACE_EXIT_ERROR, "%s - %s", __func__, (*error)->message); return NULL; } -SmlBool smlTransportHttpServerNew(SmlTransport *tsp, SmlError **error) +gboolean +smlTransportHttpServerNew (SmlTransport *tsp, + GError **error) { smlTrace(TRACE_ENTRY, "%s(%p, %p)", __func__, tsp, error); CHECK_ERROR_REF |