diff options
author | snowdrop | 2004-10-28 10:30:41 +0000 |
---|---|---|
committer | snowdrop | 2004-10-28 10:30:41 +0000 |
commit | d24d6ab7bbfda8e302af3a5cf8be62299d543c1a (patch) | |
tree | d5da54889ad987c216d6767e39c65607b4b678e5 /libcsoap | |
parent | ebde083c541b5d202014c41450a3519f4d08e3c9 (diff) | |
download | csoap-d24d6ab7bbfda8e302af3a5cf8be62299d543c1a.tar.gz csoap-d24d6ab7bbfda8e302af3a5cf8be62299d543c1a.tar.bz2 |
changed hstatus_t to herror_t and chagend the API function to return herror_t. Added herror_*() functions and fixed a bug in the socket receive comm.
Diffstat (limited to 'libcsoap')
-rw-r--r-- | libcsoap/soap-client.c | 136 | ||||
-rw-r--r-- | libcsoap/soap-client.h | 15 | ||||
-rwxr-xr-x | libcsoap/soap-ctx.c | 8 | ||||
-rwxr-xr-x | libcsoap/soap-ctx.h | 4 | ||||
-rw-r--r-- | libcsoap/soap-env.c | 215 | ||||
-rw-r--r-- | libcsoap/soap-env.h | 48 | ||||
-rw-r--r-- | libcsoap/soap-server.c | 76 | ||||
-rw-r--r-- | libcsoap/soap-server.h | 12 | ||||
-rw-r--r-- | libcsoap/soap-service.h | 4 |
9 files changed, 284 insertions, 234 deletions
diff --git a/libcsoap/soap-client.c b/libcsoap/soap-client.c index 5562399..2a56e11 100644 --- a/libcsoap/soap-client.c +++ b/libcsoap/soap-client.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-client.c,v 1.9 2004/10/20 14:17:36 snowdrop Exp $ +* $Id: soap-client.c,v 1.10 2004/10/28 10:30:46 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -27,7 +27,7 @@ /*--------------------------------- */
static int _block_socket = 0; -static SoapEnv *_soap_client_build_result(hresponse_t *res); +static herror_t _soap_client_build_result(hresponse_t *res, SoapEnv **out); /*--------------------------------- */ void soap_client_block_socket(int block)
@@ -42,11 +42,11 @@ int soap_client_get_blockmode() -int soap_client_init_args(int argc, char *argv[]) +herror_t soap_client_init_args(int argc, char *argv[]) { - return !httpc_init(argc, argv); + return httpc_init(argc, argv); } @@ -65,17 +65,15 @@ long _file_get_size(const char* filename) return size; } -SoapCtx* -soap_client_invoke(SoapCtx *call, const char *url, const char *soap_action) +
+herror_t +soap_client_invoke(SoapCtx *call, SoapCtx** response, const char *url, const char *soap_action) { /* Status */ - hstatus_t status; + herror_t status; /* Result document */ - SoapEnv* doc; - - /* Result Context */ - SoapCtx *ctx; + SoapEnv* res_env; /* Buffer variables*/ xmlBufferPtr buffer; @@ -118,48 +116,27 @@ soap_client_invoke(SoapCtx *call, const char *url, const char *soap_action) if (status != H_OK) { httpc_free(conn); - xmlBufferFree(buffer); - return soap_ctx_new( - soap_env_new_with_fault(Fault_Client, - "Can not begin post envelope","","")); + xmlBufferFree(buffer);
+ return status; } status = http_output_stream_write_string(conn->out, content); if (status != H_OK) { httpc_free(conn); xmlBufferFree(buffer); - return soap_ctx_new( - soap_env_new_with_fault(Fault_Client, - "Can not post envelope","","")); + return status;
} - /* res = httpc_post(conn, url, (int)strlen(content), content);*/ - res = httpc_post_end(conn); - if (res == NULL) { + status = httpc_post_end(conn, &res); + if (status != H_OK) { httpc_free(conn); xmlBufferFree(buffer); - return soap_ctx_new( - soap_env_new_with_fault(Fault_Client, - conn->errmsg,"","")); + return status;
} } else { - /* Use content-length transport */ - /*for (part=call->attachments->parts; part; part=part->next) { - file_size = _file_get_size(part->filename); - if (file_size == -1) [ - httpc_free(conn); - xmlBufferFree(buffer); - return soap_ctx_new( - soap_env_new_with_fault(Fault_Client, - "Can not open file!","","")); - } - - total_size += file_size + BOUDARY_LENGTH; - }*/ - /* Use chunked transport */ httpc_set_header(conn, HEADER_TRANSFER_ENCODING, TRANSFER_ENCODING_CHUNKED); @@ -168,27 +145,21 @@ soap_client_invoke(SoapCtx *call, const char *url, const char *soap_action) if (status != H_OK) { httpc_free(conn); xmlBufferFree(buffer); - return soap_ctx_new( - soap_env_new_with_fault(Fault_Client, - "Can not begin MIME transport","","")); + return status;
} status = httpc_mime_next(conn, start_id, "text/xml", "binary"); if (status != H_OK) { httpc_free(conn); xmlBufferFree(buffer); - return soap_ctx_new( - soap_env_new_with_fault(Fault_Client, - "MIME transport error","","")); + return status;
} status = http_output_stream_write(conn->out, content, strlen(content)); if (status != H_OK) { httpc_free(conn); xmlBufferFree(buffer); - return soap_ctx_new( - soap_env_new_with_fault(Fault_Client, - "MIME transport error","","")); + return status;
} @@ -200,20 +171,16 @@ soap_client_invoke(SoapCtx *call, const char *url, const char *soap_action) log_error2("Send file failed. Status:%d", status); httpc_free(conn); xmlBufferFree(buffer); - return soap_ctx_new( - soap_env_new_with_fault(Fault_Client, - "MIME transport error while sending file","","")); + return status;
} } - res = httpc_mime_end(conn); - if (!res) + status = httpc_mime_end(conn, &res); + if (status != H_OK) { httpc_free(conn); xmlBufferFree(buffer); - return soap_ctx_new( - soap_env_new_with_fault(Fault_Client, - "MIME transport error","","")); + return status;
} } @@ -221,59 +188,54 @@ soap_client_invoke(SoapCtx *call, const char *url, const char *soap_action) xmlBufferFree(buffer); /* Build result */ - /* TODO: If res == NULL, find out where and why it is NULL! */ - doc = _soap_client_build_result(res); + status = _soap_client_build_result(res, &res_env); + if (status != H_OK)
+ return status;
/* Create Context */ - ctx = soap_ctx_new(doc); - soap_ctx_add_files(ctx, res->attachments); + *response = soap_ctx_new(res_env); + soap_ctx_add_files(*response, res->attachments); - return ctx; + return H_OK; } -static -SoapEnv* _soap_client_build_result(hresponse_t *res) -{ - SoapEnv *env; +static
+herror_t + _soap_client_build_result(hresponse_t *res, SoapEnv** env) +{
+ herror_t err; log_verbose2("Building result (%p)", res); if (res == NULL) - return soap_env_new_with_fault(Fault_Client, - "Response is NULL","",""); + return herror_new("_soap_client_build_result",
+ GENERAL_INVALID_PARAM, "hresponse_t is NULL"); if (res->in == NULL) - return soap_env_new_with_fault(Fault_Client, - "Empty response from server!","",""); - + return herror_new("_soap_client_build_result",
+ GENERAL_INVALID_PARAM, "Empty response from server"); -/* - doc = xmlParseDoc(BAD_CAST res->body); - if (doc == NULL) { - return soap_env_new_with_fault(Fault_Client, - "Response is not in XML format!","",""); - } - env = soap_env_new_from_doc(doc); -*/ - env = soap_env_new_from_stream(res->in); + err = soap_env_new_from_stream(res->in, env); - if (env == NULL) { -/* xmlFreeDoc(doc);*/ - return soap_env_new_with_fault(Fault_Client, - "Can not create envelope","",""); + if (err != H_OK) {
+ return err; } - return env; + return H_OK; } -SoapCtx *soap_client_ctx_new(const char *urn, const char *method) -{ - SoapCtx *ctx = soap_ctx_new(soap_env_new_with_method(urn, method)); +herror_t soap_client_ctx_new(const char *urn, const char *method, SoapCtx **out) +{
+ SoapEnv *env;
+ herror_t err;
+ err = soap_env_new_with_method(urn, method, &env);
+ if (err != H_OK) return err; + *out = soap_ctx_new(env); - return ctx; + return H_OK; } diff --git a/libcsoap/soap-client.h b/libcsoap/soap-client.h index 6820c14..22e41bb 100644 --- a/libcsoap/soap-client.h +++ b/libcsoap/soap-client.h @@ -1,5 +1,5 @@ /******************************************************************
- * $Id: soap-client.h,v 1.5 2004/10/20 14:17:36 snowdrop Exp $
+ * $Id: soap-client.h,v 1.6 2004/10/28 10:30:46 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -30,7 +30,7 @@ /**
Initializes the client side soap engine
*/
-int soap_client_init_args(int argc, char *argv[]);
+herror_t soap_client_init_args(int argc, char *argv[]);
/**
@@ -38,19 +38,22 @@ int soap_client_init_args(int argc, char *argv[]); the given envelope.
@param env envelope to send
+ @param response the result envelope
@param url url to the soap server
@soap_action value for "SoapAction:" in the
HTTP request header.
- @returns the result envelope. In case of failure,
- this function return an envelope with a fault object.
+ @returns H_OK if success
*/
-SoapCtx* soap_client_invoke(SoapCtx *ctx,
+herror_t soap_client_invoke(SoapCtx *ctx, SoapCtx** response,
const char *url,
const char *soap_action);
-SoapCtx *soap_client_ctx_new(const char *urn, const char *method);
+/**
+ Creates a new soap context object.
+*/
+herror_t soap_client_ctx_new(const char *urn, const char *method, SoapCtx **out);
/**
Sets the underlaying socket to use while connecting
diff --git a/libcsoap/soap-ctx.c b/libcsoap/soap-ctx.c index a77bbdd..944abf0 100755 --- a/libcsoap/soap-ctx.c +++ b/libcsoap/soap-ctx.c @@ -1,5 +1,5 @@ /******************************************************************
- * $Id: soap-ctx.c,v 1.1 2004/10/15 13:33:48 snowdrop Exp $
+ * $Id: soap-ctx.c,v 1.2 2004/10/28 10:30:46 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -49,14 +49,16 @@ void soap_ctx_add_files(SoapCtx* ctx, attachments_t *attachments) }
-hstatus_t soap_ctx_add_file(SoapCtx* ctx, const char* filename, const char* content_type, char *dest_href)
+herror_t soap_ctx_add_file(SoapCtx* ctx, const char* filename, const char* content_type, char *dest_href)
{
char cid[250];
char id[250];
part_t *part;
static int counter = 1;
FILE *test = fopen(filename, "r");
- if (!test) return FILE_ERROR_OPEN;
+ if (!test)
+ return herror_new("soap_ctx_add_file", FILE_ERROR_OPEN,
+ "Can not open file '%s'", filename);
fclose(test);
diff --git a/libcsoap/soap-ctx.h b/libcsoap/soap-ctx.h index c32f372..2ea107b 100755 --- a/libcsoap/soap-ctx.h +++ b/libcsoap/soap-ctx.h @@ -1,5 +1,5 @@ /******************************************************************
- * $Id: soap-ctx.h,v 1.1 2004/10/15 13:33:48 snowdrop Exp $
+ * $Id: soap-ctx.h,v 1.2 2004/10/28 10:30:46 snowdrop Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -40,7 +40,7 @@ typedef struct _SoapCtx SoapCtx* soap_ctx_new(SoapEnv *env); /* should only be used internally */
/* Size of destination dest_href should be MAX_HREF_SIZE */
-hstatus_t soap_ctx_add_file(SoapCtx* ctx, const char* filename, const char* content_type, char *dest_href);
+herror_t soap_ctx_add_file(SoapCtx* ctx, const char* filename, const char* content_type, char *dest_href);
void soap_ctx_add_files(SoapCtx* ctx, attachments_t *attachments);
void soap_ctx_free(SoapCtx* ctx);
diff --git a/libcsoap/soap-env.c b/libcsoap/soap-env.c index 7d7811b..6527028 100644 --- a/libcsoap/soap-env.c +++ b/libcsoap/soap-env.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-env.c,v 1.8 2004/10/15 14:33:07 snowdrop Exp $ +* $Id: soap-env.c,v 1.9 2004/10/28 10:30:46 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -102,21 +102,96 @@ static /* ---------------------------------------------------------------------------- */ -SoapEnv * +
+
+herror_t
+soap_env_new_from_doc (xmlDocPtr doc, SoapEnv **out)
+{
+ xmlNodePtr node;
+ SoapEnv *env;
+
+ if (doc == NULL)
+ {
+ log_error1 ("Can not create xml document!");
+ return herror_new("soap_env_new_from_doc",
+ GENERAL_INVALID_PARAM, "XML Document (xmlDocPtr) is NULL");
+ }
+
+ node = xmlDocGetRootElement (doc);
+ if (node == NULL)
+ {
+ log_error1 ("xml document is empty!");
+ return herror_new("soap_env_new_from_doc",
+ XML_ERROR_EMPTY_DOCUMENT, "XML Document is empty!");
+ }
+
+ env = (SoapEnv *) malloc (sizeof (SoapEnv));
+
+ /* set root */
+ env->root = node;
+
+ /* set method root
+ set call->cur (current node) to <method>.
+ xpath: //Envelope/Body/
+ */
+ node = soap_xml_get_children (env->root);/* Check for NULL ! */
+ env->cur = soap_xml_get_children (node); /* Check for NULL ! */
+
+ *out = env;
+ return H_OK;
+}
+
+
+
+
+herror_t
+soap_env_new_from_buffer (const char *buffer, SoapEnv **out)
+{
+ xmlDocPtr doc;
+ herror_t err;
+
+ if (buffer == NULL)
+ return herror_new("soap_env_new_from_buffer",
+ GENERAL_INVALID_PARAM, "buffer (first param) is NULL");
+
+ doc = xmlParseDoc (BAD_CAST buffer);
+ if (doc == NULL)
+ return herror_new("soap_env_new_from_buffer",
+ XML_ERROR_PARSE, "Can not parse xml");
+
+ err = soap_env_new_from_doc (doc, out);
+ if (err != H_OK) {
+ xmlFreeDoc (doc);
+ }
+
+ return err;
+}
+
+
+herror_t soap_env_new_with_fault (fault_code_t faultcode, const char *faultstring, - const char *faultactor, const char *detail) + const char *faultactor, const char *detail, SoapEnv **out) { xmlDocPtr doc; + herror_t err;
+
doc = soap_fault_build (faultcode, faultstring, faultactor, detail); if (doc == NULL) - return NULL; - return soap_env_new_from_doc (doc); + return herror_new("soap_env_new_with_fault",
+ XML_ERROR_PARSE, "Can not parse fault xml");
+
+ err = soap_env_new_from_doc (doc, out);
+ if (err != H_OK) {
+ xmlFreeDoc (doc);
+ }
+
+ return err;
} -SoapEnv * -soap_env_new_with_response (SoapEnv * request) +herror_t +soap_env_new_with_response (SoapEnv * request, SoapEnv **out) { char urn[100]; char methodname[150]; @@ -124,19 +199,20 @@ soap_env_new_with_response (SoapEnv * request) if (request == NULL) { - log_error1 ("request object is NULL"); - return NULL; + return herror_new("soap_env_new_with_response",
+ GENERAL_INVALID_PARAM, "request (first param) is NULL");
} if (request->root == NULL) { - log_error1 ("request has no xml"); - return NULL; - } + return herror_new("soap_env_new_with_response",
+ GENERAL_INVALID_PARAM, "request (first param) has no xml structure");
+ } if (!soap_env_find_methodname (request, methodname)) { - return NULL; + return herror_new("soap_env_new_with_response",
+ GENERAL_INVALID_PARAM, "Method name '%s' not found in request", SAVE_STR(methodname));
} if (!soap_env_find_urn (request, urn)) @@ -148,15 +224,14 @@ soap_env_new_with_response (SoapEnv * request) } sprintf (methodname2, "%sResponse", methodname); - return soap_env_new_with_method (urn, methodname2); + return soap_env_new_with_method (urn, methodname2, out); } -SoapEnv * -soap_env_new_with_method (const char *urn, const char *method) +herror_t +soap_env_new_with_method (const char *urn, const char *method, SoapEnv **out) { xmlDocPtr env; - SoapEnv *call; xmlChar buffer[1054]; @@ -188,19 +263,30 @@ soap_env_new_with_method (const char *urn, const char *method) #endif } - env = xmlParseDoc (buffer); - call = soap_env_new_from_doc (env); +
+ env = xmlParseDoc (buffer);
+ if (!env)
+ return herror_new("soap_env_new_with_method",
+ XML_ERROR_PARSE, "Can not parse xml");
+ + return soap_env_new_from_doc (env, out); - return call; } +
+
static int _soap_env_xml_io_read(void* ctx, char *buffer, int len) -{ - http_input_stream_t *in = (http_input_stream_t *)ctx; - if(!http_input_stream_is_ready(in)) - return 0; - return http_input_stream_read(in, buffer, len); +{
+ int readed; + http_input_stream_t *in = (http_input_stream_t*)ctx;
+ if(!http_input_stream_is_ready(in)) + return 0;
+
+ readed = http_input_stream_read(in, buffer, len);
+ if (readed == -1)
+ return 0;
+ return readed; } static @@ -210,15 +296,21 @@ int _soap_env_xml_io_close(void *ctx) return 0; } -SoapEnv * -soap_env_new_from_stream(http_input_stream_t *in) +
+herror_t +soap_env_new_from_stream(http_input_stream_t *in, SoapEnv **out) { - xmlDocPtr doc; - + xmlDocPtr doc;
+ herror_t err; +
doc = xmlReadIO(_soap_env_xml_io_read, _soap_env_xml_io_close, in, "", NULL, 0); - - return soap_env_new_from_doc (doc); +
+ if (in->err != H_OK) return in->err;
+ if (doc == NULL) return herror_new("soap_env_new_from_stream",
+ XML_ERROR_PARSE, "Trying to parse not valid xml"); + err = soap_env_new_from_doc (doc, out);
+ return err;
} @@ -346,67 +438,6 @@ soap_env_free (SoapEnv * env) } -SoapEnv * -soap_env_new_from_doc (xmlDocPtr doc) -{ - SoapEnv *env; - xmlNodePtr node; - - if (doc == NULL) - { - log_error1 ("Can not create xml document!"); - return NULL; - } - - node = xmlDocGetRootElement (doc); - if (node == NULL) - { - log_error1 ("xml document is empty!"); - return NULL; - } - - env = (SoapEnv *) malloc (sizeof (SoapEnv)); - - /* set root */ - env->root = node; - - /* set method root - set call->cur (current node) to <method>. - xpath: //Envelope/Body/ - */ - node = soap_xml_get_children (env->root); - env->cur = soap_xml_get_children (node); - - return env; -} - - - - -SoapEnv * -soap_env_new_from_buffer (const char *buffer) -{ - xmlDocPtr doc; - SoapEnv *env; - - if (buffer == NULL) - return NULL; - - doc = xmlParseDoc (BAD_CAST buffer); - if (doc == NULL) - return NULL; - - env = soap_env_new_from_doc (doc); - if (env == NULL) - { - xmlFreeDoc (doc); - return NULL; - } - - return env; -} - - xmlNodePtr soap_env_get_body (SoapEnv * env) { diff --git a/libcsoap/soap-env.h b/libcsoap/soap-env.h index 5b3bd7f..58af136 100644 --- a/libcsoap/soap-env.h +++ b/libcsoap/soap-env.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-env.h,v 1.7 2004/10/15 13:33:13 snowdrop Exp $ + * $Id: soap-env.h,v 1.8 2004/10/28 10:30:46 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -50,8 +50,8 @@ typedef struct _SoapEnv @param faultstring A fault message @param faultactor The fault actor (This can be NULL) @param detail The detail of the error (This can be NULL) - - @returns A Soap envelope object like follows + @param out the result envelope out parameter like follows + @returns H_OK if success <pre> <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..." @@ -71,11 +71,12 @@ typedef struct _SoapEnv </pre> - */ -SoapEnv *soap_env_new_with_fault(fault_code_t faultcode, + */
+herror_t +soap_env_new_with_fault(fault_code_t faultcode, const char *faultstring, const char *faultactor, - const char *detail); + const char *detail, SoapEnv **out); /** Creates an envelope with a method to invoke a soap service. @@ -84,7 +85,8 @@ SoapEnv *soap_env_new_with_fault(fault_code_t faultcode, @param urn The urn of the soap service to invoke @param method The method name of the soap service - @returns A Soap envelope object like follows + @param out the result envelope out parameter like follows
+ @returns H_OK if success
<pre> <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..." @@ -101,7 +103,8 @@ SoapEnv *soap_env_new_with_fault(fault_code_t faultcode, </pre> */ -SoapEnv *soap_env_new_with_method(const char *urn, const char *method); +herror_t
+soap_env_new_with_method(const char *urn, const char *method, SoapEnv **out); /** @@ -115,7 +118,8 @@ SoapEnv *soap_env_new_with_method(const char *urn, const char *method); @param req The request object. A response object will be created to this request. - @returns A Soap envelope object like follows + @param out the result envelope out paramter like follows
+ @returns H_OK if success
<pre> <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..." @@ -133,18 +137,19 @@ SoapEnv *soap_env_new_with_method(const char *urn, const char *method); */ -SoapEnv *soap_env_new_with_response(SoapEnv *req); +herror_t soap_env_new_with_response(SoapEnv *req,SoapEnv **out); /** Creates an envelope from a given libxml2 xmlDoc pointer. - @param doc the xml document pointer - @returns A Soap envelop object if success, - NULL otherwise. + @param doc the xml document pointer
+ @param out the output envelope object
+ @returns H_OK if success + */ -SoapEnv *soap_env_new_from_doc(xmlDocPtr doc); +herror_t soap_env_new_from_doc(xmlDocPtr doc, SoapEnv **out); /** @@ -152,17 +157,20 @@ SoapEnv *soap_env_new_from_doc(xmlDocPtr doc); The string must be in xml format. @param buffer The string to parse into a envelope. - @returns A soap envelope object if success or - NULL if the string can not be parsed or the string - does not represent an soap envelope in xml format. + @param out the output envelope object
+ @returns H_OK if success */ -SoapEnv *soap_env_new_from_buffer(const char* buffer); +herror_t soap_env_new_from_buffer(const char* buffer,SoapEnv **out); /** - Create an envelope from input stream + Create an envelope from input stream
+ + @param in the input stream object to read from
+ @param out the output envelope object
+ @returns H_OK if success
*/ -SoapEnv *soap_env_new_from_stream(http_input_stream_t *in); +herror_t soap_env_new_from_stream(http_input_stream_t *in, SoapEnv **out); /* --------------------------------------------------- */ /* XML Serializer functions and typedefs */ diff --git a/libcsoap/soap-server.c b/libcsoap/soap-server.c index 690fa6b..65bef3f 100644 --- a/libcsoap/soap-server.c +++ b/libcsoap/soap-server.c @@ -1,5 +1,5 @@ /****************************************************************** -* $Id: soap-server.c,v 1.6 2004/10/20 14:17:36 snowdrop Exp $ +* $Id: soap-server.c,v 1.7 2004/10/28 10:30:46 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -58,9 +58,9 @@ void _soap_server_send_fault(httpd_conn_t *conn, hpair_t *header, /*---------------------------------*/ -int soap_server_init_args(int argc, char *argv[]) +herror_t soap_server_init_args(int argc, char *argv[]) { - return !httpd_init(argc, argv); + return httpd_init(argc, argv); } @@ -82,7 +82,7 @@ int soap_server_register_router(SoapRouter *router, const char* context) } -int soap_server_run() +herror_t soap_server_run() { return httpd_run(); } @@ -113,7 +113,8 @@ void soap_server_entry(httpd_conn_t *conn, hrequest_t *req) SoapCtx *ctx, *ctxres; SoapRouter *router; SoapService *service; - SoapEnv *env; + SoapEnv *env;
+ herror_t err; if (req->method != HTTP_REQUEST_POST) { @@ -125,10 +126,17 @@ void soap_server_entry(httpd_conn_t *conn, hrequest_t *req) return; } -/* postdata = httpd_get_postdata(conn, req, &received, -1);*/ - env = soap_env_new_from_stream(req->in); - header = hpairnode_new(HEADER_CONTENT_TYPE, "text/xml", NULL); + header = hpairnode_new(HEADER_CONTENT_TYPE, "text/xml", NULL);
+
+ err = soap_env_new_from_stream(req->in, &env);
+ if (err != H_OK)
+ {
+ _soap_server_send_fault(conn, header, herror_message(err));
+ herror_release(err);
+ return;
+ }
+ if (env == NULL) { @@ -183,13 +191,22 @@ void soap_server_entry(httpd_conn_t *conn, hrequest_t *req) return; } else { - log_verbose2("func: %p", service->func); + log_verbose2("func: %p", service->func);
+ ctxres = soap_ctx_new(NULL); /* ===================================== */ /* CALL SERVICE FUNCTION */ /* ===================================== */ - ctxres = service->func(ctx); - log_verbose2("func returned: (%p)", ctxres); - if (ctxres == NULL) { + err = service->func(ctx, ctxres);
+ if (err != H_OK) {
+ sprintf(buffer, "Service returned following error message: '%s'",
+ herror_message(err));
+ herror_release(err);
+ _soap_server_send_fault(conn, header, buffer);
+ soap_ctx_free(ctx);
+ return;
+ }
+ + if (ctxres->env == NULL) { sprintf(buffer, "Service '%s' returned no envelope", urn); _soap_server_send_fault(conn, header, buffer); @@ -271,13 +288,38 @@ static void _soap_server_send_fault(httpd_conn_t *conn, hpair_t *header, const char* errmsg) { - SoapEnv *envres; + SoapEnv *envres;
+ herror_t err;
+ char buffer[45]; httpd_set_headers(conn, header); - httpd_send_header(conn, 500, "FAILED"); - envres = soap_env_new_with_fault(Fault_Server, + err = httpd_send_header(conn, 500, "FAILED");
+ if (err != H_OK) {
+ /* WARNING: unhandled exception !*/
+ log_error4("%s():%s [%d]", herror_func(err), herror_message(err), herror_code(err));
+ return;
+ }
+ + err = soap_env_new_with_fault(Fault_Server, errmsg?errmsg:"General error", - "cSOAP_Server", NULL); - _soap_server_send_env(conn->out, envres); + "cSOAP_Server", NULL, &envres);
+ if (err != H_OK) {
+ log_error1(herror_message(err));
+ http_output_stream_write_string(conn->out, "<html><head></head><body>");
+ http_output_stream_write_string(conn->out, "<h1>Error</h1><hr>");
+ http_output_stream_write_string(conn->out, "Error while sending fault object:<br>Message: ");
+ http_output_stream_write_string(conn->out, herror_message(err));
+ http_output_stream_write_string(conn->out, "<br>Function: ");
+ http_output_stream_write_string(conn->out, herror_func(err));
+ http_output_stream_write_string(conn->out, "<br>Error code: ");
+ sprintf(buffer, "%d", herror_code(err));
+ http_output_stream_write_string(conn->out, buffer);
+ http_output_stream_write_string(conn->out, "</body></html>");
+ return;
+
+ herror_release(err);
+ } else { + _soap_server_send_env(conn->out, envres);
+ } } diff --git a/libcsoap/soap-server.h b/libcsoap/soap-server.h index 13abd92..62d136c 100644 --- a/libcsoap/soap-server.h +++ b/libcsoap/soap-server.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-server.h,v 1.3 2004/10/15 13:33:13 snowdrop Exp $ + * $Id: soap-server.h,v 1.4 2004/10/28 10:30:46 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -19,7 +19,7 @@ * Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * - * Email: ayaz@jprogrammer.net + * Email: ferhatayaz@yahoo.com ******************************************************************/ #ifndef cSOAP_SERVER_H #define cSOAP_SERVER_H @@ -34,7 +34,9 @@ <TABLE border=1> <TR><TH>Argument</TH><TH>Description</TH></TR> - <TR><TD>-NHTTPport [port]</TD><TD>Port to listen (default: 10000)</TD></TR> + <TR><TD>-NHTTPport [port]</TD><TD>Port to listen (default: 10000)</TD></TR>
+ <TR><TD>-NHTTPmaxconn [num]</TD><TD>Maximum thread connections</TD></TR>
+ <TR><TD>-NHTTPlog [logfilename]</TD><TD>logfile</TD></TR>
</TABLE> @param argc commandline arg count @@ -42,7 +44,7 @@ @returns 1 if success, 0 otherwise */ -int soap_server_init_args(int argc, char *argv[]); +herror_t soap_server_init_args(int argc, char *argv[]); /** @@ -66,7 +68,7 @@ int soap_server_register_router(SoapRouter *router, const char* context); Enters the server loop and starts to listen to http requests. */ -int soap_server_run(); +herror_t soap_server_run(); /** diff --git a/libcsoap/soap-service.h b/libcsoap/soap-service.h index 7c2855e..c03d7df 100644 --- a/libcsoap/soap-service.h +++ b/libcsoap/soap-service.h @@ -1,5 +1,5 @@ /****************************************************************** - * $Id: soap-service.h,v 1.2 2004/10/15 13:34:02 snowdrop Exp $ + * $Id: soap-service.h,v 1.3 2004/10/28 10:30:46 snowdrop Exp $ * * CSOAP Project: A SOAP client/server library in C * Copyright (C) 2003 Ferhat Ayaz @@ -28,7 +28,7 @@ #include <libcsoap/soap-env.h> #include <libcsoap/soap-ctx.h> -typedef SoapCtx* (*SoapServiceFunc)(SoapCtx*); +typedef herror_t (*SoapServiceFunc)(SoapCtx*, SoapCtx*); typedef struct _SoapService |