Update copyright dates
[src/app-framework-binder.git] / src / afb-method.c
1 /*
2  * Copyright (C) 2015-2020 "IoT.bzh"
3  * Author: José Bollo <jose.bollo@iot.bzh>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18
19 #include <microhttpd.h>
20
21 #include "afb-method.h"
22
23 enum afb_method get_method(const char *method)
24 {
25         switch (method[0] & ~' ') {
26         case 'C':
27                 return afb_method_connect;
28         case 'D':
29                 return afb_method_delete;
30         case 'G':
31                 return afb_method_get;
32         case 'H':
33                 return afb_method_head;
34         case 'O':
35                 return afb_method_options;
36         case 'P':
37                 switch (method[1] & ~' ') {
38                 case 'A':
39                         return afb_method_patch;
40                 case 'O':
41                         return afb_method_post;
42                 case 'U':
43                         return afb_method_put;
44                 }
45                 break;
46         case 'T':
47                 return afb_method_trace;
48         }
49         return afb_method_none;
50 }
51
52 #if !defined(MHD_HTTP_METHOD_PATCH)
53 #define MHD_HTTP_METHOD_PATCH "PATCH"
54 #endif
55 const char *get_method_name(enum afb_method method)
56 {
57         switch (method) {
58         case afb_method_get:
59                 return MHD_HTTP_METHOD_GET;
60         case afb_method_post:
61                 return MHD_HTTP_METHOD_POST;
62         case afb_method_head:
63                 return MHD_HTTP_METHOD_HEAD;
64         case afb_method_connect:
65                 return MHD_HTTP_METHOD_CONNECT;
66         case afb_method_delete:
67                 return MHD_HTTP_METHOD_DELETE;
68         case afb_method_options:
69                 return MHD_HTTP_METHOD_OPTIONS;
70         case afb_method_patch:
71                 return MHD_HTTP_METHOD_PATCH;
72         case afb_method_put:
73                 return MHD_HTTP_METHOD_PUT;
74         case afb_method_trace:
75                 return MHD_HTTP_METHOD_TRACE;
76         default:
77                 return NULL;
78         }
79 }
80
81