src/server/public/nsapi.h

changeset 385
a1f4cb076d2f
parent 371
ea836c4f7341
child 432
7c9137f9e7f9
equal deleted inserted replaced
210:21274e5950af 385:a1f4cb076d2f
107 #endif /* XP_WIN32 */ 107 #endif /* XP_WIN32 */
108 108
109 /* --- End native platform configuration definitions --- */ 109 /* --- End native platform configuration definitions --- */
110 110
111 /* --- Begin miscellaneous definitions --- */ 111 /* --- Begin miscellaneous definitions --- */
112
113 #define WS_TRUE 1
114 #define WS_FALSE 0
112 115
113 /* Used in some places as a length limit on error messages */ 116 /* Used in some places as a length limit on error messages */
114 #define MAGNUS_ERROR_LEN 1024 117 #define MAGNUS_ERROR_LEN 1024
115 118
116 /* Carriage return and line feed */ 119 /* Carriage return and line feed */
353 #include <sys/file.h> 356 #include <sys/file.h>
354 #include <pthread.h> 357 #include <pthread.h>
355 #ifndef HPUX 358 #ifndef HPUX
356 #include <sys/select.h> 359 #include <sys/select.h>
357 #endif 360 #endif
358 #ifndef BSD
359 #include <alloca.h> /* new */
360 #endif
361 #include <sys/socket.h> 361 #include <sys/socket.h>
362 #include <sys/time.h> 362 #include <sys/time.h>
363 #include <sys/types.h> 363 #include <sys/types.h>
364 #include <sys/uio.h> 364 #include <sys/uio.h>
365 #include <fcntl.h> 365 #include <fcntl.h>
402 402
403 // NOTE: no they are not NSPR PRFileDesc* 403 // NOTE: no they are not NSPR PRFileDesc*
404 // they are VFSFile* 404 // they are VFSFile*
405 // TODO: fix NOTE 405 // TODO: fix NOTE
406 406
407 typedef int WSBool;
407 408
408 #ifndef SYS_FILE_T 409 #ifndef SYS_FILE_T
409 typedef struct VFSFile *SYS_FILE; 410 typedef struct VFSFile *SYS_FILE;
410 #define SYS_FILE_T void * 411 #define SYS_FILE_T void *
411 #endif /* !SYS_FILE_T */ 412 #endif /* !SYS_FILE_T */
688 typedef struct PListStruct_s PListStruct_s; 689 typedef struct PListStruct_s PListStruct_s;
689 typedef struct ACLListHandle ACLListHandle; 690 typedef struct ACLListHandle ACLListHandle;
690 typedef struct VFS VFS; 691 typedef struct VFS VFS;
691 typedef struct VFSContext VFSContext; 692 typedef struct VFSContext VFSContext;
692 693
694 enum WSConfigNodeType {
695 WS_CONFIG_NODE_OBJECT = 0,
696 WS_CONFIG_NODE_DIRECTIVE
697 };
698
699 typedef struct ServerConfiguration ServerConfiguration;
700 typedef struct ConfigNode WSConfigNode;
701 typedef enum WSConfigNodeType WSConfigNodeType;
702
693 #ifndef PR_AF_INET 703 #ifndef PR_AF_INET
694 typedef union PRNetAddr PRNetAddr; 704 typedef union PRNetAddr PRNetAddr;
695 #endif 705 #endif
696 706
697 typedef struct Session Session; 707 typedef struct Session Session;
760 }; 770 };
761 771
762 ////// new 772 ////// new
763 773
764 typedef struct _http_listener HttpListener; 774 typedef struct _http_listener HttpListener;
775
776 typedef struct ResourcePool ResourcePool;
777
778 typedef struct ResourceType ResourceType;
779 typedef struct ResourceData ResourceData;
780
781 typedef void * (*resource_pool_init_func)(pool_handle_t *, const char *, pblock *);
782 typedef void (*resource_pool_destroy_func)(void *);
783 typedef void * (*resource_pool_createresource_func)(void *);
784 typedef void (*resource_pool_freeresource_func)(void *, void *);
785 typedef int (*resource_pool_prepare_func)(void *, void *);
786 typedef int (*resource_pool_finish_func)(void *, void *);
787 typedef void * (*resource_pool_getresourcedata_func)(void *);
788
789 struct ResourceType {
790 void * (*init)(pool_handle_t *, const char *, pblock *);
791 void (*destroy)(void *);
792 void * (*createresource)(void *);
793 void (*freeresource)(void *, void *);
794 int (*prepare)(void *, void *);
795 int (*finish)(void *, void *);
796 void * (*getresourcedata)(void *);
797 };
798
799 struct ResourceData {
800 ResourcePool *resourcepool;
801 void *data;
802 };
803
804 int resourcepool_register_type(const char *type_name, ResourceType *type_info);
765 805
766 ////// 806 //////
767 /* 807 /*
768 * VSInitFunc, VSDestroyFunc, VSDirectiveInitFunc and VSDirectiveDestroyFunc 808 * VSInitFunc, VSDestroyFunc, VSDirectiveInitFunc and VSDirectiveDestroyFunc
769 */ 809 */
1481 1521
1482 1522
1483 NSAPI_PUBLIC void http_format_etag(Session *sn, Request *rq, char *etagp, int etaglen, off_t size, time_t mtime); 1523 NSAPI_PUBLIC void http_format_etag(Session *sn, Request *rq, char *etagp, int etaglen, off_t size, time_t mtime);
1484 NSAPI_PUBLIC int http_check_preconditions(Session *sn, Request *rq, struct tm *mtm, const char *etag); 1524 NSAPI_PUBLIC int http_check_preconditions(Session *sn, Request *rq, struct tm *mtm, const char *etag);
1485 NSAPI_PUBLIC int http_set_finfo(Session *sn, Request *rq, struct stat *finfo); 1525 NSAPI_PUBLIC int http_set_finfo(Session *sn, Request *rq, struct stat *finfo);
1526 NSAPI_PUBLIC int http_set_finfo_etag(Session *sn, Request *rq, struct stat *finfo, const char *etag);
1486 1527
1487 NSAPI_PUBLIC char **http_hdrs2env(pblock *pb); 1528 NSAPI_PUBLIC char **http_hdrs2env(pblock *pb);
1488 1529
1489 // new websocket API begin 1530 // new websocket API begin
1490 1531
1566 1607
1567 void nsapi_function_return(Session *sn, Request *rq, int ret); 1608 void nsapi_function_return(Session *sn, Request *rq, int ret);
1568 1609
1569 // threadpool 1610 // threadpool
1570 threadpool_t* threadpool_new(int min, int max); 1611 threadpool_t* threadpool_new(int min, int max);
1612 int threadpool_start(threadpool_t *pool);
1571 void* threadpool_func(void *data); 1613 void* threadpool_func(void *data);
1572 threadpool_job* threadpool_get_job(threadpool_t *pool); 1614 threadpool_job* threadpool_get_job(threadpool_t *pool);
1573 void threadpool_run(threadpool_t *pool, job_callback_f func, void *data); 1615 void threadpool_run(threadpool_t *pool, job_callback_f func, void *data);
1574 1616
1575 int event_pollin(EventHandler *ev, SYS_NETFD fd, Event *event); 1617 int event_pollin(EventHandler *ev, SYS_NETFD fd, Event *event);
1576 int event_pollout(EventHandler *ev, SYS_NETFD fd, Event *event); 1618 int event_pollout(EventHandler *ev, SYS_NETFD fd, Event *event);
1577 int event_removepoll(EventHandler *ev, SYS_NETFD fd); 1619 int event_removepoll(EventHandler *ev, SYS_NETFD fd);
1578 int event_send(EventHandler *ev, Event *event); 1620 int event_send(EventHandler *ev, Event *event);
1621
1622 // resource pool
1623 ResourceData* resourcepool_lookup(Session *sn, Request *rq, const char *name, int flags);
1624 ResourceData* resourcepool_cfg_lookup(ServerConfiguration *cfg, const char *name, int flags);
1625 void resourcepool_free(Session *sn, Request *rq, ResourceData *resource);
1626
1627 // utils
1628 NSAPI_PUBLIC char *util_html_escape(const char *s);
1579 1629
1580 // assert 1630 // assert
1581 void ws_log_assert(const char *file, const char *func, int line); 1631 void ws_log_assert(const char *file, const char *func, int line);
1582 #ifdef _DEBUG 1632 #ifdef _DEBUG
1583 #ifndef __FUNCTION__ 1633 #ifndef __FUNCTION__

mercurial