@@ -1142,34 +1142,6 @@ char *mg_http_etag(char *buf, size_t len, size_t size, time_t mtime) {
11421142 return buf ;
11431143}
11441144
1145- #if MG_ENABLE_FILE
1146- int mg_http_upload (struct mg_connection * c , struct mg_http_message * hm ,
1147- const char * dir ) {
1148- char offset [40 ] = "" , name [200 ] = "" , path [256 ];
1149- mg_http_get_var (& hm -> query , "offset" , offset , sizeof (offset ));
1150- mg_http_get_var (& hm -> query , "name" , name , sizeof (name ));
1151- if (name [0 ] == '\0' ) {
1152- mg_http_reply (c , 400 , "" , "%s" , "name required" );
1153- return -1 ;
1154- } else {
1155- FILE * fp ;
1156- size_t oft = strtoul (offset , NULL , 0 );
1157- snprintf (path , sizeof (path ), "%s%c%s" , dir , MG_DIRSEP , name );
1158- LOG (LL_DEBUG ,
1159- ("%p %d bytes @ %d [%s]" , c -> fd , (int ) hm -> body .len , (int ) oft , name ));
1160- if ((fp = fopen (path , oft == 0 ? "wb" : "ab" )) == NULL ) {
1161- mg_http_reply (c , 400 , "" , "fopen(%s): %d" , name , errno );
1162- return -2 ;
1163- } else {
1164- fwrite (hm -> body .ptr , 1 , hm -> body .len , fp );
1165- fclose (fp );
1166- mg_http_reply (c , 200 , "" , "" );
1167- return (int ) hm -> body .len ;
1168- }
1169- }
1170- }
1171- #endif
1172-
11731145static void static_cb (struct mg_connection * c , int ev , void * ev_data ,
11741146 void * fn_data ) {
11751147 if (ev == MG_EV_WRITE || ev == MG_EV_POLL ) {
@@ -1680,6 +1652,34 @@ void mg_http_delete_chunk(struct mg_connection *c, struct mg_http_message *hm) {
16801652 c -> recv .len -= ch .len ;
16811653}
16821654
1655+ #if MG_ENABLE_FILE
1656+ int mg_http_upload (struct mg_connection * c , struct mg_http_message * hm ,
1657+ const char * dir ) {
1658+ char offset [40 ] = "" , name [200 ] = "" , path [256 ];
1659+ mg_http_get_var (& hm -> query , "offset" , offset , sizeof (offset ));
1660+ mg_http_get_var (& hm -> query , "name" , name , sizeof (name ));
1661+ if (name [0 ] == '\0' ) {
1662+ mg_http_reply (c , 400 , "" , "%s" , "name required" );
1663+ return -1 ;
1664+ } else {
1665+ FILE * fp ;
1666+ long oft = strtol (offset , NULL , 0 );
1667+ snprintf (path , sizeof (path ), "%s%c%s" , dir , MG_DIRSEP , name );
1668+ remove_double_dots (path );
1669+ LOG (LL_DEBUG , ("%d bytes @ %ld [%s]" , (int ) hm -> body .len , oft , path ));
1670+ if ((fp = fopen (path , oft == 0 ? "wb" : "ab" )) == NULL ) {
1671+ mg_http_reply (c , 400 , "" , "fopen(%s): %d" , path , errno );
1672+ return -2 ;
1673+ } else {
1674+ fwrite (hm -> body .ptr , 1 , hm -> body .len , fp );
1675+ fclose (fp );
1676+ mg_http_reply (c , 200 , "" , "" );
1677+ return (int ) hm -> body .len ;
1678+ }
1679+ }
1680+ }
1681+ #endif
1682+
16831683static void http_cb (struct mg_connection * c , int ev , void * evd , void * fnd ) {
16841684 if (ev == MG_EV_READ || ev == MG_EV_CLOSE ) {
16851685 struct mg_http_message hm ;
0 commit comments