aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/daemontest_post.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/daemontest_post.c')
-rw-r--r--src/daemon/daemontest_post.c46
1 files changed, 37 insertions, 9 deletions
diff --git a/src/daemon/daemontest_post.c b/src/daemon/daemontest_post.c
index 10f6ea97..00bec910 100644
--- a/src/daemon/daemontest_post.c
+++ b/src/daemon/daemontest_post.c
@@ -63,6 +63,27 @@ copyBuffer (void *ptr, size_t size, size_t nmemb, void *ctx)
63 return size * nmemb; 63 return size * nmemb;
64} 64}
65 65
66/**
67 * Note that this post_iterator is not perfect
68 * in that it fails to support incremental processing.
69 * (to be fixed in the future)
70 */
71static int
72post_iterator (void *cls,
73 enum MHD_ValueKind kind,
74 const char *key, const char *value, size_t off, size_t size)
75{
76 int *eok = cls;
77
78 if ((0 == strcmp (key, "name")) &&
79 (size == strlen ("daniel")) && (0 == strncmp (value, "daniel", size)))
80 (*eok) |= 1;
81 if ((0 == strcmp (key, "project")) &&
82 (size == strlen ("curl")) && (0 == strncmp (value, "curl", size)))
83 (*eok) |= 2;
84 return MHD_YES;
85}
86
66static int 87static int
67ahc_echo (void *cls, 88ahc_echo (void *cls,
68 struct MHD_Connection *connection, 89 struct MHD_Connection *connection,
@@ -70,31 +91,38 @@ ahc_echo (void *cls,
70 const char *method, 91 const char *method,
71 const char *version, 92 const char *version,
72 const char *upload_data, unsigned int *upload_data_size, 93 const char *upload_data, unsigned int *upload_data_size,
73 void ** unused) 94 void **unused)
74{ 95{
96 static int eok;
75 struct MHD_Response *response; 97 struct MHD_Response *response;
98 struct MHD_PostProcessor *pp;
76 int ret; 99 int ret;
77 const char *r1;
78 const char *r2;
79 100
80 if (0 != strcmp ("POST", method)) 101 if (0 != strcmp ("POST", method))
81 { 102 {
82 printf ("METHOD: %s\n", method); 103 printf ("METHOD: %s\n", method);
83 return MHD_NO; /* unexpected method */ 104 return MHD_NO; /* unexpected method */
84 } 105 }
85 r1 = MHD_lookup_connection_value (connection, MHD_POSTDATA_KIND, "name"); 106 pp = *unused;
86 r2 = MHD_lookup_connection_value (connection, MHD_POSTDATA_KIND, "project"); 107 if (pp == NULL)
87 if ((r1 != NULL) && 108 {
88 (r2 != NULL) && 109 eok = 0;
89 (0 == strcmp ("daniel", r1)) && (0 == strcmp ("curl", r2))) 110 pp = MHD_create_post_processor (connection, 1024, &post_iterator, &eok);
111 *unused = pp;
112 }
113 MHD_post_process (pp, upload_data, *upload_data_size);
114 if ((eok == 3) && (0 == *upload_data_size))
90 { 115 {
91 response = MHD_create_response_from_data (strlen (url), 116 response = MHD_create_response_from_data (strlen (url),
92 (void *) url, 117 (void *) url,
93 MHD_NO, MHD_YES); 118 MHD_NO, MHD_YES);
94 ret = MHD_queue_response (connection, MHD_HTTP_OK, response); 119 ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
95 MHD_destroy_response (response); 120 MHD_destroy_response (response);
96 return MHD_YES; /* done */ 121 MHD_destroy_post_processor (pp);
122 *unused = NULL;
123 return ret;
97 } 124 }
125 *upload_data_size = 0;
98 return MHD_YES; 126 return MHD_YES;
99} 127}
100 128