Skip to content

Commit bdda8a2

Browse files
authored
Merge pull request #67 from mchalain/master
prerelease 2.9
2 parents b738b69 + 79318e8 commit bdda8a2

File tree

5 files changed

+45
-42
lines changed

5 files changed

+45
-42
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include scripts.mk
22

33
package?=httpserver
4-
version=2.5
4+
version=2.9
55

66
ifeq ($(VTHREAD_TYPE),pthread)
77
USE_PTHREAD=y

include/httpserver/httpserver.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,14 @@ typedef int (*http_send_t)(void *ctx, const char *data, int length);
166166
typedef void (*http_disconnect_t)(void *ctx);
167167
typedef void (*http_destroy_t)(void *ctx);
168168

169+
#define HTTPCLIENT_TYPE_SECURE 0x0001
170+
169171
typedef struct httpclient_ops_s httpclient_ops_t;
170172
struct httpclient_ops_s
171173
{
172174
const char *scheme;
173175
int default_port;
176+
int type;
174177
http_create_t create;
175178
http_connect_t connect; /* callback to connect on an external server */
176179
http_recv_t recvreq; /* callback to receive data on the socket */
@@ -725,14 +728,6 @@ void httpclient_shutdown(http_client_t *client);
725728
#define WAIT_ACCEPT 0x02
726729
int httpclient_wait(http_client_t *client, int options);
727730

728-
typedef void *(*module_create_t)(http_server_t *server, void *config);
729-
typedef struct module_s
730-
{
731-
const char *name;
732-
void *(*create)(http_server_t *server, void *config);
733-
void (*destroy)(void*);
734-
} module_t;
735-
736731
#ifdef __cplusplus
737732
}
738733
#endif

src/httpserver/_httpserver.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,7 @@ struct http_client_s
8989
buffer_t *sockdata;
9090

9191
http_server_session_t *session;
92-
#if defined USE_IPV6
93-
struct sockaddr_in6 addr;
94-
#else
95-
struct sockaddr_in addr;
96-
#endif
92+
struct sockaddr_storage addr;
9793
unsigned int addr_size;
9894
struct http_client_s *next;
9995
};

src/httpserver/httpserver.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ const char str_defaultscheme[] = "http";
158158
const char str_form_urlencoded[] = "application/x-www-form-urlencoded";
159159
const char str_cookie[] = "Cookie";
160160
const char str_true[] = "true";
161+
const char str_false[] = "false";
161162

162163
static char _httpserver_software[] = "libhttpserver";
163164
char *httpserver_software = _httpserver_software;
@@ -1032,9 +1033,9 @@ static int _httpmessage_parseprecontent(http_message_t *message, buffer_t *data)
10321033
if (message->query)
10331034
length = strlen(message->query);
10341035

