created. moved cgi-related request processing here. do not use it.
authorAlex Graveley <alex@ximian.com>
Wed, 7 Mar 2001 15:08:38 +0000 (15:08 +0000)
committeralex <alex>
Wed, 7 Mar 2001 15:08:38 +0000 (15:08 +0000)
2001-03-07  Alex Graveley  <alex@ximian.com>

* src/soup-core/soup-cgi.c: created. moved cgi-related request
processing here. do not use it. completely broken.

* src/soup-core/soup-apache.c: initial commit of Apache module
handling, server registration should be performed in a
soup_server_init function. Authorization handling still needs to
be written.

* src/soup-core/soup-server.c: cleaned up to have only generic
server functions. removed extraneous unregister functions.
(soup_server_set_global_auth): set the global server authorize
function, to be called in the absence of a method-specific
authorize function.
(soup_server_set_method_auth): set per-method authorize function.

* src/soup-core/soup-queue.c (soup_parse_headers): remove unneeded
variables.

* src/soup-core/soup-private.h: add SoupServerHandler,
soup_server_get_handler(), and soup_server_authorize().

* src/soup-wsdl/Makefile.am (INCLUDES): add WSDL_CFLAGS, to get
-Werror.

* src/soup-core/Makefile.am: add new libsoup-apache.so target.

* soup.spec.in: update and remove hardcoded library version.

* soup-config.in: add module soup-apache.

* configure.in: Fix library versioning. Switch version to
0.2.1. Add APACHE_CFLAGS and APACHE_LIBS, gotten from running
`apxs`. Remove -Werror from CFLAGS, as apache_conf.h is missing a
prototype. Add WSDL_CFLAGS="-Werror" back.

* TODO (TODO): Updated.

ChangeLog
TODO
configure.in
libsoup/Makefile.am
libsoup/soup-private.h
libsoup/soup-queue.c
libsoup/soup-server.c
libsoup/soup-server.h
libsoup/soup-socks.c
libsoup/soup-uri.c
soup-2.0.pc.in

index c6ce2c8..ab79862 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,46 @@
+2001-03-07  Alex Graveley  <alex@ximian.com>
+
+       * src/soup-core/soup-cgi.c: created. moved cgi-related request
+       processing here. do not use it. completely broken.
+
+       * src/soup-core/soup-apache.c: initial commit of Apache module
+       handling, server registration should be performed in a
+       soup_server_init function. Authorization handling still needs to
+       be written.
+
+       * src/soup-core/soup-server.c: cleaned up to have only generic
+       server functions. removed extraneous unregister functions.
+       (soup_server_set_global_auth): set the global server authorize
+       function, to be called in the absence of a method-specific
+       authorize function.
+       (soup_server_set_method_auth): set per-method authorize function.
+
+       * src/soup-core/soup-queue.c (soup_parse_headers): remove unneeded
+       variables.
+
+       * src/soup-core/soup-private.h: add SoupServerHandler,
+       soup_server_get_handler(), and soup_server_authorize().
+
+       * src/soup-wsdl/Makefile.am (INCLUDES): add WSDL_CFLAGS, to get
+       -Werror.
+
+       * src/soup-core/Makefile.am: add new libsoup-apache.so target.
+
+       * soup.spec.in: update and remove hardcoded library version.
+
+       * soup-config.in: add module soup-apache.
+
+       * configure.in: Fix library versioning. Switch version to
+       0.2.1. Add APACHE_CFLAGS and APACHE_LIBS, gotten from running
+       `apxs`. Remove -Werror from CFLAGS, as apache_conf.h is missing a
+       prototype. Add WSDL_CFLAGS="-Werror" back.
+
+       * TODO (TODO): Updated.
+
 2001-03-06  JP Rosevear  <jpr@ximian.com>
 
-       * configure.in: properly version the project and give an option to disable more warnings
+       * configure.in: properly version the project and give an option to
+       disable more warnings
 
 2001-03-02  Alex Graveley  <alex@ximian.com>
 
diff --git a/TODO b/TODO
index a86ff1d..9e655df 100644 (file)
--- a/TODO
+++ b/TODO
@@ -38,11 +38,11 @@ X * SoupSerializer
 
 Release stuff:
 
