summaryrefslogtreecommitdiffstats
path: root/nanohttp
diff options
context:
space:
mode:
authorGravatar m0gg2006-11-25 15:06:57 +0000
committerGravatar m0gg2006-11-25 15:06:57 +0000
commit82c14810dd1c101f20052c4ab92f33c57a255cc1 (patch)
tree6d445e22baf26d4df2ae08ad678ba56a19f22e7e /nanohttp
parent01aaebca2e4b8b2d13aef5cdeda9b8874efe1c31 (diff)
downloadcsoap-82c14810dd1c101f20052c4ab92f33c57a255cc1.tar.gz
csoap-82c14810dd1c101f20052c4ab92f33c57a255cc1.tar.bz2
documentation enhancements and code cleanup
Diffstat (limited to 'nanohttp')
-rw-r--r--nanohttp/Makefile.am4
-rw-r--r--nanohttp/nanohttp-admin.c3
-rw-r--r--nanohttp/nanohttp-client.c5
-rw-r--r--nanohttp/nanohttp-common.c119
-rw-r--r--nanohttp/nanohttp-common.h564
-rw-r--r--nanohttp/nanohttp-error.h102
-rwxr-xr-xnanohttp/nanohttp-mime.c79
-rwxr-xr-xnanohttp/nanohttp-mime.h4
-rwxr-xr-xnanohttp/nanohttp-request.c5
-rwxr-xr-xnanohttp/nanohttp-request.h217
-rwxr-xr-xnanohttp/nanohttp-response.c12
-rwxr-xr-xnanohttp/nanohttp-response.h119
-rw-r--r--nanohttp/nanohttp-server.c3
-rw-r--r--nanohttp/nanohttp-socket.c6
-rw-r--r--nanohttp/nanohttp-ssl.c3
-rwxr-xr-xnanohttp/nanohttp-stream.c5
16 files changed, 848 insertions, 402 deletions
diff --git a/nanohttp/Makefile.am b/nanohttp/Makefile.am
index 18ccaf6..e960f50 100644
--- a/nanohttp/Makefile.am
+++ b/nanohttp/Makefile.am
@@ -6,13 +6,13 @@ libnanohttp_la_SOURCES=nanohttp-common.c nanohttp-socket.c nanohttp-client.c
nanohttp-server.c nanohttp-stream.c nanohttp-mime.c \
nanohttp-request.c nanohttp-response.c \
nanohttp-base64.c nanohttp-ssl.c nanohttp-logging.c \
- nanohttp-admin.c
+ nanohttp-admin.c nanohttp-error.c
libnanohttp_la_HEADERS=nanohttp-common.h nanohttp-socket.h nanohttp-client.h \
nanohttp-server.h nanohttp-stream.h nanohttp-mime.h \
nanohttp-request.h nanohttp-response.h \
nanohttp-base64.h nanohttp-ssl.h nanohttp-logging.h \
- nanohttp-admin.h
+ nanohttp-admin.h nanohttp-error.h
libnanohttp_la_LDFLAGS= -version-info @nanohttp_version@ -release @nanohttp_release@
libnanohttp_la_CFLAGS=-I${top_srcdir} -D__NHTTP_INTERNAL=1
diff --git a/nanohttp/nanohttp-admin.c b/nanohttp/nanohttp-admin.c
index 746855b..fa2fdaf 100644
--- a/nanohttp/nanohttp-admin.c
+++ b/nanohttp/nanohttp-admin.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-admin.c,v 1.4 2006/11/23 15:27:33 m0gg Exp $
+* $Id: nanohttp-admin.c,v 1.5 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A SOAP client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -37,6 +37,7 @@
#include <pthread.h>
#endif
+#include "nanohttp-error.h"
#include "nanohttp-common.h"
#include "nanohttp-stream.h"
#include "nanohttp-request.h"
diff --git a/nanohttp/nanohttp-client.c b/nanohttp/nanohttp-client.c
index b475d65..d9bf113 100644
--- a/nanohttp/nanohttp-client.c
+++ b/nanohttp/nanohttp-client.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-client.c,v 1.45 2006/11/24 17:28:07 m0gg Exp $
+* $Id: nanohttp-client.c,v 1.46 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -61,13 +61,14 @@
#include <netinet/in.h>
#endif
+#include "nanohttp-logging.h"
+#include "nanohttp-error.h"
#include "nanohttp-common.h"
#include "nanohttp-socket.h"
#include "nanohttp-stream.h"
#include "nanohttp-request.h"
#include "nanohttp-response.h"
#include "nanohttp-base64.h"
-#include "nanohttp-logging.h"
#include "nanohttp-client.h"
/*--------------------------------------------------
diff --git a/nanohttp/nanohttp-common.c b/nanohttp/nanohttp-common.c
index 5e13755..212de01 100644
--- a/nanohttp/nanohttp-common.c
+++ b/nanohttp/nanohttp-common.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-common.c,v 1.32 2006/11/24 17:28:07 m0gg Exp $
+* $Id: nanohttp-common.c,v 1.33 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -53,8 +53,9 @@
#include <pthread.h>
#endif
-#include "nanohttp-common.h"
#include "nanohttp-logging.h"
+#include "nanohttp-error.h"
+#include "nanohttp-common.h"
static int
strcmpigcase(const char *s1, const char *s2)
@@ -79,72 +80,6 @@ strcmpigcase(const char *s1, const char *s2)
return 1;
}
-typedef struct _herror_impl_t
-{
- int errcode;
- char message[250];
- char func[100];
-} herror_impl_t;
-
-herror_t
-herror_new(const char *func, int errcode, const char *format, ...)
-{
- va_list ap;
- herror_impl_t *impl;
-
- if (!(impl = (herror_impl_t *) malloc(sizeof(herror_impl_t))))
- {
- log_error2("malloc failed (%s)", strerror(errno));
- return NULL;
- }
-
- impl->errcode = errcode;
- strcpy(impl->func, func);
-
- va_start(ap, format);
- vsprintf(impl->message, format, ap);
- va_end(ap);
-
- return (herror_t) impl;
-}
-
-int
-herror_code(herror_t err)
-{
- herror_impl_t *impl = (herror_impl_t *) err;
- if (!err)
- return H_OK;
- return impl->errcode;
-}
-
-char *
-herror_func(herror_t err)
-{
- herror_impl_t *impl = (herror_impl_t *) err;
- if (!err)
- return "";
- return impl->func;
-}
-
-char *
-herror_message(herror_t err)
-{
- herror_impl_t *impl = (herror_impl_t *) err;
- if (!err)
- return "";
- return impl->message;
-}
-
-void
-herror_release(herror_t err)
-{
- herror_impl_t *impl = (herror_impl_t *) err;
- if (!err)
- return;
- free(impl);
-}
-
-
hpair_t *
hpairnode_new(const char *key, const char *value, hpair_t * next)
{
@@ -583,7 +518,6 @@ content_type_new(const char *content_type_str)
return ct;
}
-
void
content_type_free(content_type_t * ct)
{
@@ -592,15 +526,21 @@ content_type_free(content_type_t * ct)
hpairnode_free_deep(ct->params);
free(ct);
-}
+ return;
+}
-part_t *
-part_new(const char *id, const char *filename,
- const char *content_type, const char *transfer_encoding,
- part_t * next)
+struct part_t *
+part_new(const char *id, const char *filename, const char *content_type, const char *transfer_encoding, struct part_t * next)
{
- part_t *part = (part_t *) malloc(sizeof(part_t));
+ struct part_t *part;
+
+ if (!(part = (struct part_t *) malloc(sizeof(struct part_t))))
+ {
+ log_error2("malloc failed (%s)", strerror(errno));
+ return NULL;
+ }
+
part->header = NULL;
part->next = next;
part->deleteOnExit = 0;
@@ -632,7 +572,7 @@ part_new(const char *id, const char *filename,
}
void
-part_free(part_t * part)
+part_free(struct part_t * part)
{
if (part == NULL)
return;
@@ -647,11 +587,17 @@ part_free(part_t * part)
free(part);
}
-attachments_t *
-attachments_new() /* should be used internally */
+struct attachments_t *
+attachments_new(void) /* should be used internally */
{
- attachments_t *attachments =
- (attachments_t *) malloc(sizeof(attachments_t));
+ struct attachments_t *attachments;
+
+ if (!(attachments = (struct attachments_t *) malloc(sizeof(struct attachments_t))))
+ {
+ log_error2("malloc failed (%s)", strerror(errno));
+ return NULL;
+ }
+
attachments->parts = NULL;
attachments->last = NULL;
attachments->root_part = NULL;
@@ -660,9 +606,8 @@ attachments_new() /* should be used internally */
}
void
-attachments_add_part(attachments_t * attachments, part_t * part)
+attachments_add_part(struct attachments_t *attachments, struct part_t *part)
{
- /* paranoya check */
if (!attachments)
return;
@@ -672,15 +617,17 @@ attachments_add_part(attachments_t * attachments, part_t * part)
attachments->parts = part;
attachments->last = part;
+
+ return;
}
/*
Free a mime message
*/
void
-attachments_free(attachments_t * message)
+attachments_free(struct attachments_t *message)
{
- part_t *tmp, *part;
+ struct part_t *tmp, *part;
if (message == NULL)
return;
@@ -695,8 +642,10 @@ attachments_free(attachments_t * message)
if (message->root_part)
part_free(message->root_part);
-/* TODO (#1#): HERE IS A BUG!!!! */
+
free(message);
+
+ return;
}
diff --git a/nanohttp/nanohttp-common.h b/nanohttp/nanohttp-common.h
index cc9f8f8..dabdda6 100644
--- a/nanohttp/nanohttp-common.h
+++ b/nanohttp/nanohttp-common.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-common.h,v 1.33 2006/11/23 15:27:33 m0gg Exp $
+ * $Id: nanohttp-common.h,v 1.34 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -34,10 +34,12 @@
*
* There are a few header fields which have general applicability for both
* request and response messages, but which do not apply to the entity being
- * transferred. These header fields apply only to the message being transmitted.
- * (see RFC2616)
+ * transferred. These header fields apply only to the message being transmitted.
+ *
+ * @see http://www.ietf.org/rfc/rfc/2616.txt
*
*/
+
#define HEADER_CACHE_CONTROL "Cache-Control"
#define HEADER_CONNECTION "Connection"
#define HEADER_DATE "Date"
@@ -57,6 +59,8 @@
* metainformation is OPTIONAL; some might be REQUIRED by portions of this
* specification. (see RFC2616 7.1)
*
+ * @see http://www.ietf.org/rfc/rfc2616.txt
+ *
*/
#define HEADER_ALLOW "Allow"
#define HEADER_CONTENT_ENCODING "Content-Encoding"
@@ -71,7 +75,7 @@
/**
*
- * Command line arguments for client and server.
+ * Common commandline arguments for client and server.
*
*/
#define NHTTP_ARG_CERT "-NHTTPcert"
@@ -98,71 +102,11 @@
#define URL_DEFAULT_PORT_HTTPS 81
#define URL_DEFAULT_PORT_FTP 120
-/* Success flag */
-#define H_OK 0
-
-/* File errors */
-#define FILE_ERROR_OPEN 8000
-#define FILE_ERROR_READ 8001
-
-/* Socket errors */
-#define HSOCKET_ERROR_CREATE 1001
-#define HSOCKET_ERROR_GET_HOSTNAME 1002
-#define HSOCKET_ERROR_CONNECT 1003
-#define HSOCKET_ERROR_SEND 1004
-#define HSOCKET_ERROR_RECEIVE 1005
-#define HSOCKET_ERROR_BIND 1006
-#define HSOCKET_ERROR_LISTEN 1007
-#define HSOCKET_ERROR_ACCEPT 1008
-#define HSOCKET_ERROR_NOT_INITIALIZED 1009
-#define HSOCKET_ERROR_IOCTL 1010
-#define HSOCKET_ERROR_SSLCLOSE 1011
-#define HSOCKET_ERROR_SSLCTX 1011
-
-/* URL errors */
-#define URL_ERROR_UNKNOWN_PROTOCOL 1101
-#define URL_ERROR_NO_PROTOCOL 1102
-#define URL_ERROR_NO_HOST 1103
-
-/* Stream errors */
-#define STREAM_ERROR_INVALID_TYPE 1201
-#define STREAM_ERROR_SOCKET_ERROR 1202
-#define STREAM_ERROR_NO_CHUNK_SIZE 1203
-#define STREAM_ERROR_WRONG_CHUNK_SIZE 1204
-
-
-/* MIME errors */
-#define MIME_ERROR_NO_BOUNDARY_PARAM 1301
-#define MIME_ERROR_NO_START_PARAM 1302
-#define MIME_ERROR_PARSE_ERROR 1303
-#define MIME_ERROR_NO_ROOT_PART 1304
-#define MIME_ERROR_NOT_MIME_MESSAGE 1305
-
-
-/* General errors */
-#define GENERAL_INVALID_PARAM 1400
-#define GENERAL_HEADER_PARSE_ERROR 1401
-
-/* Thread errors */
-#define THREAD_BEGIN_ERROR 1500
-
-/* XML Errors */
-#define XML_ERROR_EMPTY_DOCUMENT 1600
-#define XML_ERROR_PARSE 1601
-
-/* SSL Errors */
-#define HSSL_ERROR_CA_LIST 1710
-#define HSSL_ERROR_CONTEXT 1720
-#define HSSL_ERROR_CERTIFICATE 1730
-#define HSSL_ERROR_PEM 1740
-#define HSSL_ERROR_CLIENT 1750
-#define HSSL_ERROR_SERVER 1760
-#define HSSL_ERROR_CONNECT 1770
-
/**
- Indicates the version of the
- used HTTP protocol.
-*/
+ *
+ * Indicates the version of the used HTTP protocol.
+ *
+ */
typedef enum _http_version
{
HTTP_1_0,
@@ -171,37 +115,124 @@ typedef enum _http_version
/**
- Indicates the used method
-*/
+ *
+ * The set of common methods for HTTP/1.1 is defined below. Although this set
+ * can be expanded, additional methods cannot be assumed to share the same
+ * semantics for separately extended clients and servers.
+ *
+ * The Host request-header field MUST accompany all HTTP/1.1 requests.
+ *
+ * @see HTTP_HEADER_HOST
+ *
+ */
typedef enum _hreq_method
{
- HTTP_REQUEST_POST,
+ /**
+ *
+ * The POST method is used to request that the origin server accept the entity
+ * enclosed in the request as a new subordinate of the resource identified by
+ * the Request-URI in the Request-Line. POST is designed to allow a uniform
+ * method to cover the following functions:
+ * - Annotation of existing resources;
+ * - Posting a message to a bulletin board, newsgroup, mailing list, or
+ * similar group of articles;
+ * - Providing a block of data, such as the result of submitting a form, to a
+ * data-handling process;
+ * - Extending a database through an append operation.
+ *
+ */
+ HTTP_REQUEST_POST,
+ /**
+ *
+ * The GET method means retrieve whatever information (in the form of an entity)
+ * is identified by the Request-URI. If the Request-URI refers to a
+ * data-producing process, it is the produced data which shall be returned as
+ * the entity in the response and not the source text of the process, unless
+ * that text happens to be the output of the process.
+ *
+ */
HTTP_REQUEST_GET,
+ /**
+ *
+ * The OPTIONS method represents a request for information about the
+ * communication options available on the request/response chain identified by
+ * the Request-URI. This method allows the client to determine the options
+ * and/or requirements associated with a resource, or the capabilities of a
+ * server, without implying a resource action or initiating a resource
+ * retrieval.
+ *
+ */
HTTP_REQUEST_OPTIONS,
+ /**
+ *
+ * The HEAD method is identical to GET except that the server MUST NOT return
+ * a message-body in the response. The metainformation contained in the HTTP
+ * headers in response to a HEAD request SHOULD be identical to the information
+ * sent in response to a GET request. This method can be used for obtaining
+ * metainformation about the entity implied by the request without transferring
+ * the entity-body itself. This method is often used for testing hypertext
+ * links for validity, accessibility, and recent modification.
+ *
+ */
HTTP_REQUEST_HEAD,
+ /**
+ *
+ * The PUT method requests that the enclosed entity be stored under the
+ * supplied Request-URI. If the Request-URI refers to an already existing
+ * resource, the enclosed entity SHOULD be considered as a modified version of
+ * the one residing on the origin server. If the Request-URI does not point to
+ * an existing resource, and that URI is capable of being defined as a new
+ * resource by the requesting user agent, the origin server can create the
+ * resource with that URI. If a new resource is created, the origin server MUST
+ * inform the user agent via the 201 (Created) response. If an existing
+ * resource is modified, either the 200 (OK) or 204 (No Content) response codes
+ * SHOULD be sent to indicate successful completion of the request. If the
+ * resource could not be created or modified with the Request-URI, an
+ * appropriate error response SHOULD be given that reflects the nature of the
+ * problem. The recipient of the entity MUST NOT ignore any Content-* (e.g.
+ * Content-Range) headers that it does not understand or implement and MUST
+ * return a 501 (Not Implemented) response in such cases.
+ *
+ */
HTTP_REQUEST_PUT,
+ /**
+ *
+ * The DELETE method requests that the origin server delete the resource
+ * identified by the Request-URI. This method MAY be overridden by human
+ * intervention (or other means) on the origin server. The client cannot be
+ * guaranteed that the operation has been carried out, even if the status code
+ * returned from the origin server indicates that the action has been completed
+ * successfully. However, the server SHOULD NOT indicate success unless, at the
+ * time the response is given, it intends to delete the resource or move it to
+ * an inaccessible location.
+ *
+ */
HTTP_REQUEST_DELETE,
+ /**
+ *
+ * The TRACE method is used to invoke a remote, application-layer loop-back of
+ * the request message. The final recipient of the request SHOULD reflect the
+ * message received back to the client as the entity-body of a 200 (OK)
+ * response. The final recipient is either the origin server or the first proxy
+ * or gateway to receive a Max-Forwards value of zero (0) in the request (see
+ * section 14.31). A TRACE request MUST NOT include an entity.
+ *
+ */
HTTP_REQUEST_TRACE,
+ /**
+ *
+ * This specification reserves the method name CONNECT for use with a proxy
+ * that can dynamically switch to being a tunnel (e.g. SSL tunneling [44]).
+ *
+ */
HTTP_REQUEST_CONNECT,
HTTP_REQUEST_UNKOWN
} hreq_method_t;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef void *herror_t;
-
-herror_t herror_new(const char *func, int errcode, const char *format, ...);
-int herror_code(herror_t err);
-char *herror_func(herror_t err);
-char *herror_message(herror_t err);
-void herror_release(herror_t err);
-
-/*
- hpairnode_t represents a pair (key, value) pair.
- This is also a linked list.
+/**
+ *
+ * hpairnode_t represents a pair (key, value) pair. This is also a linked list.
+ *
*/
typedef struct hpair hpair_t;
struct hpair
@@ -211,122 +242,134 @@ struct hpair
hpair_t *next;
};
+#ifdef __cplusplus
+extern "C" {
+#endif
/**
- Creates a new pair with the given parameters. Both strings
- key and value will be cloned while creating the pair.
-
- @param key the key of the (key,value) pair
- @param value the value of the (key,value) pair
- @param next next pair node in the linked list
-
- @returns A newly crated hpair_t object. Use hpair_free()
- or hpair_free_deep() to free the pair.
-*/
-hpair_t *hpairnode_new(const char *key, const char *value, hpair_t * next);
-
+ *
+ * Creates a new pair with the given parameters. Both strings key and value will
+ * be cloned while creating the pair.
+ *
+ * @param key the key of the (key,value) pair
+ * @param value the value of the (key,value) pair
+ * @param next next pair node in the linked list
+ *
+ * @returns A newly crated hpair_t object. Use hpair_free() or hpair_free_deep()
+ * to free the pair.
+ *
+ */
+extern hpair_t *hpairnode_new(const char *key, const char *value, hpair_t * next);
/**
- Creates a new pair from a given string. This function
- will split 'str' with the found first delimiter 'delim'.
- The 'value' field of the newly created pair will have
- the value "", if no delimiter was found/
- Whitespaces (' ') will be removed from the beginnig of
- the parsed value.
-
- @param str A string to parse
- @param delim a delimiter to use while splitting into key,value
- @param next next pair node in the linked list
-
- @returns A newly crated hpair_t object. Use hpair_free()
- or hpair_free_deep() to free the pair.
-*/
-hpair_t *hpairnode_parse(const char *str, const char *delim, hpair_t * next);
-
+ *
+ * Creates a new pair from a given string. This function will split 'str' with
+ * the found first delimiter 'delim'. The 'value' field of the newly created
+ * pair will have the value "", if no delimiter was found/ Whitespaces (' ') will
+ * be removed from the beginnig of the parsed value.
+ *
+ * @param str A string to parse
+ * @param delim a delimiter to use while splitting into key,value
+ * @param next next pair node in the linked list
+ *
+ * @returns A newly crated hpair_t object. Use hpair_free() or hpair_free_deep()
+ * to free the pair.
+ *
+ */
+extern hpair_t *hpairnode_parse(const char *str, const char *delim, hpair_t * next);
/**
- Frees a given pair.
-
- @param pair the pair to free
-*/
-void hpairnode_free(hpair_t * pair);
-
+ *
+ * Frees a given pair.
+ *
+ * @param pair the pair to free
+ *
+ */
+extern void hpairnode_free(hpair_t * pair);
/**
- Makes a deep free operation. All pairnodes,
- beginning with the given pari, in the
- linked list will be destroyed.
-
- @param pair the pair to start to free the linked list
-*/
-void hpairnode_free_deep(hpair_t * pair);
-
+ *
+ * Makes a deep free operation. All pairnodes, beginning with the given pari, in
+ * the linked list will be destroyed.
+ *
+ * @param pair the pair to start to free the linked list
+ *
+ */
+extern void hpairnode_free_deep(hpair_t * pair);
/**
- Returns the (key,value) pair, which key is the
- given 'key'.
-
- @param pair the first pair to start to search from.
- @param key key to find the in the pair.
- @returns if a value will be found, this function will
- return the value (do not free this string) or NULL
- if no pair was found with the key 'key'.
-*/
-char *hpairnode_get(hpair_t * pair, const char *key);
-
+ *
+ * Returns the (key,value) pair, which key is the given 'key'.
+ *
+ * @param pair the first pair to start to search from.
+ * @param key key to find the in the pair.
+ * @returns if a value will be found, this function will
+ *
+ * @return the value (do not free this string) or NULL if no pair was found with
+ * the key 'key'.
+ *
+ */
+extern char *hpairnode_get(hpair_t * pair, const char *key);
/**
- Returns the (key,value) pair, which key is the
- given 'key'. The case will be ignored while
- comparing the key strings.
-
- @param pair the first pair to start to search from.
- @param key key to find the in the pair.
- @returns if a value will be found, this function will
- return the value (do not free this string) or NULL
- if no pair was found with the key 'key'.
-*/
-char *hpairnode_get_ignore_case(hpair_t * pair, const char *key);
-
+ *
+ * Returns the (key,value) pair, which key is the given 'key'. The case will be
+ * ignored while comparing the key strings.
+ *
+ * @param pair the first pair to start to search from.
+ * @param key key to find the in the pair.
+ * @returns if a value will be found, this function will
+ *
+ * @return the value (do not free this string) or NULL if no pair was found with
+ * the key 'key'.
+ *
+ */
+extern char *hpairnode_get_ignore_case(hpair_t * pair, const char *key);
/**
- This function will create a new pair and fills the
- (key,value) fields of a given pair. Note that the 'next'
- field will not be copied.
-
- @param src the source pair object to copy.
-
- @returns a newly created pair with the same (key,value)
- pairs as in 'src'. This fields will be cloned. The'next'
- field will be set to NULL.
-
- @see hpairnode_copy_deep
-*/
-hpair_t *hpairnode_copy(const hpair_t * src);
-
+ *
+ * This function will create a new pair and fills the (key,value) fields of a
+ * given pair. Note that the 'next' field will not be copied.
+ *
+ * @param src the source pair object to copy.
+ *
+ * @returns a newly created pair with the same (key,value) pairs as in 'src'.
+ * This fields will be cloned. The'next' field will be set to NULL.
+ *
+ * @see hpairnode_copy_deep
+ *
+ */
+extern hpair_t *hpairnode_copy(const hpair_t * src);
/**
- Clones the hole linked list.
-
- @param src the source pair object to copy from
-
- @returns the first object in the linked list.
-
- @see hpairnode_copy
-*/
-hpair_t *hpairnode_copy_deep(const hpair_t * src);
-
-/* Debug functions */
-void hpairnode_dump_deep(hpair_t * pair);
-void hpairnode_dump(hpair_t * pair);
+ *
+ * Clones the hole linked list.
+ *
+ * @param src the source pair object to copy from
+ *
+ * @return the first object in the linked list.
+ *
+ * @see hpairnode_copy
+ *
+ */
+extern hpair_t *hpairnode_copy_deep(const hpair_t * src);
/**
- The protocol types in enumeration
- format. Used in some other nanohttp objects
- like hurl_t.
+ *
+ * Debug functions
+ *
+ */
+extern void hpairnode_dump_deep(hpair_t * pair);
+extern void hpairnode_dump(hpair_t * pair);
- @see hurl_t
-*/
+/**
+ *
+ * The protocol types in enumeration format. Used in some other nanohttp objects
+ * like hurl_t.
+ *
+ * @see hurl_t
+ *
+ */
typedef enum _hprotocol
{
PROTOCOL_HTTP,
@@ -337,12 +380,14 @@ typedef enum _hprotocol
/**
- The URL object. A representation
- of an URL like:<P>
-
- [protocol]://[host]:[port]/[context]
-
-*/
+ *
+ * The URL object. A representation of an URL like:
+ *
+ * [protocol]://[host]:[port]/[context]
+ *
+ * @see http://www.ietf.org/rfc/rfc2396.txt
+ *
+ */
typedef struct _hurl
{
/**
@@ -367,62 +412,64 @@ typedef struct _hurl
char context[URL_MAX_CONTEXT_SIZE];
} hurl_t;
+/**
+ *
+ * Parses the given 'urlstr' and fills the given hurl_t object.
+ *
+ * @param obj the destination URL object to fill
+ * @param url the URL in string format
+ *
+ * @returns H_OK on success or one of the following otherwise
+ * - URL_ERROR_UNKNOWN_PROTOCOL
+ * - URL_ERROR_NO_PROTOCOL
+ * - URL_ERROR_NO_HOST
+ *
+ */
+extern herror_t hurl_parse(hurl_t * obj, const char *url);
/**
- Parses the given 'urlstr' and fills the given hurl_t object.
-
- @param obj the destination URL object to fill
- @param url the URL in string format
-
- @returns H_OK on success or one of the following otherwise
-
- URL_ERROR_UNKNOWN_PROTOCOL
- URL_ERROR_NO_PROTOCOL
- URL_ERROR_NO_HOST
-*/
-herror_t hurl_parse(hurl_t * obj, const char *url);
-
-/*
- Object representation of the content-type field
- in a HTTP header:
- <P>
- Example:<P>
-
- text/xml; key="value" key2="value2' ...
-*/
+ *
+ * Object representation of the content-type field in a HTTP header:
+ *
+ * Example:
+ *
+ * text/xml; key="value" key2="value2' ...
+ *
+ */
typedef struct _content_type
{
char type[128];
hpair_t *params;
} content_type_t;
-
/**
- Parses the given string and creates a new ccontent_type_t
- object.
-
- @param content_type_str the string representation of the
- content-type field in a HTTP header.
-
- @returns A newly created content_type_t object. Free this
- object with content_type_free();
-
- @see content_type_free
-*/
-content_type_t *content_type_new(const char *content_type_str);
+ *
+ * Parses the given string and creates a new ccontent_type_t object.
+ *
+ * @param content_type_str the string representation of the content-type field in
+ * a HTTP header.
+ *
+ * @returns A newly created content_type_t object. Free this object with
+ * content_type_free();
+ *
+ * @see content_type_free
+ */
+extern content_type_t *content_type_new(const char *content_type_str);
/**
- Frees the given content_type_t object
-*/
-void content_type_free(content_type_t * ct);
-
-
+ *
+ * Frees the given content_type_t object
+ *
+ */
+extern void content_type_free(content_type_t * ct);
-/*
- part. Attachment
-*/
-typedef struct _part
+/**
+ *
+ * part. Attachment
+ *
+ */
+struct part_t
{
char id[250];
char location[250];
@@ -430,39 +477,38 @@ typedef struct _part
char content_type[128];
char transfer_encoding[128];
char filename[250];
- struct _part *next;
+ struct part_t *next;
int deleteOnExit; /* default is 0 */
-} part_t;
-
-
-part_t *part_new(const char *id, const char *filename,
- const char *content_type, const char *transfer_encoding,
- part_t * next);
-void part_free(part_t * part);
-
+};
+extern struct part_t *part_new(const char *id, const char *filename, const char *content_type, const char *transfer_encoding, struct part_t * next);
+extern void part_free(struct part_t * part);
-/*
- Attachments
-*/
-typedef struct _attachments
+/**
+ *
+ * Attachments
+ *
+ */
+struct attachments_t
{
- part_t *parts;
- part_t *last;
- part_t *root_part;
-} attachments_t;
-
-attachments_t *attachments_new(void); /* should be used internally */
+ struct part_t *parts;
+ struct part_t *last;
+ struct part_t *root_part;
+};
-/*
- Free a attachment. Create attachments with MIME
- and DIME (DIME is not supported yet).
+extern struct attachments_t *attachments_new(void); /* should be used internally */
- @see mime_get_attachments
-*/
-void attachments_free(attachments_t * message);
-void attachments_add_part(attachments_t * attachments, part_t * part);
+/**
+ *
+ * Free a attachment. Create attachments with MIME and DIME (DIME is not
+ * supported yet).
+ *
+ * @see mime_get_attachments
+ *
+ */
+extern void attachments_free(struct attachments_t * message);
+extern void attachments_add_part(struct attachments_t * attachments, struct part_t * part);
#ifdef __cplusplus
}
diff --git a/nanohttp/nanohttp-error.h b/nanohttp/nanohttp-error.h
new file mode 100644
index 0000000..57b6634
--- /dev/null
+++ b/nanohttp/nanohttp-error.h
@@ -0,0 +1,102 @@
+/******************************************************************
+ * $Id: nanohttp-error.h,v 1.1 2006/11/25 15:06:58 m0gg Exp $
+ *
+ * CSOAP Project: A http client/server library in C
+ * Copyright (C) 2003-2004 Ferhat Ayaz
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Email: ferhatayaz@yahoo.com
+ ******************************************************************/
+#ifndef __nanohttp_error_h
+#define __nanohttp_error_h
+
+/* Success flag */
+#define H_OK 0
+
+/* Socket errors */
+#define HSOCKET_ERROR_CREATE 1001
+#define HSOCKET_ERROR_GET_HOSTNAME 1002
+#define HSOCKET_ERROR_CONNECT 1003
+#define HSOCKET_ERROR_SEND 1004
+#define HSOCKET_ERROR_RECEIVE 1005
+#define HSOCKET_ERROR_BIND 1006
+#define HSOCKET_ERROR_LISTEN 1007
+#define HSOCKET_ERROR_ACCEPT 1008
+#define HSOCKET_ERROR_NOT_INITIALIZED 1009
+#define HSOCKET_ERROR_IOCTL 1010
+#define HSOCKET_ERROR_SSLCLOSE 1011
+#define HSOCKET_ERROR_SSLCTX 1011
+
+/* URL errors */
+#define URL_ERROR_UNKNOWN_PROTOCOL 1101
+#define URL_ERROR_NO_PROTOCOL 1102
+#define URL_ERROR_NO_HOST 1103
+
+/* Stream errors */
+#define STREAM_ERROR_INVALID_TYPE 1201
+#define STREAM_ERROR_SOCKET_ERROR 1202
+#define STREAM_ERROR_NO_CHUNK_SIZE 1203
+#define STREAM_ERROR_WRONG_CHUNK_SIZE 1204
+
+/* MIME errors */
+#define MIME_ERROR_NO_BOUNDARY_PARAM 1301
+#define MIME_ERROR_NO_START_PARAM 1302
+#define MIME_ERROR_PARSE_ERROR 1303
+#define MIME_ERROR_NO_ROOT_PART 1304
+#define MIME_ERROR_NOT_MIME_MESSAGE 1305
+
+/* General errors */
+#define GENERAL_INVALID_PARAM 1400
+#define GENERAL_HEADER_PARSE_ERROR 1401
+
+/* Thread errors */
+#define THREAD_BEGIN_ERROR 1500
+
+/* XML Errors */
+#define XML_ERROR_EMPTY_DOCUMENT 1600
+#define XML_ERROR_PARSE 1601
+
+/* SSL Errors */
+#define HSSL_ERROR_CA_LIST 1710
+#define HSSL_ERROR_CONTEXT 1720
+#define HSSL_ERROR_CERTIFICATE 1730
+#define HSSL_ERROR_PEM 1740
+#define HSSL_ERROR_CLIENT 1750
+#define HSSL_ERROR_SERVER 1760
+#define HSSL_ERROR_CONNECT 1770
+
+/* File errors */
+#define FILE_ERROR_OPEN 8000
+#define FILE_ERROR_READ 8001
+
+typedef void *herror_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern herror_t herror_new(const char *func, int errcode, const char *format, ...);
+extern int herror_code(herror_t err);
+extern char *herror_func(herror_t err);
+extern char *herror_message(herror_t err);
+extern void herror_release(herror_t err);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/nanohttp/nanohttp-mime.c b/nanohttp/nanohttp-mime.c
index 1736e3b..05694c6 100755
--- a/nanohttp/nanohttp-mime.c
+++ b/nanohttp/nanohttp-mime.c
@@ -3,7 +3,7 @@
* | \/ | | | | \/ | | _/
* |_''_| |_| |_''_| |_'/ PARSER
*
-* $Id: nanohttp-mime.c,v 1.16 2006/11/23 15:27:33 m0gg Exp $
+* $Id: nanohttp-mime.c,v 1.17 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -41,6 +41,10 @@
#include <string.h>
#endif
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
@@ -49,11 +53,12 @@
Buffered Reader. A helper object to read bytes from a source
----------------------------------------------------------------*/
+#include "nanohttp-logging.h"
+#include "nanohttp-error.h"
#include "nanohttp-common.h"
#include "nanohttp-socket.h"
#include "nanohttp-stream.h"
#include "nanohttp-mime.h"
-#include "nanohttp-logging.h"
/* ------------------------------------------------------------------
@@ -475,9 +480,6 @@ MIME_parse(MIME_read_function reader_function,
} /* while (1) */
}
-
-
-
MIME_read_status
MIME_filereader_function(void *userdata, unsigned char *dest, int *size)
{
@@ -501,8 +503,8 @@ MIME_filereader_function(void *userdata, unsigned char *dest, int *size)
typedef struct _mime_callback_data
{
int part_id;
- attachments_t *message;
- part_t *current_part;
+ struct attachments_t *message;
+ struct part_t *current_part;
int buffer_capacity;
char header[4064];
char root_id[256];
@@ -513,7 +515,6 @@ typedef struct _mime_callback_data
} mime_callback_data_t;
-
MIME_read_status
mime_streamreader_function(void *userdata, unsigned char *dest, int *size)
{
@@ -568,11 +569,16 @@ static void
_mime_part_begin(void *data)
{
char buffer[1054];
- mime_callback_data_t *cbdata = (mime_callback_data_t *) data;
- part_t *part;
-
+ struct part_t *part;
+ mime_callback_data_t *cbdata;
+
+ cbdata = (mime_callback_data_t *) data;
log_verbose2("Begin Part (%p)", data);
- part = (part_t *) malloc(sizeof(part_t));
+ if (!(part = (struct part_t *) malloc(sizeof(struct part_t))))
+ {
+ log_error2("malloc failed (%s)", strerror(errno));
+ return;
+ }
part->next = NULL;
@@ -798,16 +804,21 @@ _mime_received_bytes(void *data, const unsigned char *bytes, int size)
The mime message parser
*/
-attachments_t *
+struct attachments_t *
mime_message_parse(struct http_input_stream_t * in, const char *root_id,
const char *boundary, const char *dest_dir)
{
MIME_parser_status status;
MIME_callbacks callbacks;
- attachments_t *message;
+ struct attachments_t *message;
- mime_callback_data_t *cbdata = (mime_callback_data_t *)
- malloc(sizeof(mime_callback_data_t));
+ mime_callback_data_t *cbdata;
+
+ if (!(cbdata = (mime_callback_data_t *) malloc(sizeof(mime_callback_data_t))))
+ {
+ log_error2("malloc failed (%s)", strerror(errno));
+ return NULL;
+ }
cbdata->part_id = 100;
cbdata->buffer_capacity = 0;
@@ -817,7 +828,13 @@ mime_message_parse(struct http_input_stream_t * in, const char *root_id,
cbdata->header_search = 0;
strcpy(cbdata->root_id, root_id);
strcpy(cbdata->root_dir, dest_dir);
- message = (attachments_t *) malloc(sizeof(attachments_t));
+
+ if (!(message = (struct attachments_t *) malloc(sizeof(struct attachments_t))))
+ {
+ log_error2("malloc failed (%s)", strerror(errno));
+ free(cbdata);
+ return NULL;
+ }
cbdata->message = message;
cbdata->message->parts = NULL;
cbdata->message->root_part = NULL;
@@ -845,16 +862,21 @@ mime_message_parse(struct http_input_stream_t * in, const char *root_id,
}
}
-attachments_t *
+struct attachments_t *
mime_message_parse_from_file(FILE * in, const char *root_id,
const char *boundary, const char *dest_dir)
{
MIME_parser_status status;
MIME_callbacks callbacks;
- attachments_t *message;
+ struct attachments_t *message;
- mime_callback_data_t *cbdata = (mime_callback_data_t *)
- malloc(sizeof(mime_callback_data_t));
+ mime_callback_data_t *cbdata;
+
+ if (!(cbdata = (mime_callback_data_t *) malloc(sizeof(mime_callback_data_t))))
+ {
+ log_error2("malloc failed (%s)", strerror(errno));
+ return NULL;
+ }
cbdata->part_id = 100;
cbdata->buffer_capacity = 0;
@@ -864,7 +886,14 @@ mime_message_parse_from_file(FILE * in, const char *root_id,
cbdata->header_search = 0;
strcpy(cbdata->root_id, root_id);
strcpy(cbdata->root_dir, dest_dir);
- message = (attachments_t *) malloc(sizeof(attachments_t));
+
+ if (!(message = (struct attachments_t *) malloc(sizeof(struct attachments_t))))
+ {
+ log_error2("malloc failed (%s)", strerror(errno));
+ free(cbdata);
+ return NULL;
+ }
+
cbdata->message = message;
cbdata->message->parts = NULL;
cbdata->message->root_part = NULL;
@@ -897,11 +926,11 @@ mime_message_parse_from_file(FILE * in, const char *root_id,
herror_t
mime_get_attachments(content_type_t * ctype, struct http_input_stream_t * in,
- attachments_t ** dest)
+ struct attachments_t ** dest)
{
/* MIME variables */
- attachments_t *mimeMessage;
- part_t *part, *tmp_part = NULL;
+ struct attachments_t *mimeMessage;
+ struct part_t *part, *tmp_part = NULL;
char *boundary, *root_id;
/* Check for MIME message */
diff --git a/nanohttp/nanohttp-mime.h b/nanohttp/nanohttp-mime.h
index 655c7e2..d6ce17d 100755
--- a/nanohttp/nanohttp-mime.h
+++ b/nanohttp/nanohttp-mime.h
@@ -3,7 +3,7 @@
* | \/ | | | | \/ | | _/
* |_''_| |_| |_''_| |_'/ PARSER
*
-* $Id: nanohttp-mime.h,v 1.10 2006/11/23 15:27:33 m0gg Exp $
+* $Id: nanohttp-mime.h,v 1.11 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -37,7 +37,7 @@ extern "C" {
"multipart/related" MIME Message Builder
------------------------------------------------------------------*/
-extern herror_t mime_get_attachments(content_type_t * ctype, struct http_input_stream_t * in, attachments_t ** dest);
+extern herror_t mime_get_attachments(content_type_t * ctype, struct http_input_stream_t * in, struct attachments_t ** dest);
#ifdef __cplusplus
}
diff --git a/nanohttp/nanohttp-request.c b/nanohttp/nanohttp-request.c
index 0fd1d7e..4572e2c 100755
--- a/nanohttp/nanohttp-request.c
+++ b/nanohttp/nanohttp-request.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-request.c,v 1.18 2006/11/23 15:27:33 m0gg Exp $
+* $Id: nanohttp-request.c,v 1.19 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -50,6 +50,7 @@
#endif
#include "nanohttp-logging.h"
+#include "nanohttp-error.h"
#include "nanohttp-common.h"
#include "nanohttp-socket.h"
#include "nanohttp-stream.h"
@@ -275,7 +276,7 @@ hrequest_new_from_socket(struct hsocket_t *sock, struct hrequest_t ** out)
herror_t status;
struct hrequest_t *req;
char buffer[MAX_HEADER_SIZE + 1];
- attachments_t *mimeMessage;
+ struct attachments_t *mimeMessage;
memset(buffer, 0, MAX_HEADER_SIZE);
/* Read header */
diff --git a/nanohttp/nanohttp-request.h b/nanohttp/nanohttp-request.h
index 2234e99..d1d599b 100755
--- a/nanohttp/nanohttp-request.h
+++ b/nanohttp/nanohttp-request.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-request.h,v 1.10 2006/11/23 15:27:33 m0gg Exp $
+ * $Id: nanohttp-request.h,v 1.11 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -31,27 +31,226 @@
* The request-header fields allow the client to pass additional information
* about the request, and about the client itself, to the server. These fields
* act as request modifiers, with semantics equivalent to the parameters on a
- * programming language method invocation (see RFC2616).
+ * programming language method invocation.
+ *
+ * @see http://www.ietf.org/rfc/rfc2616.txt
+ *
+ */
+
+/**
+ *
+ * The Accept request-header field can be used to specify certain media types
+ * which are acceptable for the response. Accept headers can be used to indicate
+ * that the request is specifically limited to a small set of desired types, as
+ * in the case of a request for an in-line image.
*
*/
#define HEADER_ACCEPT "Accept"
-#define HEADER_CHARSET "Accept-Charset"
+
+/**
+ *
+ * The Accept-Charset request-header field can be used to indicate what character
+ * sets are acceptable for the response. This field allows clients capable of
+ * understanding more comprehensive or special-purpose character sets to signal
+ * that capability to a server which is capable of representing documents in
+ * those character sets.
+ *
+ */
+#define HEADER_ACCEPT_CHARSET "Accept-Charset"
+
+/**
+ *
+ * The Accept-Encoding request-header field is similar to Accept, but restricts
+ * the content-codings (section 3.5) that are acceptable in the response.
+ *
+ */
#define HEADER_ACCEPT_ENCODING "Accept-Encoding"
+
+/**
+ *
+ * The Accept-Language request-header field is similar to Accept, but restricts
+ * the set of natural languages that are preferred as a response to the request.
+ *
+ */
#define HEADER_ACCEPT_LANGUAGE "Accept-Language"
+
+/**
+ *
+ * A user agent that wishes to authenticate itself with a server -- usually, but
+ * not necessarily, after receiving a 401 response -- does so by including an
+ * Authorization request-header field with the request. The Authorization field
+ * value consists of credentials containing the authentication information of the
+ * user agent for the realm of the resource being requested.
+ *
+ */
#define HEADER_AUTHORIZATION "Authorization"
+
+/**
+ *
+ * The Expect request-header field is used to indicate that particular server
+ * behaviors are required by the client.
+ *
+ */
#define HEADER_EXPECT "Expect"
+
+/**
+ *
+ * The From request-header field, if given, SHOULD contain an Internet e-mail
+ * address for the human user who controls the requesting user agent. The
+ * address SHOULD be machine-usable, as defined by "mailbox" in RFC 822 as
+ * updated by RFC 1123.
+ *
+ * @see http://www.ietf.org/rfc/rfc1123.txt,
+ * http://www.ietf.org/rfc/rfc822.txt
+ *
+ */
#define HEADER_FROM "From"
+
+/**
+ *
+ * The Host request-header field specifies the Internet host and port number of
+ * the resource being requested, as obtained from the original URI given by the
+ * user or referring resource (generally an HTTP URL, as described in section
+ * 3.2.2). The Host field value MUST represent the naming authority of the origin
+ * server or gateway given by the original URL. This allows the origin server or
+ * gateway to differentiate between internally-ambiguous URLs, such as the root
+ * "/" URL of a server for multiple host names on a single IP address.
+ *
+ */
#define HEADER_HOST "Host"
+
+/**
+ *
+ * The If-Match request-header field is used with a method to make it
+ * conditional. A client that has one or more entities previously obtained from
+ * the resource can verify that one of those entities is current by including a
+ * list of their associated entity tags in the If-Match header field. Entity tags
+ * are defined in section 3.11. The purpose of this feature is to allow efficient
+ * updates of cached information with a minimum amount of transaction overhead.
+ * It is also used, on updating requests, to prevent inadvertent modification of
+ * the wrong version of a resource. As a special case, the value "*" matches any
+ * current entity of the resource.
+ *
+ */
#define HEADER_IF_MATCH "If-Match"
+
+/**
+ *
+ * The If-Modified-Since request-header field is used with a method to make it
+ * conditional: if the requested variant has not been modified since the time
+ * specified in this field, an entity will not be returned from the server;
+ * instead, a 304 (not modified) response will be returned without any
+ * message-body.
+ *
+ */
#define HEADER_IF_MODIFIED_SINCE "If-Modified-Since"
+
+/**
+ *
+ * The If-None-Match request-header field is used with a method to make it
+ * conditional. A client that has one or more entities previously obtained from
+ * the resource can verify that none of those entities is current by including a
+ * list of their associated entity tags in the If-None-Match header field. The
+ * purpose of this feature is to allow efficient updates of cached information
+ * with a minimum amount of transaction overhead. It is also used to prevent a
+ * method (e.g. PUT) from inadvertently modifying an existing resource when the
+ * client believes that the resource does not exist.
+ *
+ */
#define HEADER_IF_NONE_MATCH "If-None-Match"
+
+/**
+ *
+ * If a client has a partial copy of an entity in its cache, and wishes to have
+ * an up-to-date copy of the entire entity in its cache, it could use the Range
+ * request-header with a conditional GET (using either or both of
+ * If-Unmodified-Since and If-Match.) However, if the condition fails because the
+ * entity has been modified, the client would then have to make a second request
+ * to obtain the entire current entity-body.
+ *
+ */
#define HEADER_IF_RANGE "If-Range"
+
+/**
+ *
+ * The If-Unmodified-Since request-header field is used with a method to make it
+ * conditional. If the requested resource has not been modified since the time
+ * specified in this field, the server SHOULD perform the requested operation as
+ * if the If-Unmodified-Since header were not present.
+ *
+ */
#define HEADER_IF_UNMODIFIED_SINCE "If-Unmodified-Since"
+
+/**
+ *
+ * The Max-Forwards request-header field provides a mechanism with the TRACE
+ * (section 9.8) and OPTIONS (section 9.2) methods to limit the number of
+ * proxies or gateways that can forward the request to the next inbound server.
+ * This can be useful when the client is attempting to trace a request chain
+ * which appears to be failing or looping in mid-chain.
+ *
+ */
#define HEADER_IF_MAX_FORWARDS "Max-Forwards"
+
+/**
+ *
+ * The Proxy-Authorization request-header field allows the client to identify
+ * itself (or its user) to a proxy which requires authentication. The
+ * Proxy-Authorization field value consists of credentials containing the
+ * authentication information of the user agent for the proxy and/or realm of
+ * the resource being requested.
+ *
+ */
#define HEADER_PROXY_AUTHORIZATION "Proxy-Authorization"
+
+/**
+ *
+ * HTTP retrieval requests using conditional or unconditional GET methods MAY
+ * request one or more sub-ranges of the entity, instead of the entire entity,
+ * using the Range request header, which applies to the entity returned as the
+ * result of the request
+ *
+ */
#define HEADER_RANGE "Range"
+
+/**
+ *
+ * The Referer[sic] request-header field allows the client to specify, for the
+ * server's benefit, the address (URI) of the resource from which the Request-URI
+ * was obtained (the "referrer", although the header field is misspelled.) The
+ * Referer request-header allows a server to generate lists of back-links to
+ * resources for interest, logging, optimized caching, etc. It also allows
+ * obsolete or mistyped links to be traced for maintenance. The Referer field
+ * MUST NOT be sent if the Request-URI was obtained from a source that does not
+ * have its own URI, such as input from the user keyboard.
+ *
+ */
#define HEADER_REFERER "Referer"
+
+/**
+ *
+ * The TE request-header field indicates what extension transfer-codings it is
+ * willing to accept in the response and whether or not it is willing to accept
+ * trailer fields in a chunked transfer-coding. Its value may consist of the
+ * keyword "trailers" and/or a comma-separated list of extension transfer-coding
+ * names with optional accept parameters.
+ *
+ */
#define HEADER_TRANSFER_EXTENSION "TE"
+
+/**
+ *
+ * The User-Agent request-header field contains information about the user agent
+ * originating the request. This is for statistical purposes, the tracing of
+ * protocol violations, and automated recognition of user agents for the sake of
+ * tailoring responses to avoid particular user agent limitations. User agents
+ * SHOULD include this field with requests. The field can contain multiple
+ * product tokens (section 3.8) and comments identifying the agent and any
+ * subproducts which form a significant part of the user agent. By convention,
+ * the product tokens are listed in order of their significance for identifying
+ * the application.
+ *
+ */
#define HEADER_USER_AGENT "User-Agent"
#ifdef __NHTTP_INTERNAL
@@ -63,8 +262,10 @@ struct request_statistics
};
#endif
-/*
- request object
+/**
+ *
+ * HTTP request object
+ *
*/
struct hrequest_t
{
@@ -79,7 +280,7 @@ struct hrequest_t
struct http_input_stream_t *in;
content_type_t *content_type;
- attachments_t *attachments;
+ struct attachments_t *attachments;
char root_part_id[150];
};
@@ -88,8 +289,8 @@ extern "C" {
#endif
#ifdef __NHTTP_INTERNAL
-herror_t hrequest_new_from_socket(struct hsocket_t *sock, struct hrequest_t **out);
-void hrequest_free(struct hrequest_t *req);
+extern herror_t hrequest_new_from_socket(struct hsocket_t *sock, struct hrequest_t **out);
+extern void hrequest_free(struct hrequest_t *req);
#endif
#ifdef __cplusplus
diff --git a/nanohttp/nanohttp-response.c b/nanohttp/nanohttp-response.c
index ad8c4a1..c239eb4 100755
--- a/nanohttp/nanohttp-response.c
+++ b/nanohttp/nanohttp-response.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-response.c,v 1.14 2006/11/23 15:27:33 m0gg Exp $
+* $Id: nanohttp-response.c,v 1.15 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -46,6 +46,7 @@
#endif
#include "nanohttp-logging.h"
+#include "nanohttp-error.h"
#include "nanohttp-common.h"
#include "nanohttp-socket.h"
#include "nanohttp-stream.h"
@@ -57,10 +58,11 @@ hresponse_new(void)
{
hresponse_t *res;
- if (!(res = (hresponse_t *) malloc(sizeof(hresponse_t)))) {
+ if (!(res = (hresponse_t *) malloc(sizeof(hresponse_t))))
+ {
- log_error2("malloc failed (%s)", strerror(errno));
- return NULL;
+ log_error2("malloc failed (%s)", strerror(errno));
+ return NULL;
}
res->version = HTTP_1_1;
@@ -159,7 +161,7 @@ hresponse_new_from_socket(struct hsocket_t *sock, hresponse_t ** out)
int i = 0, count;
herror_t status;
hresponse_t *res;
- attachments_t *mimeMessage;
+ struct attachments_t *mimeMessage;
char buffer[MAX_HEADER_SIZE + 1];
read_header: /* for errorcode: 100 (continue) */
diff --git a/nanohttp/nanohttp-response.h b/nanohttp/nanohttp-response.h
index 553d69f..edc48fc 100755
--- a/nanohttp/nanohttp-response.h
+++ b/nanohttp/nanohttp-response.h
@@ -1,5 +1,5 @@
/******************************************************************
- * $Id: nanohttp-response.h,v 1.9 2006/11/23 15:27:33 m0gg Exp $
+ * $Id: nanohttp-response.h,v 1.10 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -36,17 +36,126 @@
* @see http://www.ietf.org/rfc/rfc2616.txt
*
*/
+
+/**
+ *
+ * The Accept-Ranges response-header field allows the server to indicate its
+ * acceptance of range requests for a resource
+ *
+ */
#define HEADER_ACCEPT_RANGES "Accept-Ranges"
+
+/**
+ *
+ * The Age response-header field conveys the sender's estimate of the amount of
+ * time since the response (or its revalidation) was generated at the origin
+ * server. A cached response is "fresh" if its age does not exceed its freshness
+ * lifetime.
+ *
+ */
#define HEADER_AGE "Age"
+
+/**
+ *
+ * The ETag response-header field provides the current value of the entity tag
+ * for the requested variant. The headers used with entity tags are described in
+ * RFC 2616 sections 14.24, 14.26 and 14.44. The entity tag MAY be used for
+ * comparison with other entities from the same resource
+ *
+ * @see http://www.ietf.org/rfc/rfc/2616.txt
+ *
+ */
#define HEADER_EXTENSION_TAG "ETag"
+
+/**
+ *
+ * The Location response-header field is used to redirect the recipient to a
+ * location other than the Request-URI for completion of the request or
+ * identification of a new resource. For 201 (Created) responses, the Location
+ * is that of the new resource which was created by the request. For 3xx
+ * responses, the location SHOULD indicate the server's preferred URI for
+ * automatic redirection to the resource. The field value consists of a single
+ * absolute URI.
+ *
+ */
#define HEADER_LOCATION "Location"
+
+/**
+ *
+ * The Proxy-Authenticate response-header field MUST be included as part of a
+ * 407 (Proxy Authentication Required) response. The field value consists of a
+ * challenge that indicates the authentication scheme and parameters applicable
+ * to the proxy for this Request-URI.
+ *
+ */
#define HEADER_PROXY_AUTHENTICATE "Proxy-Authenticate"
+
+/**
+ *
+ * The Retry-After response-header field can be used with a 503 (Service
+ * Unavailable) response to indicate how long the service is expected to be
+ * unavailable to the requesting client. This field MAY also be used with any
+ * 3xx (Redirection) response to indicate the minimum time the user-agent is
+ * asked wait before issuing the redirected request. The value of this field
+ * can be either an HTTP-date or an integer number of seconds (in decimal) after
+ * the time of the response.
+ *
+ */
#define HEADER_RETRY_AFTER "Retry-After"
+
+/**
+ *
+ * The Server response-header field contains information about the software used
+ * by the origin server to handle the request. The field can contain multiple
+ * product tokens (section 3.8) and comments identifying the server and any
+ * significant subproducts. The product tokens are listed in order of their
+ * significance for identifying the application.
+ *
+ */
#define HEADER_SERVER "Server"
+
+/**
+ *
+ * The Vary field value indicates the set of request-header fields that fully
+ * determines, while the response is fresh, whether a cache is permitted to use
+ * the response to reply to a subsequent request without revalidation. For
+ * uncacheable or stale responses, the Vary field value advises the user agent
+ * about the criteria that were used to select the representation. A Vary field
+ * value of "*" implies that a cache cannot determine from the request headers of
+ * a subsequent request whether this response is the appropriate representation.
+ * See RFC 2616 section 13.6 for use of the Vary header field by caches.
+ *
+ * @see http://www.ietf.org/rfc/rfc2616.txt
+ *
+ */
#define HEADER_VARY "Vary"
+
+/**
+ *
+ * The WWW-Authenticate response-header field MUST be included in 401
+ * (Unauthorized) response messages. The field value consists of at least one
+ * challenge that indicates the authentication scheme(s) and parameters
+ * applicable to the Request-URI.
+ *
+ * WWW-Authenticate = "WWW-Authenticate" ":" 1#challenge
+ *
+ * The HTTP access authentication process is described in "HTTP Authentication:
+ * Basic and Digest Access Authentication" [43]. User agents are advised to take
+ * special care in parsing the WWW-Authenticate field value as it might contain
+ * more than one challenge, or if more than one WWW-Authenticate header field is
+ * provided, the contents of a challenge itself can contain a comma-separated
+ * list of authentication parameters.
+ *
+ * @see http://www.ietf.org/rfc/rfc2617.txt
+ *
+ */
#define HEADER_WWW_AUTHENTICATE "WWW-Authenticate"
-/* response object */
+/**
+ *
+ * HTTP response object
+ *
+ */
typedef struct hresponse
{
http_version_t version;
@@ -57,7 +166,7 @@ typedef struct hresponse
struct http_input_stream_t *in;
content_type_t *content_type;
- attachments_t *attachments;
+ struct attachments_t *attachments;
char root_part_id[150];
} hresponse_t;
@@ -66,8 +175,8 @@ extern "C" {
#endif
#ifdef __NHTTP_INTERNAL
-herror_t hresponse_new_from_socket(struct hsocket_t *sock, hresponse_t ** out);
-void hresponse_free(hresponse_t * res);
+extern herror_t hresponse_new_from_socket(struct hsocket_t *sock, hresponse_t **out);
+extern void hresponse_free(hresponse_t * res);
#endif
#ifdef __cplusplus
diff --git a/nanohttp/nanohttp-server.c b/nanohttp/nanohttp-server.c
index f9e56fb..e79e448 100644
--- a/nanohttp/nanohttp-server.c
+++ b/nanohttp/nanohttp-server.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-server.c,v 1.66 2006/11/24 10:54:03 m0gg Exp $
+* $Id: nanohttp-server.c,v 1.67 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -78,6 +78,7 @@
#endif
#include "nanohttp-logging.h"
+#include "nanohttp-error.h"
#include "nanohttp-common.h"
#include "nanohttp-socket.h"
#include "nanohttp-stream.h"
diff --git a/nanohttp/nanohttp-socket.c b/nanohttp/nanohttp-socket.c
index 9936379..c5c4b98 100644
--- a/nanohttp/nanohttp-socket.c
+++ b/nanohttp/nanohttp-socket.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-socket.c,v 1.63 2006/11/23 15:27:33 m0gg Exp $
+* $Id: nanohttp-socket.c,v 1.64 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003 Ferhat Ayaz
@@ -79,10 +79,12 @@ typedef int ssize_t;
#endif
+#include "nanohttp-error.h"
+#include "nanohttp-logging.h"
+
#include "nanohttp-common.h"
#include "nanohttp-socket.h"
#include "nanohttp-ssl.h"
-#include "nanohttp-logging.h"
#ifdef WIN32
static void
diff --git a/nanohttp/nanohttp-ssl.c b/nanohttp/nanohttp-ssl.c
index 8dbc948..7967bfb 100644
--- a/nanohttp/nanohttp-ssl.c
+++ b/nanohttp/nanohttp-ssl.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-ssl.c,v 1.30 2006/11/23 15:27:33 m0gg Exp $
+* $Id: nanohttp-ssl.c,v 1.31 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2001-2005 Rochester Institute of Technology
@@ -71,6 +71,7 @@
#endif
#endif
+#include "nanohttp-error.h"
#include "nanohttp-common.h"
#include "nanohttp-socket.h"
#include "nanohttp-logging.h"
diff --git a/nanohttp/nanohttp-stream.c b/nanohttp/nanohttp-stream.c
index 821c279..59888d1 100755
--- a/nanohttp/nanohttp-stream.c
+++ b/nanohttp/nanohttp-stream.c
@@ -1,5 +1,5 @@
/******************************************************************
-* $Id: nanohttp-stream.c,v 1.16 2006/11/24 17:28:07 m0gg Exp $
+* $Id: nanohttp-stream.c,v 1.17 2006/11/25 15:06:58 m0gg Exp $
*
* CSOAP Project: A http client/server library in C
* Copyright (C) 2003-2004 Ferhat Ayaz
@@ -45,9 +45,10 @@
#include <netinet/in.h>
#endif
+#include "nanohttp-logging.h"
+#include "nanohttp-error.h"
#include "nanohttp-common.h"
#include "nanohttp-socket.h"
-#include "nanohttp-logging.h"
#include "nanohttp-stream.h"
/*------------------------------------------------------------