1035-
if (message->method->properties == MESSAGE_ALLOW_CONTENT &&
1036+
if ((message->method->properties & MESSAGE_ALLOW_CONTENT) &&
10361037
message->content_type != NULL &&
1037-
!strcmp(message->content_type, str_form_urlencoded))
1038+
!strncasecmp(message->content_type, str_form_urlencoded, sizeof(str_form_urlencoded) - 1))
10381039
{
10391040
next = PARSE_POSTCONTENT;
10401041
message->state &= ~PARSE_CONTINUE;
@@ -2759,6 +2760,7 @@ static int _httpclient_run(http_client_t *client)
27592760
{
27602761
ret = ECONTINUE;
27612762
client->request_queue = request->next;
2763+
27622764
if ((request->state & PARSE_MASK) < PARSE_END)
27632765
{
27642766
dbg("client: uncomplete");
@@ -2776,6 +2778,12 @@ static int _httpclient_run(http_client_t *client)
27762778
client->state = CLIENT_EXIT | (client->state & ~CLIENT_MACHINEMASK);
27772779
ret = EINCOMPLETE;
27782780
}
2781+
else if (httpmessage_result(request->response, -1) > 299)
2782+
{
2783+
dbg("client: exit on result");
2784+
client->state = CLIENT_EXIT | (client->state & ~CLIENT_MACHINEMASK);
2785+
ret = EINCOMPLETE;
2786+
}
27792787
else
27802788
{
27812789
dbg("client: keep alive");
@@ -3617,6 +3625,13 @@ const char *httpserver_INFO(http_server_t *server, const char *key)
36173625
snprintf(service, NI_MAXSERV, "%d", server->protocol_ops->default_port);
36183626
value = service;
36193627
}
3628+
else if (!strcasecmp(key, "secure"))
3629+
{
3630+
if (server->protocol_ops->type & HTTPCLIENT_TYPE_SECURE)
3631+
value = str_true;
3632+
else
3633+
value = str_false;
3634+
}
36203635
else if (!strcasecmp(key, "port"))
36213636
{
36223637
#if 1

src/utils.c

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -219,58 +219,52 @@ int utils_searchexp(const char *haystack, const char *needleslist, const char **
219219
static int _utils_searchexp(const char *haystack, const char *needleslist, int ignore_case, const char **rest)
220220
{
221221
int ret = EREJECT;
222+
if (needleslist == NULL || needleslist[0] == '\0')
223+
return ret;
222224
if (haystack != NULL)
223225
{
224226
int i = -1;
225227
const char *needle = needleslist;
226228
while (needle != NULL)
227229
{
228-
i = -1;
230+
i = 0;
229231
ret = ECONTINUE;
230-
int wildcard = 1;
232+
const char *wildcard = &(haystack[i]);
231233
if (*needle == '^')
232234
{
233-
wildcard = 0;
235+
wildcard = NULL;
236+
needle++;
234237
}
235238
const char *needle_entry = needle;
236239
do
237240
{
241+
utils_dbg("wildcard %s needle %s, haystack %s", wildcard, needle, &haystack[i]);
242+
char hay = haystack[i];
238243
if (*needle == '*')
239244
{
240-
wildcard = 1;
245+
wildcard = &(haystack[i]);
241246
needle++;
242247
}
243-
i++;
244-
char hay = haystack[i];
245248
// lowercase
246249
if (ignore_case && hay > 0x40 && hay < 0x5b)
247250
hay += 0x20;
248-
utils_dbg("wildcard %d, needle %s, haystack %s", wildcard, needle, &haystack[i]);
249-
if (!wildcard)
251+
if (wildcard == NULL)
250252
{
251-
needle++;
252253
char lneedle = *needle;
253254
if (ignore_case && lneedle > 0x40 && lneedle < 0x5b)
254255
lneedle += 0x20;
255-
if (*needle == ',' || *needle == '\0' || *needle == '$')
256-
{
257-
utils_dbg("end of needle, hay %c", hay);
258-
break;
259-
}
260-
else if (lneedle != hay && *needle != '*')
256+
if (lneedle != hay)
261257
{
262258
utils_dbg("end of needle %c, hay %c",lneedle, hay);
263259
needle = needle_entry;
264260
ret = EREJECT;
265-
if (*needle == '^')
266-
{
267-
break;
268-
}
261+
break;
269262
}
270263
else if (lneedle == hay)
271264
{
272265
ret = ESUCCESS;
273266
}
267+
needle++;
274268
}
275269
else
276270
{
@@ -281,13 +275,16 @@ static int _utils_searchexp(const char *haystack, const char *needleslist, int i
281275
ret = ESUCCESS;
282276
if (lneedle == hay)
283277
{
284-
wildcard = 0;
285-
}
286-
else if (*needle == ',' || *needle == '\0')
287-
{
288-
break;
278+
wildcard = NULL;
279+
needle++;
289280
}
290281
}
282+
i++;
283+
if (*needle == ',' || *needle == '\0' || *needle == '$')
284+
{
285+
utils_dbg("end of needle %c, hay %c", *needle, hay);
286+
break;
287+
}
291288
}
292289
while(haystack[i] != '\0');
293290
if (*needle == '*' && haystack[i] != '\0')
@@ -305,8 +302,8 @@ static int _utils_searchexp(const char *haystack, const char *needleslist, int i
305302
{
306303
if (*needle == ',' || *needle == '\0' || *needle == '$')
307304
{
308-
if (wildcard && (rest != NULL))
309-
*rest = &haystack[i - 1];
305+
if (wildcard && (*needle != '$') && (rest != NULL))
306+
*rest = wildcard;
310307
break;
311308
}
312309
else if (*needle != '*')

0 commit comments

Comments
 (0)