lwip-1.4.1 (partial)
http-server/cparser.h@1:119c4f7144c8, 2018-07-24 (annotated)
- Committer:
- ua1arn
- Date:
- Tue Jul 24 17:36:01 2018 +0000
- Revision:
- 1:119c4f7144c8
lwip 1.4.1 with necessary servers
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ua1arn | 1:119c4f7144c8 | 1 | /* |
ua1arn | 1:119c4f7144c8 | 2 | * The MIT License (MIT) |
ua1arn | 1:119c4f7144c8 | 3 | * |
ua1arn | 1:119c4f7144c8 | 4 | * Copyright (c) 2015 by Sergey Fetisov <fsenok@gmail.com> |
ua1arn | 1:119c4f7144c8 | 5 | * |
ua1arn | 1:119c4f7144c8 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
ua1arn | 1:119c4f7144c8 | 7 | * of this software and associated documentation files (the "Software"), to deal |
ua1arn | 1:119c4f7144c8 | 8 | * in the Software without restriction, including without limitation the rights |
ua1arn | 1:119c4f7144c8 | 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
ua1arn | 1:119c4f7144c8 | 10 | * copies of the Software, and to permit persons to whom the Software is |
ua1arn | 1:119c4f7144c8 | 11 | * furnished to do so, subject to the following conditions: |
ua1arn | 1:119c4f7144c8 | 12 | * |
ua1arn | 1:119c4f7144c8 | 13 | * The above copyright notice and this permission notice shall be included in all |
ua1arn | 1:119c4f7144c8 | 14 | * copies or substantial portions of the Software. |
ua1arn | 1:119c4f7144c8 | 15 | * |
ua1arn | 1:119c4f7144c8 | 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
ua1arn | 1:119c4f7144c8 | 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
ua1arn | 1:119c4f7144c8 | 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
ua1arn | 1:119c4f7144c8 | 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
ua1arn | 1:119c4f7144c8 | 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ua1arn | 1:119c4f7144c8 | 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
ua1arn | 1:119c4f7144c8 | 22 | * SOFTWARE. |
ua1arn | 1:119c4f7144c8 | 23 | */ |
ua1arn | 1:119c4f7144c8 | 24 | |
ua1arn | 1:119c4f7144c8 | 25 | /* |
ua1arn | 1:119c4f7144c8 | 26 | * version: 1.0 demo (7.02.2015) |
ua1arn | 1:119c4f7144c8 | 27 | */ |
ua1arn | 1:119c4f7144c8 | 28 | |
ua1arn | 1:119c4f7144c8 | 29 | #ifndef CPARSER_H |
ua1arn | 1:119c4f7144c8 | 30 | #define CPARSER_H |
ua1arn | 1:119c4f7144c8 | 31 | |
ua1arn | 1:119c4f7144c8 | 32 | #include <stdio.h> |
ua1arn | 1:119c4f7144c8 | 33 | #include <stdbool.h> |
ua1arn | 1:119c4f7144c8 | 34 | #include <stdint.h> |
ua1arn | 1:119c4f7144c8 | 35 | #include <string.h> |
ua1arn | 1:119c4f7144c8 | 36 | |
ua1arn | 1:119c4f7144c8 | 37 | #ifdef __cplusplus |
ua1arn | 1:119c4f7144c8 | 38 | extern "C" { |
ua1arn | 1:119c4f7144c8 | 39 | #endif |
ua1arn | 1:119c4f7144c8 | 40 | |
ua1arn | 1:119c4f7144c8 | 41 | typedef struct parser parser_t; |
ua1arn | 1:119c4f7144c8 | 42 | |
ua1arn | 1:119c4f7144c8 | 43 | typedef size_t (*parser_read_t)(parser_t *parser, char *buffer, size_t size); |
ua1arn | 1:119c4f7144c8 | 44 | typedef char chatset_t[256]; |
ua1arn | 1:119c4f7144c8 | 45 | |
ua1arn | 1:119c4f7144c8 | 46 | typedef struct parser |
ua1arn | 1:119c4f7144c8 | 47 | { |
ua1arn | 1:119c4f7144c8 | 48 | char *buff; |
ua1arn | 1:119c4f7144c8 | 49 | size_t buff_size; |
ua1arn | 1:119c4f7144c8 | 50 | void *user_data; |
ua1arn | 1:119c4f7144c8 | 51 | parser_read_t read_cb; |
ua1arn | 1:119c4f7144c8 | 52 | size_t total; |
ua1arn | 1:119c4f7144c8 | 53 | size_t line; |
ua1arn | 1:119c4f7144c8 | 54 | size_t col; |
ua1arn | 1:119c4f7144c8 | 55 | struct |
ua1arn | 1:119c4f7144c8 | 56 | { |
ua1arn | 1:119c4f7144c8 | 57 | const char *curr; |
ua1arn | 1:119c4f7144c8 | 58 | const char *stop; |
ua1arn | 1:119c4f7144c8 | 59 | } priv; |
ua1arn | 1:119c4f7144c8 | 60 | } parser_t; |
ua1arn | 1:119c4f7144c8 | 61 | |
ua1arn | 1:119c4f7144c8 | 62 | |
ua1arn | 1:119c4f7144c8 | 63 | #define VAL_FMT_0X 1 // supports 0x12AB |
ua1arn | 1:119c4f7144c8 | 64 | #define VAL_FMT_0H 2 // supports 0h12AB |
ua1arn | 1:119c4f7144c8 | 65 | #define VAL_FMT_0B 4 // supports 0b01101001 |
ua1arn | 1:119c4f7144c8 | 66 | #define VAL_FMT_FLOAT 8 // supports 3.1415 |
ua1arn | 1:119c4f7144c8 | 67 | #define VAL_FMT_EXP 16 // supports 0.31415e+1 |
ua1arn | 1:119c4f7144c8 | 68 | #define VAL_FMT_SIGN 32 // supports +-3.1415 |
ua1arn | 1:119c4f7144c8 | 69 | #define VAL_FMT_ALL 0xFF |
ua1arn | 1:119c4f7144c8 | 70 | |
ua1arn | 1:119c4f7144c8 | 71 | #define STR_FMT_QUOTE 1 // supports "string" |
ua1arn | 1:119c4f7144c8 | 72 | #define STR_FMT_APOST 2 // supports 'string' |
ua1arn | 1:119c4f7144c8 | 73 | #define STR_FMT_NAKED 4 // supports string |
ua1arn | 1:119c4f7144c8 | 74 | #define STR_FMT_ESC 8 // supports \ escaping (bfnrt'"/\) |
ua1arn | 1:119c4f7144c8 | 75 | #define STR_FMT_ESCU 16 // supports unicode escaping \u12AB (like json) |
ua1arn | 1:119c4f7144c8 | 76 | #define STR_FMT_ESCW 32 // supports web escaping %2A |
ua1arn | 1:119c4f7144c8 | 77 | #define STR_FMT_ALL 0xFF |
ua1arn | 1:119c4f7144c8 | 78 | |
ua1arn | 1:119c4f7144c8 | 79 | void parser_init(parser_t *p, const char *str, int len); |
ua1arn | 1:119c4f7144c8 | 80 | void parser_init_s(parser_t *p, char *stream_buff, size_t size, parser_read_t cb); |
ua1arn | 1:119c4f7144c8 | 81 | bool parser_is_next(parser_t *p, const char *str, int len); |
ua1arn | 1:119c4f7144c8 | 82 | char parser_curr(parser_t *p); |
ua1arn | 1:119c4f7144c8 | 83 | bool parser_eof(parser_t *p); |
ua1arn | 1:119c4f7144c8 | 84 | |
ua1arn | 1:119c4f7144c8 | 85 | int parser_read(parser_t *p, const chatset_t chatset, char *dest, int dest_size); |
ua1arn | 1:119c4f7144c8 | 86 | int parser_read_before2(parser_t *p, char *dest, int dest_size, char c1, char c2); |
ua1arn | 1:119c4f7144c8 | 87 | int parser_read_digits(parser_t *p, char *dest, int dest_size, bool hex); |
ua1arn | 1:119c4f7144c8 | 88 | int parser_read_value(parser_t *p, char *dest, int dest_size, int fmt); |
ua1arn | 1:119c4f7144c8 | 89 | int parser_read_string(parser_t *p, char *dest, int dest_size, int fmt); |
ua1arn | 1:119c4f7144c8 | 90 | #define parser_read_before(p, dest, dest_size, c) \ |
ua1arn | 1:119c4f7144c8 | 91 | parser_read_before2(p, dest, dest_size, c, c); |
ua1arn | 1:119c4f7144c8 | 92 | #define parser_read_before_line_end(p, dest, dest_size) \ |
ua1arn | 1:119c4f7144c8 | 93 | parser_read_before2(p, dest, dest_size, '\r', '\n'); |
ua1arn | 1:119c4f7144c8 | 94 | |
ua1arn | 1:119c4f7144c8 | 95 | int parser_skip(parser_t *p, const chatset_t chatset); |
ua1arn | 1:119c4f7144c8 | 96 | int parser_skip_n(parser_t *p, int n); |
ua1arn | 1:119c4f7144c8 | 97 | bool parser_skip_char(parser_t *p, char c); |
ua1arn | 1:119c4f7144c8 | 98 | bool parser_skip_ws(parser_t *p); |
ua1arn | 1:119c4f7144c8 | 99 | bool parser_skip_ws_in_line(parser_t *p); |
ua1arn | 1:119c4f7144c8 | 100 | bool parser_skip_line(parser_t *p); |
ua1arn | 1:119c4f7144c8 | 101 | bool parser_skip_before(parser_t *p, char c); |
ua1arn | 1:119c4f7144c8 | 102 | |
ua1arn | 1:119c4f7144c8 | 103 | #ifdef __cplusplus |
ua1arn | 1:119c4f7144c8 | 104 | } |
ua1arn | 1:119c4f7144c8 | 105 | #endif |
ua1arn | 1:119c4f7144c8 | 106 | |
ua1arn | 1:119c4f7144c8 | 107 | #endif |