Browse code

webkernel: post callback

Dario Rodriguez authored on 24/06/2014 20:25:38
Showing 2 changed files
... ...
@@ -275,6 +275,9 @@ wk_service(wk *paramweb)
275 275
                                         continue;
276 276
                                 }
277 277
                         }
278
+                        sbuf_discard(in);
279
+                        if(sbuf_unused(in)>0)
280
+                                sselect_addread(web->ssel,client->fd,(void *)client);
278 281
                 }
279 282
         }
280 283
         while((n=sselect_getwritefiltered(web->ssel,&(web->fdset),fds,sizeof(fds)/sizeof(fds[0])))>0) {
... ...
@@ -959,7 +962,7 @@ wk_clientservicereadheader(_wk *web, wk_client *client)
959 962
                 client->serviced=1;
960 963
                 client->continuationactive=1;
961 964
                 client->status=wkc_none;
962
-        } else if(action==wkact_post) {
965
+        } else if(action==wkact_post && web->callback_post!=NULL) {
963 966
                 char *lenvar;
964 967
                 char *contenttype;
965 968
                 if(strcmp(client->uri.method,"POST")!=0 ||
... ...
@@ -994,9 +997,10 @@ wk_clientservicereadpost(_wk *web, wk_client *client)
994 997
         char *sep;
995 998
         char *start;
996 999
         char *end;
1000
+        wk_action action;
997 1001
         if((in=wk_sbufget((wk *)web, client->inbufid))==NULL)
998 1002
                 return(-1); /* internal error */
999
-        while(sbuf_count(in)>0) {
1003
+        while(sbuf_count(in)>0 && client->pendingpost>0) {
1000 1004
                 if(client->inpostvar==-1) {
1001 1005
                         sbuf_discard(in);
1002 1006
                         buf=sbuf_ptr(in);
... ...
@@ -1031,6 +1035,21 @@ wk_clientservicereadpost(_wk *web, wk_client *client)
1031 1035
                         client->inpostvar=-1;
1032 1036
                 }
1033 1037
         }
1038
+        if(client->pendingpost>0)
1039
+                return(0); /* nothing more to do for now*/
1040
+        /* call the post method */
1041
+        client->serviced=1;
1042
+        client->continuationactive=0;
1043
+        action=web->callback_post((wk *)web, client->connid, client->uri, web->userptr);
1044
+        if(action==wkact_continuation) {
1045
+                client->serviced=1;
1046
+                client->continuationactive=1;
1047
+                client->status=wkc_none;
1048
+        } else {
1049
+                client->serviced=1;
1050
+                client->continuationactive=0;
1051
+                client->status=wkc_none;
1052
+        }
1034 1053
         return(0);
1035 1054
 }
1036 1055
 
... ...
@@ -62,6 +62,7 @@ char *wk_uri_getheader(wk_uri *wkuri, char *header, char *defaultvalue);
62 62
 char *wk_uri_getheaderbynum(wk_uri *wkuri, int num);
63 63
 
64 64
 char *wk_uri_getvar(wk_uri *wkuri, char *varname, int *len);
65
+char *wk_uri_copyvar(wk_uri *uri, char *varname, char *dest, int destlen);
65 66
 
66 67
 int wk_post_addvalid(wk *web, int connid, char *varname, char *tofile);
67 68
 char *wk_post_get(wk *web, int connid, char *varname, int *isfile);