| 122 | } |
| 123 | |
| 124 | int loadParams(cgiRequestObj *request, |
| 125 | char* (*getenv2)(const char*, void* thread_context), |
| 126 | char *raw_post_data, |
| 127 | ms_uint32 raw_post_data_length, |
| 128 | void* thread_context) { |
| 129 | register int x,m=0; |
| 130 | char *s, *queryString = NULL, *httpCookie = NULL; |
| 131 | int debuglevel; |
| 132 | int maxParams = MS_DEFAULT_CGI_PARAMS; |
| 133 | |
| 134 | if (getenv2==NULL) |
| 135 | getenv2 = &msGetEnv; |
| 136 | |
| 137 | if(getenv2("REQUEST_METHOD", thread_context)==NULL) { |
| 138 | msIO_printf("This script can only be used to decode form results and \n"); |
| 139 | msIO_printf("should be initiated as a CGI process via a httpd server.\n"); |
| 140 | exit(0); |
| 141 | } |
| 142 | |
| 143 | debuglevel = (int)msGetGlobalDebugLevel(); |
| 144 | |
| 145 | if(strcmp(getenv2("REQUEST_METHOD", thread_context),"POST") == 0) { /* we've got a post from a form */ |
| 146 | char *post_data; |
| 147 | int data_len; |
| 148 | request->type = MS_POST_REQUEST; |
| 149 | |
| 150 | s = getenv2("CONTENT_TYPE", thread_context); |
| 151 | if (s != NULL) |
| 152 | request->contenttype = msStrdup(s); |
| 153 | /* we've to set default content-type which is |
| 154 | * application/octet-stream according to |
| 155 | * W3 RFC 2626 section 7.2.1 */ |
| 156 | else request->contenttype = msStrdup("application/octet-stream"); |
| 157 | |
| 158 | if (raw_post_data) { |
| 159 | post_data = msStrdup(raw_post_data); |
| 160 | data_len = raw_post_data_length; |
| 161 | } |
| 162 | else { |
| 163 | post_data = readPostBody( request ); |
| 164 | data_len = strlen(post_data); |
| 165 | } |
| 166 | |
| 167 | /* if the content_type is application/x-www-form-urlencoded, |
| 168 | we have to parse it like the QUERY_STRING variable */ |
| 169 | if(strcmp(request->contenttype, "application/x-www-form-urlencoded") == 0) |
| 170 | { |
| 171 | while( data_len > 0 && isspace(post_data[data_len-1]) ) |
| 172 | post_data[--data_len] = '\0'; |
| 173 | |
| 174 | while( post_data[0] ) { |
| 175 | if(m >= maxParams) { |
| 176 | maxParams *= 2; |
| 177 | request->ParamNames = (char **) realloc(request->ParamNames,sizeof(char *) * maxParams); |
| 178 | if (request->ParamNames == NULL) { |
| 179 | msIO_printf("Out of memory trying to allocate name/value pairs.\n"); |
| 180 | exit(1); |
| 181 | } |
no test coverage detected