-* Write apache plugin stuff (soup-server)
+* Write apache plugin stuff (soup-server)
 
 * Write response code handling stuff, add response userland error
 
-* clean up configure.in
+* clean up configure.in
 
 X * fix soup-serializer header file crap.
 
@@ -50,8 +50,8 @@ X * fix soup-serializer SOAP-ENV prefixing, test prefixing.
 
 X * make callback return void? YES. soup_queue_message now takes ownership
 
-* fix ssl pending bug
+* fix ssl pending bug
 
-* fix ssl unsecure error crap
+* fix ssl unsecure error crap
 
-* update tests/*
\ No newline at end of file
+* update tests/*
\ No newline at end of file
index 4c94613..e11d32d 100644 (file)
@@ -3,8 +3,8 @@
 
 AC_INIT(src/soup-core/soup.h)
 
-SOUP_CURRENT=0
-SOUP_REVISION=2
+SOUP_CURRENT=2
+SOUP_REVISION=0
 SOUP_AGE=0
 
 AC_SUBST(SOUP_CURRENT)
@@ -12,7 +12,7 @@ AC_SUBST(SOUP_REVISION)
 AC_SUBST(SOUP_AGE)
 
 AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE(soup, $SOUP_CURRENT.$SOUP_REVISION.$SOUP_AGE)
+AM_INIT_AUTOMAKE(soup, 0.2.1)
 AM_MAINTAINER_MODE
 
 
@@ -32,15 +32,12 @@ AC_ARG_ENABLE(debug,
              enable_debug=$debug_default)
 
 # Set the debug flags
-AC_MSG_CHECKING(for --enable-debug)
 if test "x$enable_debug" = "xyes"; then
        test "$cflags_set" = set || CFLAGS="$CFLAGS -g"
        SOUP_DEBUG_FLAGS="-DG_ENABLE_DEBUG"
-       AC_MSG_RESULT(yes)
 else
        if test "x$enable_debug" = "xno"; then
                SOUP_DEBUG_FLAGS="-DG_DISABLE_ASSERT -DG_DISABLE_CHECKS"
-               AC_MSG_RESULT(no)
        fi
 fi
 
@@ -183,16 +180,38 @@ if test "x$enable_ssl" = xyes; then
 fi
 
 
+AC_PATH_PROG(APXS,apxs,no)
+if test x$APXS != xno; then
+       APACHE_CFLAGS="-I`apxs -q INCLUDEDIR`"
+       APACHE_LIBS=`apxs -q LDFLAGS_SHLIB LIBS_SHLIB`
+
+       save_CPPFLAGS=$CPPFLAGS
+       CPPFLAGS=$APACHE_CFLAGS
+       AC_CHECK_HEADERS(httpd.h http_config.h http_core.h http_log.h http_main.h http_protocol.h,
+                         [enable_apache="yes"],
+                         [enable_apache="no"
+                          break])
+       CPPFLAGS=$save_CPPFLAGS
+
+       AC_SUBST(APACHE_CFLAGS)
+       AC_SUBST(APACHE_LIBS)
+fi
+
+
 AC_ARG_ENABLE(more-warnings,
-[  --enable-more-warnings  Maximum compiler warnings],
-set_more_warnings="$enableval",set_more_warnings=yes)
+             [  --enable-more-warnings  Maximum compiler warnings],
+             set_more_warnings="$enableval",
+             set_more_warnings=yes)
 
 if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
        CFLAGS="$CFLAGS \
        -Wall -Wstrict-prototypes -Wmissing-declarations -Wmissing-prototypes \
-       -Wnested-externs -Wpointer-arith -Werror"
+       -Wnested-externs -Wpointer-arith"
+       WSDL_CFLAGS="-Werror"
 fi
 
+AC_SUBST(WSDL_CFLAGS)
+
 # Use reentrant functions
 CFLAGS="$CFLAGS -D_REENTRANT"
 
@@ -216,11 +235,13 @@ echo "
 
 Configuration:
 
-  Source code location:  ${srcdir}
-  Compiler:              ${CC}
-  Build flags:           ${CFLAGS} ${SOUP_DEBUG_FLAGS}
+  Source code location:                ${srcdir}
+  Compiler:                    ${CC}
+  Build flags:                 ${CFLAGS} ${SOUP_DEBUG_FLAGS}
+
+  OpenSSL support:             ${enable_openssl}
+  Mozilla NSS support:         ${enable_nss}
 
-  OpenSSL support:       ${enable_openssl}
-  Mozilla NSS support:  ${enable_nss}
+  Apache module support:       ${enable_apache}
 
 "
\ No newline at end of file
index 0aa0e59..1a8ae73 100644 (file)
@@ -6,15 +6,26 @@ INCLUDES =                            \
        -DG_LOG_DOMAIN=\"SOUP\"         \
        -DSYSCONFDIR=\"$(sysconfdir)\"  \
        -DBINDIR=\"$(bindir)\"          \
-       @SOUP_DEBUG_FLAGS@              \
-       @GNET_CFLAGS@                   \
-       @XML_CFLAGS@                    \
-       @OPENSSL_CFLAGS@                \
-       @NSS_CFLAGS@
+       $(SOUP_DEBUG_FLAGS)             \
+       $(GNET_CFLAGS)                  \
+       $(XML_CFLAGS)                   \
+       $(OPENSSL_CFLAGS)               \
+       $(NSS_CFLAGS)                   \
+       $(APACHE_CFLAGS)
 
 soupincludedir = $(includedir)/soup
 
-lib_LTLIBRARIES = libsoup.la
+soupinclude_HEADERS =          \
+       soup.h                  \
+       soup-context.h          \
+       soup-message.h          \
+       soup-misc.h             \
+       soup-queue.h            \
+       soup-serializer.h       \
+       soup-server.h           \
+       soup-uri.h
+
+lib_LTLIBRARIES = libsoup.la libsoup-apache.la
 
 libsoup_la_LDFLAGS = -version-info $(SOUP_CURRENT):$(SOUP_REVISION):$(SOUP_AGE)
 
@@ -23,6 +34,7 @@ libsoup_la_LIBADD =           \
        $(XML_LIBS)
 
 libsoup_la_SOURCES =           \
+       soup-cgi.c              \
        soup-context.c          \
        soup-headers.h          \
        soup-headers.c          \
@@ -38,15 +50,15 @@ libsoup_la_SOURCES =                \
        soup-ssl.c              \
        soup-uri.c
 
-soupinclude_HEADERS =          \
-       soup.h                  \
-       soup-context.h          \
-       soup-message.h          \
-       soup-misc.h             \
-       soup-queue.h            \
-       soup-serializer.h       \
-       soup-server.h           \
-       soup-uri.h
+libsoup_apache_la_LDFLAGS =    \
+       -version-info $(SOUP_CURRENT):$(SOUP_REVISION):$(SOUP_AGE)
+
+libsoup_apache_la_LIBADD =     \
+       $(APACHE_LIBS)          \
+       -L.libs -lsoup
+
+libsoup_apache_la_SOURCES =    \
+       soup-apache.c
 
 bin_PROGRAMS = soup-ssl-proxy
 
index 2789f54..4e571ac 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "soup-context.h"
 #include "soup-queue.h"
+#include "soup-server.h"
 #include "soup-uri.h"
 
 #ifdef __cplusplus
@@ -80,6 +81,14 @@ struct _SoupMessagePrivate {
        gpointer        user_data;
 };
 
+typedef struct {
+       gchar                *methodname;
+       SoupServerCallbackFn  cb;
+       gpointer              user_data;
+       SoupServerAuthorizeFn auth_fn;
+       gpointer              auth_user_data;
+} SoupServerHandler;
+
 /* from soup-message.c */
 
 void      soup_message_issue_callback (SoupMessage   *req, 
@@ -101,6 +110,15 @@ gint      soup_substring_index        (gchar         *str,
 gchar    *soup_base64_encode          (const gchar   *text,
                                       gint           len);
 
+/* from soup-server.c */
+
+SoupServerHandler *soup_server_get_handler (const gchar *methodname);
+
+gboolean           soup_server_authorize   (SoupMessage *msg,
+                                           gchar       *username, 
+                                           gchar       *password,
+                                           gchar       *realm);
+
 #ifdef __cplusplus
 }
 #endif
index 835ce69..22ef08b 100644 (file)
@@ -30,17 +30,14 @@ static guint soup_queue_idle_tag = 0;
 static gboolean
 soup_parse_headers (SoupMessage *req)
 {
-       guint len = req->priv->recv_buf->len;
-       gchar *str = req->priv->recv_buf->data;
-
        if (req->response_headers) 
                g_hash_table_destroy (req->response_headers);
 
        req->response_headers = g_hash_table_new (soup_str_case_hash, 
                                                  soup_str_case_equal);
 
-       if (!soup_headers_parse_response (str
-                                         len, 
+       if (!soup_headers_parse_response (req->priv->recv_buf->data
+                                         req->priv->recv_buf->len, 
                                          req->response_headers,
                                          &req->response_code,
                                          &req->response_phrase))
index deed5c7..50b8173 100644 (file)
 #include "soup-headers.h"
 #include "soup-private.h"
 
-static GSList    *server_handlers;
-static GMainLoop *server_main;
-static guint      server_read_source_tag;
+static GSList                *soup_server_handlers = NULL;
 
-typedef struct {
-       gchar                *methodname;
-       SoupServerCallbackFn  cb;
-       gpointer              user_data;
-} SoupServerHandler;
+static SoupServerAuthorizeFn  soup_server_global_auth = NULL;
+static gpointer               soup_server_global_auth_user_data = NULL;
+
+SoupServerHandler *
+soup_server_get_handler (const gchar *methodname)
+{
+       GSList *iter = soup_server_handlers;
+
+       g_return_val_if_fail (methodname != NULL, NULL);
+
+       for (iter = soup_server_handlers; iter; iter = iter->next) {
+               SoupServerHandler *hand = iter->data;
+               if (!strcmp (hand->methodname, methodname))
+                       return hand;
+       }
+       return NULL;
+}
 
 void  
 soup_server_register (const gchar          *methodname, 
                      SoupServerCallbackFn  cb,
                      gpointer              user_data)
 {
-       SoupServerHandler *hand = g_new0 (SoupServerHandler, 1);
+       SoupServerHandler *hand;
+
+       g_return_if_fail (methodname != NULL);
+
+       hand = g_new0 (SoupServerHandler, 1);
        hand->methodname = g_strdup (methodname);
        hand->cb = cb;
        hand->user_data = user_data;
 
-       server_handlers = g_slist_prepend (server_handlers, hand);
+       soup_server_handlers = g_slist_prepend (soup_server_handlers, hand);
 }
 
-static void
-soup_server_free_handler (SoupServerHandler *hand)
+void  
+soup_server_unregister (const gchar *methodname)
 {
-       server_handlers = g_slist_remove (server_handlers, hand);
+       SoupServerHandler *hand;
+
+       g_return_if_fail (methodname != NULL);
+
+       hand = soup_server_get_handler (methodname);
+       soup_server_handlers = g_slist_remove (soup_server_handlers, hand);
        g_free (hand->methodname);
        g_free (hand);
 }
 
 void  
-soup_server_unregister_by_name (const gchar *methodname)
+soup_server_set_global_auth (SoupServerAuthorizeFn  cb,
+                            gpointer              *user_data)
 {
-       GSList *iter = server_handlers;
-       for (iter = server_handlers; iter; iter = iter->next) {
-               SoupServerHandler *hand = iter->data;
-               if (!strcmp (hand->methodname, methodname))
-                       soup_server_free_handler (hand);
-       }
+       soup_server_global_auth = cb;
+       soup_server_global_auth_user_data = user_data;
 }
 
 void  
-soup_server_unregister_by_cb (SoupServerCallbackFn cb)
+soup_server_set_method_auth (gchar                 *methodname,
+                            SoupServerAuthorizeFn  cb,
+                            gpointer              *user_data)
 {
-       GSList *iter = server_handlers;
-       for (iter = server_handlers; iter; iter = iter->next) {
-               SoupServerHandler *hand = iter->data;
-               if (hand->cb == cb) soup_server_free_handler (hand);
-       }
-}
+       SoupServerHandler *hand = soup_server_get_handler (methodname);
+       if (!hand) return;
 
-void  
-soup_server_unregister_by_data (gpointer user_data)
-{
-       GSList *iter = server_handlers;
-       for (iter = server_handlers; iter; iter = iter->next) {
-               SoupServerHandler *hand = iter->data;
-               if (hand->user_data == user_data) 
-                       soup_server_free_handler (hand);
-       }
+       hand->auth_fn = cb;
+       hand->auth_user_data = user_data;
 }
 
-static gboolean 
-soup_server_read_cb (GIOChannel   *iochannel, 
-                    GIOCondition  condition, 
-                    gpointer      not_used) 
+gboolean 
+soup_server_authorize (SoupMessage *msg,
+                      gchar       *username, 
+                      gchar       *password,
+                      gchar       *realm)
 {
-       GSList *iter;
-       SoupServerCallbackFn cb = NULL;
-       SoupContext *ctx;
-       SoupMessage *msg;
-       GHashTable *req_headers;
-       gchar *req_host, *req_path, *req_method, *resp_phrase, *str, *url;
-       gint len, index;
-       SoupAction action;
-       gpointer user_data;
-
-       index = soup_substring_index (str, len, "\r\n\r\n");
-       if (!index) goto THROW_MALFORMED_REQUEST;
-
-       req_headers = g_hash_table_new (soup_str_case_hash, 
-                                       soup_str_case_equal);
-
-       if (!soup_headers_parse_request (str, 
-                                        index, 
-                                        req_headers, 
-                                        &req_method, 
-                                        &req_path))
-               goto THROW_MALFORMED_HEADER;
-
-       if ((g_strcasecmp (req_method, "POST") != 0 && 
-            g_strcasecmp (req_method, "M-POST") != 0))
-               goto THROW_MALFORMED_HEADER;
-
-       action = g_hash_table_lookup (req_headers, "SOAPAction");
-       if (!action) goto THROW_MALFORMED_HEADER;
-
-       for (iter = server_handlers; iter; iter = iter->next) {
-               SoupServerHandler *hand = iter->data;
-               if (!strcmp (hand->methodname, action)) {
-                       cb = hand->cb;
-                       user_data = hand->user_data;
-               }
-       }
-       if (!cb) goto THROW_NO_HANDLER;
-
-       req_host = g_hash_table_lookup (req_headers, "Host");
-       if (req_host) 
-               url = g_strconcat ("http://", req_host, req_path, NULL);
-       else 
-               url = g_strdup (req_path);
-
-       ctx = soup_context_get (url);
-       g_free (url);
-
-       /* No Host, no AbsoluteUri */
-       if (!ctx) {
-               url = g_strconcat ("http://localhost/", req_path, NULL);
-               ctx = soup_context_get (url);
-               g_free (url);
-       }
-
-       if (!ctx) goto THROW_MALFORMED_HEADER;
-
-       msg = soup_message_new (ctx, action);
-
-       msg->action = g_strdup (action);
-
-       msg->request.owner = SOUP_BUFFER_SYSTEM_OWNED;
-       msg->request.length = len - index - 4;
-       msg->request.body = &str [index + 4];
-       msg->request_headers = req_headers;
+       SoupServerHandler *hand = soup_server_get_handler (msg->action);
+
+       if (hand && hand->auth_fn) 
+               return (hand->auth_fn) (msg,
+                                       username,
+                                       password,
+                                       realm,
+                                       hand->auth_user_data);
+
+       if (soup_server_global_auth) 
+               return (soup_server_global_auth) (msg,
+                                                 username,
+                                                 password,
+                                                 realm,
+                                                 soup_server_global_auth_user_data);
 
-       msg->response_code = 200;
-       msg->response_phrase = resp_phrase = g_strdup ("OK");
-       msg->response_headers = g_hash_table_new (soup_str_case_hash, 
-                                                 soup_str_case_equal);
-       g_hash_table_insert (msg->response_headers, 
-                            "Content-Type",
-                            "text/xml\r\n\tcharset=\"utf-8\"");
-
-       (*cb) (msg, user_data); 
-
-       if (msg->response_phrase != resp_phrase) g_free (resp_phrase);
-
-       // write msg->response to STDOUT
-
-       g_free (req_method);
-       g_free (req_path);
-       soup_message_free (msg);
-       
- THROW_NO_HANDLER:
        return TRUE;
-
- THROW_MALFORMED_HEADER:
-       g_hash_table_destroy (req_headers);
-       g_free (req_method);
-       g_free (req_path);
-
- THROW_MALFORMED_REQUEST:
-       return TRUE;
-}
-
-static gboolean 
-soup_server_error_cb (GIOChannel   *iochannel, 
-                     GIOCondition  condition, 
-                     gpointer      not_used) 
-{
-       g_source_remove (server_read_source_tag);
-       soup_server_main_quit ();
-       return FALSE;
-}
-
-void
-soup_server_main (void)
-{
-       GIOChannel *chan = g_io_channel_unix_new (STDIN_FILENO);
-       server_main = g_main_new (TRUE);
-
-       server_read_source_tag = g_io_add_watch (chan, 
-                                                G_IO_IN, 
-                                                soup_server_read_cb, 
-                                                server_handlers);
-       g_io_add_watch (chan, 
-                       G_IO_ERR | G_IO_HUP | G_IO_NVAL, 
-                       soup_server_error_cb, 
-                       server_handlers);
-
-       g_main_run (server_main);
-}
-
-void  
-soup_server_main_quit (void)
-{
-       g_return_if_fail (server_main != NULL);
-       g_main_quit (server_main);
-       server_main = NULL;
 }
index fe2afb2..da93714 100644 (file)
@@ -21,11 +21,20 @@ void  soup_server_register           (const gchar          *methodname,
                                      SoupServerCallbackFn  cb,
                                      gpointer              user_data);
 
-void  soup_server_unregister_by_name (const gchar          *methodname);
+void  soup_server_unregister         (const gchar          *methodname);
 
-void  soup_server_unregister_by_cb   (SoupServerCallbackFn  cb);
+typedef gboolean (*SoupServerAuthorizeFn) (SoupMessage *msg, 
+                                          gchar       *username, 
+                                          gchar       *password,
+                                          gchar       *realm,
+                                          gpointer     user_data);
 
-void  soup_server_unregister_by_data (gpointer              user_data);
+void  soup_server_set_global_auth    (SoupServerAuthorizeFn  cb,
+                                     gpointer              *user_data);
+
+void  soup_server_set_method_auth    (gchar                 *methodname,
+                                     SoupServerAuthorizeFn  cb,
+                                     gpointer              *user_data);
 
 /* CGI Server methods */
 
@@ -38,6 +47,8 @@ void  soup_server_main_quit          (void);
 
 typedef void (*SoupServerInit) (void);
 
+extern SoupServerInit soup_server_init;
+
 /* Implement soup_server_init() in your library. */
 
 #endif /* SOUP_SERVER_H */
index 0dfb768..cf19c5a 100644 (file)
@@ -240,7 +240,7 @@ soup_connect_socks_proxy (SoupConnection        *conn,
                          SoupConnectCallbackFn  cb,
                          gpointer               user_data)
 {
-       SoupSocksData *sd;
+       SoupSocksData *sd = NULL;
        SoupContext *proxy_ctx;
        SoupUri *dest_uri;
        GIOChannel *channel;
index a8474f7..52a42a4 100644 (file)
@@ -84,7 +84,7 @@ soup_uri_get_default_port (gchar *proto)
 SoupUri *soup_uri_new (const gchar* uri_string)
 {
        SoupUri *g_uri;
-       char *semi, *colon, *at, *slash, *path, *query;
+       char *semi, *colon, *at, *slash, *path, *query = NULL;
        char **split;
 
        g_uri = g_new (SoupUri,1);
index 646d7a8..ebbaba2 100644 (file)
@@ -6,6 +6,6 @@ includedir=@includedir@
 Name: Soup
 Description: a SOAP client library in C.
 Version: @VERSION@
-Requires: glib, gnet
+Requires: glib
 Libs: -L${libdir} -lsoup @GNET_LIBS@ @XML_LIBS@
 Cflags: -I${includedir} @GNET_CFLAGS@ @XML_CFLAGS@
\ No newline at end of file