Mercurial > hg > freeDiameter
view extensions/dict_json/json-schema-to-c.cc @ 1510:a2fb51309cd2
Add 3GPP TS 29.345 V15.1.0 (2019-09)
Add AVPs:
- App-Layer-User-Id, UTF8String, code 3801, section 6.3.2
- Assistance-info, Grouped, code 3802, section 6.3.3
- Assistance-Info-Validity-Timer, Unsigned32, code 3803, section 6.3.4
- Discovery-Type, Unsigned32, code 3804, section 6.3.5
- Filter-Id, OctetString, code 3805, section 6.3.9
- MAC-Address, UTF8String, code 3806, section 6.3.11
- Match-Report, Grouped, code 3807, section 6.3.12
- Operating-Channel, Unsigned32, code 3808, section 6.3.14
- P2P-Features, Unsigned32, code 3809, section 6.3.15
- ProSe-App-Code, OctetString, code 3810, section 6.3.16
- ProSe-App-Id, UTF8String, code 3811, section 6.3.17
- ProSe-App-Mask, OctetString, code 3812, section 6.3.18
- ProSe-Discovery-Filter, Grouped, code 3813, section 6.3.20
- PRR-Flags, Unsigned32, code 3814, section 6.3.21
- ProSe-Validity-Timer, Unsigned32, code 3815, section 6.3.22
- Requesting-EPUID, UTF8String, code 3816, section 6.3.23
- Targeted-EPUID, UTF8String, code 3817, section 6.3.26
- Time-Window, Unsigned32, code 3818, section 6.3.27
- WiFi-P2P-Assistance-Info, Grouped, code 3819, section 6.3.30
- WLAN-Assistance-Info, Grouped, code 3820, section 6.3.31
- WLAN-Link-Layer-Id, OctetString, code 3821, section 6.3.32
- WLAN-Link-Layer-Id-List, Grouped, code 3822, section 6.3.33
- Location-Update-Trigger, Grouped, code 3823, section 6.3.42
- Location-Update-Event-Type, Unsigned32, code 3824, section 6.3.43
- Change-Of-Area-Type, Grouped, code 3825, section 6.3.44
- Location-Update-Event-Trigger, Unsigned32, code 3826, section 6.3.45
- Report-Cardinality, Enumerated, code 3827, section 6.3.46
- Minimum-Interval-Time, Unsigned32, code 3828, section 6.3.47
- Periodic-Location-Type, Grouped, code 3829, section 6.3.48
- Location-Report-Interval-Time, Unsigned32, code 3830, section 6.3.49
- Total-Number-Of-Reports, Unsigned32, code 3831, section 6.3.50
- Validity-Time-Announce, Unsigned32, code 3832, section 6.3.36
- Validity-Time-Monitor, Unsigned32, code 3833, section 6.3.37
- Validity-Time-Communication, Unsigned32, code 3834, section 6.3.38
- ProSe-App-Code-Info, Grouped, code 3835, section 6.3.39
- MIC, OctetString, code 3836, section 6.3.40
- UTC-based-Counter, Unsigned32, code 3837, section 6.3.41
- ProSe-Match-Refresh-Timer, Unsigned32, code 3838, section 6.3.52
- ProSe-Metadata-Index-Mask, OctetString, code 3839, section 6.3.60
- App-Identifier, Grouped, code 3840, section 6.3.61
- OS-ID, OctetString, code 3841, section 6.3.62
- OS-App-ID, UTF8String, code 3842, section 6.3.63
- Requesting-RPAUID, UTF8String, code 3843, section 6.3.64
- Target-RPAUID, UTF8String, code 3844, section 6.3.65
- Target-PDUID, OctetString, code 3845, section 6.3.66
- ProSe-Restricted-Code, OctetString, code 3846, section 6.3.67
- ProSe-Restricted-Code-Suffix-Range, OctetString, code 3847, section 6.3.68
- Beginning-Suffix, OctetString, code 3848, section 6.3.69
- Ending-Suffix, OctetString, code 3849, section 6.3.70
- Discovery-Entry-ID, Unsigned32, code 3850, section 6.3.59
- Match-Timestamp, Time, code 3851, section 6.3.71
- PMR-Flags, Unsigned32, code 3852, section 6.3.57
- ProSe-Application-Metadata, UTF8String, code 3853, section 6.3.58
- Discovery-Auth-Request, Grouped, code 3854, section 6.3.53
- Discovery-Auth-Response, Grouped, code 3855, section 6.3.54
- Match-Request, Grouped, code 3856, section 6.3.55
- Match-Report-Info, Grouped, code 3857, section 6.3.56
- Banned-RPAUID, UTF8String, code 3858, section 6.3.73
- Banned-PDUID, OctetString, code 3859, section 6.3.74
- Code-Receiving-Security-Material, Grouped, code 3860, section 6.3.75
- Code-Sending-Security-Material, Grouped, code 3861, section 6.3.76
- DUSK, OctetString, code 3862, section 6.3.77
- DUIK, OctetString, code 3863, section 6.3.78
- DUCK, OctetString, code 3864, section 6.3.79
- MIC-Check-indicator, Unsigned32, code 3865, section 6.3.80
- Encrypted-Bitmask, OctetString, code 3866, section 6.3.81
- ProSe-App-Code-Suffix-Range, OctetString, code 3867, section 6.3.82
- PC5-tech, OctetString, code 3868, section 6.3.84
Note: Name conflict with 3GPP TS 29.154 Time-Window (4204).
Time-Window (3818) in 3GPP TS 29.345 V12.1.0 (2014-12) predates
Time-Window (4204) in 3GPP TS 29.154 V13.1.0 (2016-03).
author | Luke Mewburn <luke@mewburn.net> |
---|---|
date | Sun, 05 Apr 2020 08:27:37 +1000 |
parents | cf411b1dcbbb |
children |
line wrap: on
line source
/********************************************************************************************************** * Software License Agreement (BSD License) * * Author: Thomas Klausner <tk@giga.or.at> * * * * Copyright (c) 2016, 2017, 2019 Thomas Klausner * * All rights reserved. * * * * Written under contract by nfotex IT GmbH, http://nfotex.com/ * * * * Redistribution and use of this software in source and binary forms, with or without modification, are * * permitted provided that the following conditions are met: * * * * * Redistributions of source code must retain the above * * copyright notice, this list of conditions and the * * following disclaimer. * * * * * Redistributions in binary form must reproduce the above * * copyright notice, this list of conditions and the * * following disclaimer in the documentation and/or other * * materials provided with the distribution. * * * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * **********************************************************************************************************/ #include <errno.h> #include <getopt.h> #include <inttypes.h> #include <libgen.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <unistd.h> #include <json/SchemaValidator.h> [[noreturn]] void usage(char *prg, int exit_status) { FILE *f = (exit_status ? stderr : stdout); fprintf(f, "Usage: %s [-hV] [-i include] [-N variable-name] [-n namespace] [-t type] json [output]\n", prg); fprintf(f, "options:\n\ -h, --help print this usage message and exit\n\ -i, --include FILE include FILE in output C source file\n\ -n, --namespace NAME specify namespace in which to define variable\n\ -N, --name NAME specify name of variable to define\n\ --no-validate don't validate against JSON meta schema (default)\n\ --type TYPE specify type of variable (char * (default) or std::string)\n\ --validate validate against JSON meta schema\n\ --validate-only validate against JSON meta schema and exit (don't create C source)\n\ "); exit(exit_status); } const char *OPTIONS = "hi:N:n:t:V"; enum { OPT_NO_VALIDATE = 256, OPT_VALIDATE_ONLY }; struct option options[] = { { "help", no_argument, NULL, 'h' }, { "include", required_argument, NULL, 'i' }, { "name", required_argument, NULL, 'N' }, { "namespace", required_argument, NULL, 'n' }, { "no-validate", no_argument, NULL, OPT_NO_VALIDATE }, { "type", required_argument, NULL, 't' }, { "validate", no_argument, NULL, 'V' }, { "validate-only", no_argument, NULL, OPT_VALIDATE_ONLY }, { NULL, 0, NULL, 0 } }; char *read_full_file (const char *filename, off_t max_size, off_t* size_ret, const char *desc) { FILE *fp; if ((fp = fopen (filename, "rb")) == NULL) { fprintf (stderr, "couldn't open %s file [%s]: %d, %s\n", desc, filename, errno, strerror(errno)); return NULL; } struct stat stat_buf; if (fstat (fileno(fp), &stat_buf) < 0) { fprintf (stderr, "couldn't stat %s file [%s]: %d, %s\n", desc, filename, errno, strerror(errno)); fclose (fp); return NULL; } off_t n = stat_buf.st_size; if (max_size > 0 && n > max_size) { fprintf (stderr, "%s file [%s] is larger than %lld bytes\n", desc, filename, (long long)max_size); fclose (fp); return NULL; } char *buf; if ((buf = (char *) malloc ((size_t)n+1)) == NULL) { fprintf (stderr, "error allocating %lld bytes for read of %s file [%s]\n", (long long)n, desc, filename); fclose (fp); return NULL; } if (fread (buf, 1, (size_t)n, fp) < (size_t) n) { fprintf (stderr, "error reading %s file [%s]: %d, %s\n", desc, filename, errno, strerror(errno)); fclose (fp); free (buf); return NULL; } fclose (fp); buf[n] = '\0'; if (size_ret != NULL) *size_ret = n; return buf; } int main (int argc, char **argv) { char *name_space = NULL; char *name = NULL; bool free_name = false; char default_type[] = "char *"; char *type = default_type; bool validate = false; bool convert = true; char *include = NULL; int c; while ((c=getopt_long(argc, argv, OPTIONS, options, NULL)) != EOF) { switch (c) { case 'i': include = optarg; break; case 'N': name = optarg; break; case 'n': name_space = optarg; break; case 't': type = optarg; break; case 'V': validate = true; break; case OPT_NO_VALIDATE: validate = false; break; case OPT_VALIDATE_ONLY: validate = true; convert = false; break; case 'h': usage(argv[0], 0); default: usage(argv[0], 1); } } if (optind != argc - 2 && optind != argc - 1) usage(argv[0], 1); char *input = argv[optind]; char *output = NULL; if (optind == argc -2) { output = argv[optind+1]; } char *str = read_full_file(input, 10*1024*1024, NULL, input); Json::Reader reader; Json::Value json; if (!reader.parse(str, json)) { fprintf(stderr, "%s: parse error: %s\n", input, reader.getFormattedErrorMessages().c_str()); exit(1); } if (validate) { std::string error_message; Json::SchemaValidator *validator; try { validator = Json::SchemaValidator::create_meta_validator(); } catch (Json::SchemaValidator::Exception e) { fprintf(stderr, "%s: can't create meta schema validator\n", argv[0]); exit(1); } if (!validator->validate(json)) { const std::vector<Json::SchemaValidator::Error> errors = validator->errors(); for (unsigned int i=0; i<errors.size(); i++) fprintf(stderr, "%s:%s: %s\n", input, errors[i].path.c_str(), errors[i].message.c_str()); exit(1); } try { Json::SchemaValidator v(json); } catch (Json::SchemaValidator::Exception e) { fprintf(stderr, "%s: can't create schema validator: %s\n", argv[0], e.type_message().c_str()); for (auto error : e.errors) { fprintf(stderr, "%s:%s: %s\n", input, error.path.c_str(), error.message.c_str()); } exit(1); } } if (!convert) { exit(0); } FILE *fin = fopen(input, "r"); if (fin == NULL) { fprintf(stderr, "%s: can't open schema file [%s]: %s\n", argv[0], input, strerror(errno)); exit(1); } FILE *fout; if (output) { fout = fopen(output, "w"); if (fout == NULL) { fprintf(stderr, "%s: can't create output file [%s]: %s\n", argv[0], output, strerror(errno)); exit(1); } } else { fout = stdout; } if (name == NULL) { char *base = basename(input); char *end = strrchr(base, '.'); if (end == NULL) { end = base + strlen(base); } name = strndup(base, static_cast<size_t>(end-base)); for (char *p = name; *p; p++) { if ((*p >= 'A' && *p < 'Z') || (*p >= 'a' && *p < 'z') || *p == '_') { continue; } else if (*p >= '0' && *p <= '9') { if (p > name) { continue; } } *p = '_'; } } else { for (const char *p = name; *p; p++) { if ((*p >= 'A' && *p < 'Z') || (*p >= 'a' && *p < 'z') || *p == '_') { continue; } else if (*p >= '0' && *p <= '9') { if (p > name) { continue; } } else if (p[0] == ':' && p[1] == ':') { p += 1; continue; } fprintf(stderr, "%s: name [%s] is not a valid C identifier\n", argv[0], name); exit(1); } } if (include) { fprintf(fout, "#include <%s>\n\n", include); } if (strcmp(type, "std::string") == 0) { fputs("#include <string>\n\n", fout); } if (name_space) { fprintf(fout, "namespace %s {\n\n", name_space); } fprintf(fout, "const %s %s = \"\\\n", type, name); if (free_name) { free(name); name = NULL; } char line[8192]; while (fgets(line, sizeof(line), fin)) { if (line[strlen(line)-1] == '\n') line[strlen(line)-1] = '\0'; char *p = line; char *end = line+strlen(line); char *q; do { q = p + strcspn(p, "\"\\"); if (q < end) { fprintf(fout, "%.*s\\%c", (int)(q-p), p, *q); p=q+1; } else fprintf(fout, "%s", p); } while (q < end); fputs(" \\n\\\n", fout); } fputs("\";\n", fout); if (name_space) { fputs("\n}\n", fout); } if (ferror(fin)) { fprintf(stderr, "%s: read error on schema file [%s]: %s\n", argv[0], input, strerror(errno)); fclose(fout); unlink(output); exit(1); } fclose(fin); if (ferror(fout)) { fprintf(stderr, "%s: write error on output file [%s]: %s\n", argv[0], output, strerror(errno)); fclose(fout); unlink(output); exit(1); } fclose(fout); exit(0); }