- zval array;
- char *http_method, *method;
- int i, method_len = strlen(method_name);
- unsigned long meth_num = HTTP_G(request).methods.custom.nNextFreeElement + HTTP_MAX_REQUEST_METHOD;
-
- method = emalloc(method_len + 1);
- for (i = 0; i < method_len; ++i) {
- method[i] = toupper(method_name[i]);
+ int i, meth_num;
+ char *http_method, *method, *mconst;
+ http_request_method_entry **ptr = HTTP_G->request.methods.custom.entries;
+
+ if (!isalpha(*method_name)) {
+ http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Request method does not start with a character (%s)", method_name);
+ return 0;
+ }
+
+ if (http_request_method_exists(1, 0, method_name)) {
+ http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Request method does already exist (%s)", method_name);
+ return 0;
+ }
+
+ method = emalloc(method_name_len + 1);
+ mconst = emalloc(method_name_len + 1);
+ for (i = 0; i < method_name_len; ++i) {
+ switch (method_name[i])
+ {
+ case '-':
+ method[i] = '-';
+ mconst[i] = '_';
+ break;
+
+ default:
+ if (!isalnum(method_name[i])) {
+ efree(method);
+ efree(mconst);
+ http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Request method contains illegal characters (%s)", method_name);
+ return 0;
+ }
+ mconst[i] = method[i] = toupper(method_name[i]);
+ break;
+ }