Add support for L4Re Virtio Sockets
[src/app-framework-binder.git] / src / afb-method.c
1 /*
2  * Copyright (C) 2016-2019 "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 #if WITH_LIBMICROHTTPD
19
20 #include <microhttpd.h>
21
22 #include "afb-method.h"
23
24 enum afb_method get_method(const char *method)
25 {
26         switch (method[0] & ~' ') {
27         case 'C':
28                 return afb_method_connect;
29         case 'D':
30                 return afb_method_delete;
31         case 'G':
32                 return afb_method_get;
33         case 'H':
34                 return afb_method_head;
35         case 'O':
36                 return afb_method_options;
37         case 'P':
38                 switch (method[1] & ~' ') {
39                 case 'A':
40                         return afb_method_patch;
41                 case 'O':
42                         return afb_method_post;
43                 case 'U':
44                         return afb_method_put;
45                 }
46                 break;
47         case 'T':
48                 return afb_method_trace;
49         }
50         return afb_method_none;
51 }
52
53 #if !defined(MHD_HTTP_METHOD_PATCH)
54 #define MHD_HTTP_METHOD_PATCH "PATCH"
55 #endif
56 const char *get_method_name(enum afb_method method)
57 {
58         switch (method) {
59         case afb_method_get:
60                 return MHD_HTTP_METHOD_GET;
61         case afb_method_post:
62                 return MHD_HTTP_METHOD_POST;
63         case afb_method_head:
64                 return MHD_HTTP_METHOD_HEAD;
65         case afb_method_connect:
66                 return MHD_HTTP_METHOD_CONNECT;
67         case afb_method_delete:
68                 return MHD_HTTP_METHOD_DELETE;
69         case afb_method_options:
70                 return MHD_HTTP_METHOD_OPTIONS;
71         case afb_method_patch:
72                 return MHD_HTTP_METHOD_PATCH;
73         case afb_method_put:
74                 return MHD_HTTP_METHOD_PUT;
75         case afb_method_trace:
76                 return MHD_HTTP_METHOD_TRACE;
77         default:
78                 return NULL;
79         }
80 }
81
82 #endif
83