- // POST datas may come in multiple chunk. Even when it never happen on AFB, we still have to handle the case
- if (strcasestr(encoding, JSON_CONTENT) == 0) {
- errMessage = jsonNewMessage(AFB_FATAL, "Post Date wrong type encoding=%s != %s", encoding, JSON_CONTENT);
- goto ExitOnError;
- }
+ // allocate application POST processor handle to zero
+ posthandle = cmalloc(1, sizeof (AFB_PostHandle));
+ posthandle->uid = postcount++; // build a UID for DEBUG
+ *con_cls = posthandle; // attache POST handle to current HTTP request
+
+ // Let make sure we have the right encoding and a valid length
+ encoding = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_TYPE);
+ param = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, MHD_HTTP_HEADER_CONTENT_LENGTH);
+ if (param) sscanf(param, "%i", &contentlen);
+
+ // Form post is handle through a PostProcessor and call API once per form key
+ if (strcasestr(encoding, FORM_CONTENT) != NULL) {
+
+ posthandle = malloc(sizeof (AFB_PostHandle)); // allocate application POST processor handle
+ posthandle->type = AFB_POST_FORM;
+ posthandle->private= (void*)createRequest (connection, session, url);
+ posthandle->pp = MHD_create_post_processor (connection, MAX_POST_SIZE, doPostIterate, posthandle);
+
+ if (NULL == posthandle->pp) {
+ fprintf(stderr,"OOPS: Internal error fail to allocate MHD_create_post_processor\n");
+ free (posthandle);
+ return MHD_NO;
+ }
+ return MHD_YES;
+ }
+
+ // POST json is store into a buffer and present in one piece to API
+ if (strcasestr(encoding, JSON_CONTENT) != NULL) {