33 char filename_dec[1024];
39 mg_url_decode(key, (
int)key_len, key_dec, (
int)
sizeof(key_dec), 1);
41 if (((
size_t)key_dec_len >= (
size_t)
sizeof(key_dec)) || (key_dec_len < 0)) {
49 (
int)
sizeof(filename_dec),
52 if (((
size_t)filename_dec_len >= (
size_t)
sizeof(filename_dec))
53 || (filename_dec_len < 0)) {
70 "%s: Function \"Get\" not available",
78 "%s: Function \"Store\" not available",
100 int value_dec_len, ret;
105 "%s: Not enough memory (required: %lu)",
107 (
unsigned long)(*value_len + 1));
111 mg_url_decode(key, (
int)key_len, key_dec, (
int)
sizeof(key_dec), 1);
113 if (*value_len >= 2 &&
value[*value_len - 2] ==
'%')
115 else if (*value_len >= 1 &&
value[*value_len - 1] ==
'%')
118 value, (
int)*value_len, value_dec, ((
int)*value_len) + 1, 1);
122 (
size_t)value_dec_len,
141 mg_url_decode(key, (
int)key_len, key_dec, (
int)
sizeof(key_dec), 1);
162 const char *boundary,
167 int clen = (
int)buf_len - (
int)boundary_len - 4;
170 for (i = 0; i <= clen; i++) {
171 if (!memcmp(buf + i,
"\r\n--", 4)) {
172 if (!memcmp(buf + i + 4, boundary, boundary_len)) {
184 const char *content_type;
192 int64_t file_size = 0;
213 if (!has_body_data) {
234 const char *val = strchr(
data,
'=');
236 ptrdiff_t keylen, vallen;
256 memset(path, 0,
sizeof(path));
268 next = strchr(val,
'&');
272 vallen = (ptrdiff_t)strlen(val);
278 conn,
data, (
size_t)keylen, val, (
size_t *)&vallen, fdh);
296#if !defined(NO_FILESYSTEMS)
305 fwrite(val, 1, (
size_t)vallen, fstore.
access.
fp);
306 if ((
n != (
size_t)vallen) || (ferror(fstore.
access.
fp))) {
308 "%s: Cannot write file %s",
314 file_size += (int64_t)
n;
328 "%s: Error saving file %s",
338 "%s: Cannot create file %s",
375 "APPLICATION/X-WWW-FORM-URLENCODED",
378 "APPLICATION/WWW-FORM-URLENCODED",
382 int all_data_read = 0;
392 ptrdiff_t keylen, vallen;
394 int end_of_key_value_pair_found = 0;
397 if ((
size_t)buf_fill < (
sizeof(buf) - 1)) {
399 size_t to_read =
sizeof(buf) - 1 - (
size_t)buf_fill;
400 r =
mg_read(conn, buf + (
size_t)buf_fill, to_read);
401 if ((
r < 0) || ((
r == 0) && all_data_read)) {
411 all_data_read = (buf_fill == 0);
420 val = strchr(buf,
'=');
429 memset(path, 0,
sizeof(path));
446#if !defined(NO_FILESYSTEMS)
454 "%s: Cannot create file %s",
464 next = strchr(val,
'&');
467 end_of_key_value_pair_found = 1;
469 vallen = (ptrdiff_t)strlen(val);
470 end_of_key_value_pair_found = all_data_read;
475 if (!end_of_key_value_pair_found && !all_data_read) {
482 ((get_block > 0) ? NULL : buf),
507#if !defined(NO_FILESYSTEMS)
510 fwrite(val, 1, (
size_t)vallen, fstore.
access.
fp);
511 if ((
n != (
size_t)vallen) || (ferror(fstore.
access.
fp))) {
513 "%s: Cannot write file %s",
519 file_size += (int64_t)
n;
523 if (!end_of_key_value_pair_found) {
527 sizeof(buf) - (
size_t)used);
529 buf_fill -= (
int)used;
530 if ((
size_t)buf_fill < (
sizeof(buf) - 1)) {
532 size_t to_read =
sizeof(buf) - 1 - (
size_t)buf_fill;
533 r =
mg_read(conn, buf + (
size_t)buf_fill, to_read);
534 if ((
r < 0) || ((
r == 0) && all_data_read)) {
535#if !defined(NO_FILESYSTEMS)
550 all_data_read = (buf_fill == 0);
561 }
while (!end_of_key_value_pair_found);
563#if !defined(NO_FILESYSTEMS)
575 "%s: Error saving file %s",
584 if (all_data_read && (buf_fill == 0)) {
591 memmove(buf, buf + (
size_t)used,
sizeof(buf) - (
size_t)used);
592 buf_fill -= (
int)used;
607 const char *content_disp, *hend, *fbeg, *fend, *nbeg, *nend;
610 int all_data_read = 0;
612 memset(&part_header, 0,
sizeof(part_header));
616 while (content_type[bl] ==
' ') {
627 fbeg = content_type + bl + 9;
633 "%s: Cannot allocate memory for boundary [%lu]",
638 memcpy(boundary, fbeg, bl);
643 if (boundary[0] ==
'"') {
644 hbuf = strchr(boundary + 1,
'"');
645 if ((!hbuf) || (*hbuf !=
'"')) {
651 memmove(boundary, boundary + 1, bl);
652 bl = strlen(boundary);
678 for (part_no = 0;; part_no++) {
679 size_t towrite, fnlen,
n;
681 size_t to_read =
sizeof(buf) - 1 - (
size_t)buf_fill;
686 r =
mg_read(conn, buf + (
size_t)buf_fill, to_read);
687 if ((
r < 0) || ((
r == 0) && all_data_read)) {
693 all_data_read = (buf_fill == 0);
706 while ((
d < buf_fill) && (buf[
d] !=
'-')) {
709 if ((
d > 0) && (buf[
d] ==
'-')) {
710 memmove(buf, buf +
d, (
unsigned)buf_fill - (
unsigned)
d);
716 if (buf[0] !=
'-' || buf[1] !=
'-') {
721 if (0 != strncmp(buf + 2, boundary, bl)) {
726 if (buf[bl + 2] !=
'\r' || buf[bl + 3] !=
'\n') {
729 if (((
size_t)buf_fill != (
size_t)(bl + 6))
730 || (strncmp(buf + bl + 2,
"--\r\n", 4))) {
741 hend = strstr(hbuf,
"\r\n\r\n");
750 if ((hend + 2) != hbuf) {
763 "Content-Disposition");
772 nbeg = strstr(content_disp,
"name=\"");
773 while ((nbeg != NULL) && (strcspn(nbeg - 1,
":,; \t") != 0)) {
775 nbeg = strstr(nbeg + 1,
"name=\"");
787 nend = strchr(nbeg,
'\"');
795 nbeg = strstr(content_disp,
"name=");
796 while ((nbeg != NULL) && (strcspn(nbeg - 1,
":,; \t") != 0)) {
798 nbeg = strstr(nbeg + 1,
"name=");
814 nend = nbeg + strcspn(nbeg,
",; \t");
819 fbeg = strstr(content_disp,
"filename=\"");
820 while ((fbeg != NULL) && (strcspn(fbeg - 1,
":,; \t") != 0)) {
822 fbeg = strstr(fbeg + 1,
"filename=\"");
832 fend = strchr(fbeg,
'\"');
846 fbeg = strstr(content_disp,
"filename=");
847 while ((fbeg != NULL) && (strcspn(fbeg - 1,
":,; \t") != 0)) {
849 fbeg = strstr(fbeg + 1,
"filename=");
853 fend = fbeg + strcspn(fbeg,
",; \t");
857 if (!fbeg || !fend) {
862 fnlen = (size_t)(fend - fbeg);
868 if (!(((ptrdiff_t)fbeg > (ptrdiff_t)nend)
869 || ((ptrdiff_t)nbeg > (ptrdiff_t)fend))) {
875 memset(path, 0,
sizeof(path));
879 (
size_t)(nend - nbeg),
880 ((fnlen > 0) ? fbeg : NULL),
889 (
size_t)((buf - hbuf) + buf_fill),
893#if !defined(NO_FILESYSTEMS)
903 "%s: Cannot create file %s",
914 towrite = (size_t)(buf - hend + buf_fill);
916 if (towrite < bl + 4) {
930 ((get_block > 0) ? NULL : nbeg),
933 : (size_t)(nend - nbeg)),
948#if !defined(NO_FILESYSTEMS)
953 n = (size_t)fwrite(hend, 1, towrite, fstore.
access.
fp);
954 if ((
n != towrite) || (ferror(fstore.
access.
fp))) {
956 "%s: Cannot write file %s",
962 file_size += (int64_t)
n;
967 memmove(buf, hend + towrite, bl + 4);
968 buf_fill = (
int)(bl + 4);
972 to_read =
sizeof(buf) - 1 - (
size_t)buf_fill;
973 r =
mg_read(conn, buf + (
size_t)buf_fill, to_read);
974 if ((
r < 0) || ((
r == 0) && all_data_read)) {
975#if !defined(NO_FILESYSTEMS)
994 if (!next && (
r == 0)) {
1000 towrite = (next ? (size_t)(next - hend) : 0);
1005 ((get_block > 0) ? NULL : nbeg),
1008 : (size_t)(nend - nbeg)),
1022#if !defined(NO_FILESYSTEMS)
1026 n = (size_t)fwrite(hend, 1, towrite, fstore.
access.
fp);
1027 if ((
n != towrite) || (ferror(fstore.
access.
fp))) {
1029 "%s: Cannot write file %s",
1035 file_size += (int64_t)
n;
1046 "%s: Error saving file %s",
1065 used = next - buf + 2;
1066 memmove(buf, buf + (
size_t)used,
sizeof(buf) - (
size_t)used);
1067 buf_fill -= (
int)used;
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
int mg_strncasecmp(const char *s1, const char *s2, size_t len)
#define mg_malloc_ctx(a, c)
static void remove_bad_file(const struct mg_connection *conn, const char *path)
static __inline void * mg_malloc(size_t a)
static int mg_fopen(const struct mg_connection *conn, const char *path, int mode, struct mg_file *filep)
static int parse_http_headers(char **buf, struct mg_header hdr[(64)])
static const char * get_header(const struct mg_header *hdr, int num_hdr, const char *name)
const char * mg_get_header(const struct mg_connection *conn, const char *name)
#define mg_cry_internal(conn, fmt,...)
int mg_url_decode(const char *src, int src_len, char *dst, int dst_len, int is_form_url_encoded)
#define MG_FOPEN_MODE_WRITE
static void remove_dot_segments(char *inout)
int mg_read(struct mg_connection *conn, void *buf, size_t len)
static int mg_fclose(struct mg_file_access *fileacc)
static __inline void mg_free(void *a)
#define STRUCT_FILE_INITIALIZER
@ MG_FORM_FIELD_STORAGE_GET
@ MG_FORM_FIELD_STORAGE_ABORT
@ MG_FORM_FIELD_STORAGE_STORE
@ MG_FORM_FIELD_STORAGE_SKIP
@ MG_FORM_FIELD_HANDLE_NEXT
@ MG_FORM_FIELD_HANDLE_ABORT
struct mg_request_info request_info
struct mg_context * phys_ctx
struct mg_file_access access
struct mg_header http_headers[(64)]
const char * request_method
const char * query_string