nanohttp-server.h

Go to the documentation of this file.
00001 /******************************************************************
00002  *  $Id: nanohttp-server.h,v 1.38 2007/01/25 10:24:10 m0gg Exp $
00003  *
00004  * CSOAP Project:  A http client/server library in C
00005  * Copyright (C) 2003  Ferhat Ayaz
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Library General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Library General Public
00018  * License along with this library; if not, write to the
00019  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020  * Boston, MA  02111-1307, USA.
00021  * 
00022  * Email: ferhatayaz@yahoo.com
00023  ******************************************************************/
00024 #ifndef __nanohttp_server_h
00025 #define __nanohttp_server_h
00026 
00027 /* XXX: Clean up nanohttp to make this unnecessary */
00028 #ifndef __NHTTP_INTERNAL
00029 #include <nanohttp/nanohttp-error.h>
00030 #include <nanohttp/nanohttp-common.h>
00031 #include <nanohttp/nanohttp-stream.h>
00032 #include <nanohttp/nanohttp-request.h>
00033 #include <nanohttp/nanohttp-response.h>
00034 #include <nanohttp/nanohttp-logging.h>
00035 #endif
00036 
00197 #define NHTTPD_ARG_PORT         "-NHTTPport"
00198 #define NHTTPD_ARG_TERMSIG      "-NHTTPtsig"
00199 #define NHTTPD_ARG_MAXCONN      "-NHTTPmaxconn"
00200 #define NHTTPD_ARG_TIMEOUT      "-NHTTPtimeout"
00201 
00202 typedef struct httpd_conn
00203 {
00204   struct hsocket_t *sock;
00205   char content_type[25];
00206   struct http_output_stream_t *out;
00207   hpair_t *header;
00208 }
00209 httpd_conn_t;
00210 
00216 typedef void (*httpd_service) (httpd_conn_t *conn, struct hrequest_t *req);
00217 
00223 typedef int (*httpd_auth) (struct hrequest_t *req, const char *user, const char *pass);
00224 
00225 #ifdef __NHTTP_INTERNAL
00226 
00231 struct service_statistics
00232 {
00233   unsigned long requests;
00234   unsigned long bytes_transmitted;
00235   unsigned long bytes_received;
00236   struct timeval time;
00237   pthread_rwlock_t lock;
00238 };
00239 #endif
00240 
00247 #define NHTTPD_SERVICE_DOWN     0
00248 
00255 #define NHTTPD_SERVICE_UP       1
00256 
00262 typedef struct tag_hservice
00263 {
00264   char *context;
00265   int status;
00266   httpd_service func;
00267   httpd_auth auth;
00268   struct tag_hservice *next;
00269   struct service_statistics *statistics;
00270 }
00271 hservice_t;
00272 
00273 #ifdef __cplusplus
00274 extern "C"
00275 {
00276 #endif
00277 
00283 extern herror_t httpd_init(int argc, char *argv[]);
00284 
00290 extern void httpd_destroy(void);
00291 
00292 
00293 extern herror_t httpd_run(void);
00294 
00295 extern herror_t httpd_register(const char *context, httpd_service service);
00296 extern herror_t httpd_register_secure(const char *context, httpd_service service, httpd_auth auth);
00297 
00298 extern herror_t httpd_register_default(const char *context, httpd_service service);
00299 extern herror_t httpd_register_default_secure(const char *context, httpd_service service, httpd_auth auth);
00300 
00301 extern short httpd_get_port(void);
00302 extern int httpd_get_timeout(void);
00303 extern void httpd_set_timeout(int secs);
00304 
00305 extern const char *httpd_get_protocol(void);
00306 extern int httpd_get_conncount(void);
00307 
00308 extern hservice_t *httpd_get_services(void);
00309 extern hservice_t *httpd_find_service(const char *name);
00310 
00311 extern int httpd_enable_service(hservice_t *service);
00312 extern int httpd_disable_service(hservice_t *service);
00313 
00314 extern void httpd_response_set_content_type(httpd_conn_t * res, const char *content_type);
00315 
00316 extern herror_t httpd_send_header(httpd_conn_t * res, int code, const char *text);
00317 
00318 extern int httpd_set_header(httpd_conn_t * conn, const char *key, const char *value);
00319 extern void httpd_set_headers(httpd_conn_t * conn, hpair_t * header);
00320 
00321 extern int httpd_add_header(httpd_conn_t * conn, const char *key, const char *value);
00322 extern void httpd_add_headers(httpd_conn_t * conn, const hpair_t * values);
00323 
00336 extern herror_t httpd_mime_send_header(httpd_conn_t * conn, const char *related_start, const char *related_start_info, const char *related_type, int code, const char *text);
00337 
00343 extern herror_t httpd_mime_next(httpd_conn_t * conn, const char *content_id, const char *content_type, const char *transfer_encoding);
00344 
00350 extern herror_t httpd_mime_send_file(httpd_conn_t * conn, const char *content_id, const char *content_type, const char *transfer_encoding, const char *filename);
00351 
00359 extern herror_t httpd_mime_end(httpd_conn_t * conn);
00360 
00368 extern herror_t httpd_send_bad_request(httpd_conn_t *conn, const char *msg);
00369 
00377 extern herror_t httpd_send_unauthorized(httpd_conn_t *conn, const char *realm);
00378 
00386 extern herror_t httpd_send_not_found(httpd_conn_t *conn, const char *msg);
00387 
00395 extern herror_t httpd_send_internal_error(httpd_conn_t * conn, const char *msg);
00396 
00404 extern herror_t httpd_send_not_implemented(httpd_conn_t *conn, const char *msg);
00405 
00406 #ifdef __cplusplus
00407 }
00408 #endif
00409 
00410 #endif

Generated on Thu Jan 25 23:36:03 2007 for csoap by  doxygen 1.4.6