2 * Copyright (c) 2007 Ry Dahl <ry.d4hl@gmail.com>
3 * This software is released under the "MIT License". See README file for details.
8 #include <sys/socket.h>
9 #include <netinet/in.h>
12 #define EV_STANDALONE 1
18 typedef struct ebb_server ebb_server
;
19 typedef struct ebb_client ebb_client
;
21 #define EBB_LOG_DOMAIN "Ebb"
22 #define ebb_error(str, ...) \
23 g_log(EBB_LOG_DOMAIN, G_LOG_LEVEL_ERROR, str, ## __VA_ARGS__);
24 #define ebb_warning(str, ...) \
25 g_log(EBB_LOG_DOMAIN, G_LOG_LEVEL_WARNING, str, ## __VA_ARGS__);
26 #define ebb_info(str, ...) \
27 g_log(EBB_LOG_DOMAIN, G_LOG_LEVEL_INFO, str, ## __VA_ARGS__);
28 #define ebb_debug(str, ...) \
29 g_log(EBB_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, str, ## __VA_ARGS__);
31 #define EBB_BUFFERSIZE (16*1024)
32 #define EBB_MAX_CLIENTS 200
33 #define EBB_TIMEOUT 30.0
34 #define EBB_MAX_ENV 100
35 #define EBB_TCP_COMMON \
38 struct sockaddr_in sockaddr;
42 typedef void (*ebb_client_cb
)(ebb_client
*);
44 void ebb_client_close(ebb_client
*);
45 size_t ebb_client_read(ebb_client
*, char *buffer
, int length
);
46 void ebb_client_write(ebb_client
*, const char *data
, int length
);
47 void ebb_client_start_writing( ebb_client
*client
48 , ebb_client_cb after_write_cb
50 /* User must free the GString returned from ebb_client_read_input */
51 GString
* ebb_client_read_input(ebb_client
*client
, ssize_t size
);
53 enum { EBB_REQUEST_METHOD
70 char read_buffer
[EBB_BUFFERSIZE
];
75 GString
*write_buffer
;
77 ebb_client_cb after_write_cb
;
81 char upload_file_filename
[200];
88 ev_timer timeout_watcher
;
90 /* the ENV structure */
92 const char *env_fields
[EBB_MAX_ENV
];
93 int env_field_lengths
[EBB_MAX_ENV
];
94 const char *env_values
[EBB_MAX_ENV
];
95 int env_value_lengths
[EBB_MAX_ENV
];
100 typedef void (*ebb_request_cb
)(ebb_client
*, void*);
102 ebb_server
* ebb_server_alloc();
103 void ebb_server_init( ebb_server
*server
104 , struct ev_loop
*loop
107 , ebb_request_cb request_cb
108 , void *request_cb_data
110 void ebb_server_free(ebb_server
*);
111 void ebb_server_start(ebb_server
*);
112 void ebb_server_stop(ebb_server
*);
116 struct hostent
*dns_info
;
122 void *request_cb_data
;
123 ebb_request_cb request_cb
;
125 ev_io
*request_watcher
;
126 struct ev_loop
*loop
;
128 ebb_client clients
[EBB_MAX_CLIENTS
];