mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-15 01:55:03 +00:00
Backport from xs.
This commit is contained in:
parent
79270abd09
commit
0337c71cf4
3 changed files with 22 additions and 6 deletions
18
xs.h
18
xs.h
|
@ -90,6 +90,7 @@ d_char *xs_number_new(double f);
|
||||||
double xs_number_get(const char *v);
|
double xs_number_get(const char *v);
|
||||||
const char *xs_number_str(const char *v);
|
const char *xs_number_str(const char *v);
|
||||||
|
|
||||||
|
void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size);
|
||||||
|
|
||||||
#ifdef XS_IMPLEMENTATION
|
#ifdef XS_IMPLEMENTATION
|
||||||
|
|
||||||
|
@ -907,6 +908,23 @@ const char *xs_number_str(const char *v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size)
|
||||||
|
/* clone of memmem */
|
||||||
|
{
|
||||||
|
char *p, *r = NULL;
|
||||||
|
int offset = 0;
|
||||||
|
|
||||||
|
while (!r && h_size - offset > n_size && (p = strchr(haystack + offset, *needle))) {
|
||||||
|
if (memcmp(p, needle, n_size) == 0)
|
||||||
|
r = p;
|
||||||
|
else
|
||||||
|
offset = p - haystack + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* XS_IMPLEMENTATION */
|
#endif /* XS_IMPLEMENTATION */
|
||||||
|
|
||||||
#endif /* _XS_H */
|
#endif /* _XS_H */
|
||||||
|
|
|
@ -69,8 +69,6 @@ d_char *xs_url_vars(char *str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void *memmem(const void *, size_t, const void *, size_t);
|
|
||||||
|
|
||||||
d_char *_xs_multipart_form_data(char *payload, int p_size, char *header)
|
d_char *_xs_multipart_form_data(char *payload, int p_size, char *header)
|
||||||
/* parses a multipart/form-data payload */
|
/* parses a multipart/form-data payload */
|
||||||
{
|
{
|
||||||
|
@ -94,7 +92,7 @@ d_char *_xs_multipart_form_data(char *payload, int p_size, char *header)
|
||||||
d_char *p_vars = xs_dict_new();
|
d_char *p_vars = xs_dict_new();
|
||||||
|
|
||||||
/* iterate searching the boundaries */
|
/* iterate searching the boundaries */
|
||||||
while ((p = memmem(payload + offset, p_size - offset, boundary, bsz)) != NULL) {
|
while ((p = xs_memmem(payload + offset, p_size - offset, boundary, bsz)) != NULL) {
|
||||||
xs *s1 = NULL;
|
xs *s1 = NULL;
|
||||||
xs *l1 = NULL;
|
xs *l1 = NULL;
|
||||||
char *vn = NULL;
|
char *vn = NULL;
|
||||||
|
@ -133,13 +131,13 @@ d_char *_xs_multipart_form_data(char *payload, int p_size, char *header)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* find the start of the part content */
|
/* find the start of the part content */
|
||||||
if ((p = memmem(p, p_size - offset, "\r\n\r\n", 4)) == NULL)
|
if ((p = xs_memmem(p, p_size - offset, "\r\n\r\n", 4)) == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
p += 4;
|
p += 4;
|
||||||
|
|
||||||
/* find the next boundary */
|
/* find the next boundary */
|
||||||
if ((q = memmem(p, p_size - offset, boundary, bsz)) == NULL)
|
if ((q = xs_memmem(p, p_size - offset, boundary, bsz)) == NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
po = p - payload;
|
po = p - payload;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
/* ad1c7ba748725abdecc1f1124d697f9130c49e87 */
|
/* 3aa82bc4fc310ec95194602bed88a9767e100350 */
|
||||||
|
|
Loading…
Reference in a new issue