7934e2995a5bc08137aa5629240d7ff989429247
[src/app-framework-binder.git] / src / afb-api.c
1 /*
2  * Copyright (C) 2016-2019 "IoT.bzh"
3  * Author "Fulup Ar Foll"
4  * Author José Bollo <jose.bollo@iot.bzh>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *   http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #define _GNU_SOURCE
20
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <errno.h>
25
26 #include "afb-api.h"
27
28 /**
29  * Checks wether 'name' is a valid API name.
30  * @return 1 if valid, 0 otherwise
31  */
32 int afb_api_is_valid_name(const char *name)
33 {
34         unsigned char c;
35
36         c = (unsigned char)*name;
37         if (c == 0)
38                 /* empty names aren't valid */
39                 return 0;
40
41         do {
42                 if (c < (unsigned char)'\x80') {
43                         switch(c) {
44                         default:
45                                 if (c > ' ')
46                                         break;
47                                 /*@fallthrough@*/
48                         case '"':
49                         case '#':
50                         case '%':
51                         case '&':
52                         case '\'':
53                         case '/':
54                         case '?':
55                         case '`':
56                         case '\\':
57                         case '\x7f':
58                                 return 0;
59                         }
60                 }
61                 c = (unsigned char)*++name;
62         } while(c != 0);
63         return 1;
64 }
65