yumapro  20.10-12
YumaPro SDK
tk.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 - 2020, Andy Bierman, All Rights Reserved.
3  * Copyright (c) 2012 - 2021, YumaWorks, Inc., All Rights Reserved.
4  *
5  * Unless required by applicable law or agreed to in writing,
6  * software distributed under the License is distributed on an
7  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8  * KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations
10  * under the License.
11  */
12 #ifndef _H_tk
13 #define _H_tk
14 
15 /* FILE: tk.h
16 *********************************************************************
17 * *
18 * P U R P O S E *
19 * *
20 *********************************************************************/
21 
28 /*********************************************************************
29 * *
30 * C H A N G E H I S T O R Y *
31 * *
32 *********************************************************************
33 
34 date init comment
35 ----------------------------------------------------------------------
36 12-nov-05 abb Begun
37 
38 */
39 
40 #include <xmlstring.h>
41 
42 #ifndef _H_dlq
43 #include "dlq.h"
44 #endif
45 
46 #ifndef _H_ncxtypes
47 #include "ncxtypes.h"
48 #endif
49 
50 #ifndef _H_xmlns
51 #include "xmlns.h"
52 #endif
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 /********************************************************************
59 * *
60 * C O N S T A N T S *
61 * *
62 *********************************************************************/
63 
76 #define TK_BUFF_SIZE 0xffff
77 
78 
79 
80  /******************** tk_token_t macros ******************/
81 
82 /* macros for quick processing of token chains
83  * All these macros take 1 parameter
84  * INPUTS:
85  * T == pointer to the tk_chain_t in progress
86  */
87 
89 #define TK_NEXT(T) ((tk_token_t *)dlq_nextEntry(T))
90 
92 #define TK_TYP(T) ((T)->typ)
93 
95 #define TK_ID(T) ((T)->typ==TK_TT_TSTRING || (T)->typ==TK_TT_MSTRING)
96 
98 #define TK_VAL(T) (T)->val
99 
101 #define TK_NSID(T) (T)->nsid
102 
104 #define TK_MOD(T) (T)->mod
105 
107 #define TK_ADV(T) \
108  ((T)->cur ? (((T)->cur = (tk_token_t *)dlq_nextEntry((T)->cur)) \
109  ? NO_ERR : ERR_NCX_EOF) : ERR_NCX_EOF)
110 
112 #define TK_BKUP(T) \
113  if (! ((T)->cur = (tk_token_t *)dlq_prevEntry((T)->cur))) \
114  (T)->cur = (tk_token_t *)&((T)->tkQ)
115 
116 
117 
118  /******************** tk_chain_t macros ******************/
119 
120 
122 #define TK_CUR(T) ((T)->cur)
123 
125 #define TK_CUR_TYP(T) ((T)->cur->typ)
126 
128 #define TK_CUR_VAL(T) ((T)->cur->val)
129 
131 #define TK_CUR_LEN(T) ((T)->cur->len)
132 
134 #define TK_CUR_MOD(T) (T)->cur->mod
135 
137 #define TK_CUR_MODLEN(T) ((T)->cur->modlen)
138 
140 #define TK_CUR_STR(T) ((T)->cur->typ >= TK_TT_STRING && \
141  (T)->cur->typ <= TK_TT_SQSTRING)
142 
144 #define TK_TYP_STR(T) ((T) >= TK_TT_STRING && (T) <= TK_TT_SQSTRING)
145 
147 #define TK_CUR_NOWSTR(T) ((T)->cur->typ >= TK_TT_STRING && \
148  (T)->cur->typ <= TK_TT_SQSTRING)
149 
151 #define TK_CUR_NUM(T) ((T)->cur->typ==TK_TT_DNUM || \
152  (T)->cur->typ==TK_TT_HNUM || \
153  (T)->cur->typ==TK_TT_RNUM)
154 
155 
157 #define TK_TYP_NUM(T) (((T) >= TK_TT_DNUM) && ((T) <= TK_TT_RNUM))
158 
159 
161 #define TK_CUR_INUM(T) ((T)->cur->typ==TK_TT_DNUM || \
162  (T)->cur->typ==TK_TT_HNUM)
163 
165 #define TK_CUR_IQUAL(T) ((T)->cur->typ==TK_TT_QMARK || \
166  (T)->cur->typ==TK_TT_STAR || \
167  (T)->cur->typ==TK_TT_PLUS)
168 
169 
171 #define TK_CUR_ID(T) ((T)->cur->typ==TK_TT_TSTRING || \
172  (T)->cur->typ==TK_TT_MSTRING)
173 
175 #define TK_CUR_SID(T) ((T)->cur->typ==TK_TT_SSTRING || \
176  (T)->cur->typ==TK_TT_MSSTRING)
177 
179 #define TK_CUR_LNUM(T) ((T)->cur->linenum)
180 
182 #define TK_CUR_LPOS(T) ((T)->cur->linepos)
183 
188 #define TK_CUR_TEXT(T) (((T)->cur->typ == TK_TT_STRING) || \
189  ((T)->cur->typ >= TK_TT_SSTRING && \
190  (T)->cur->typ <= TK_TT_RNUM))
191 
192 
194 #define TK_CUR_NSID(T) (T)->cur->nsid
195 
197 #define TK_DOCMODE(TKC) ((TKC)->flags & TK_FL_DOCMODE)
198 
200 #define TK_HAS_ORIGTK(TK) (((TK)->typ == TK_TT_QSTRING || \
201  (TK)->typ == TK_TT_SQSTRING) && \
202  (TK)->origval != NULL)
203 
205 #define TK_SET_ESCERR(TK) (TK)->flags |= TK_FL_ESCSTR_ERR
206 
208 #define TK_GET_ESCERR(TK) ((TK)->flags & TK_FL_ESCSTR_ERR)
209 
210 
217 #define TK_FL_REDO bit0
218 
225 #define TK_FL_MALLOC bit1
226 
233 #define TK_FL_DOCMODE bit2
234 
235 
242 #define TK_FL_BINARYMODE bit3
243 
244 
250 #define TK_FL_ESCSTR_ERR bit4
251 
252 
253 
259 #define TK_FL_VAL_MALLOC bit0
260 
261 
266 #define TK_FL_ORIGVAL_MALLOC bit1
267 
268 
269 #define TK_VALBUFF_LEN 8
270 
271 
272 /********************************************************************
273 * *
274 * T Y P E S *
275 * *
276 *********************************************************************/
277 
279 typedef enum tk_type_t_ {
280  TK_TT_NONE,
281  /* PUT ALL 1-CHAR TOKENS FIRST */
282  TK_TT_LBRACE,
283  TK_TT_RBRACE,
284  TK_TT_SEMICOL,
285  TK_TT_LPAREN,
302  /* PUT ALL 2-CHAR TOKENS SECOND */
311  /* PUT ALL STRING CLASSIFICATION TOKENS THIRD */
313  TK_TT_LINE,
314  TK_TT_SSTRING,
315  TK_TT_TSTRING,
326  /* PUT ALL NUMBER CLASSIFICATION TOKENS FOURTH */
327  TK_TT_DNUM,
329  TK_TT_RNUM,
331  /* PUT ALL SPECIAL CASE TOKENS LAST */
333 } tk_type_t;
334 
335 
337 typedef enum tk_source_t_ {
345  TK_SOURCE_CLI
346 } tk_source_t;
347 
348 
350 typedef enum tk_origstr_typ_t_ {
351  TK_ORIGSTR_NONE,
356 } tk_origstr_typ_t;
357 
358 
363 typedef struct tk_origstr_t_ {
364  dlq_hdr_t qhdr;
365  tk_origstr_typ_t origtyp;
366  xmlChar *str;
367 } tk_origstr_t;
368 
369 
371 typedef struct tk_token_t_ {
372  dlq_hdr_t qhdr;
373  tk_type_t typ;
374  xmlChar *mod;
375  uint32 modlen;
376  xmlChar *val;
377  xmlChar *origval;
378  uint32 len;
379  uint32 linenum;
380  uint32 linepos;
382  dlq_hdr_t origstrQ;
383  xmlChar valbuff[TK_VALBUFF_LEN];
384  uint8 flags;
385 } tk_token_t;
386 
387 
391 typedef struct tk_token_ptr_t_ {
392  dlq_hdr_t qhdr;
393  tk_token_t *tk;
394  const void *field;
395 } tk_token_ptr_t;
396 
397 
407 typedef status_t
408  (*tk_getline_fn_t) (xmlChar *fillbuff,
409  uint32 fillbuffsize,
410  void *cookie);
411 
412 
413 
415 typedef struct tk_chain_t_ {
416  dlq_hdr_t qhdr;
417  dlq_hdr_t tkQ;
418  dlq_hdr_t tkptrQ;
419  tk_token_t *cur;
420  tk_token_t *escerr_tk;
421  ncx_error_t *curerr;
422  const xmlChar *filename;
423  FILE *fp;
424  xmlChar *buff;
425  xmlChar *bptr;
426  uint32 linenum;
427  uint32 linepos;
428  uint32 flags;
429  tk_source_t source;
431  void *cookie;
432  xmlChar escerr_ch;
433 } tk_chain_t;
434 
435 
436 /********************************************************************
437 * *
438 * F U N C T I O N S *
439 * *
440 *********************************************************************/
441 
442 
448 extern tk_chain_t *
449  tk_new_chain (void);
450 
451 
459 extern void
460  tk_setup_chain_conf (tk_chain_t *tkc,
461  FILE *fp,
462  const xmlChar *filename);
463 
464 
472 extern void
473  tk_setup_chain_cli (tk_chain_t *tkc,
474  xmlChar *line);
475 
476 
486 extern void
487  tk_setup_chain_fields (tk_chain_t *tkc,
488  xmlChar *str);
489 
496 extern void
497  tk_setup_chain_feature (tk_chain_t *tkc,
498  xmlChar *str);
499 
500 
508 extern void
509  tk_setup_chain_yang (tk_chain_t *tkc,
510  FILE *fp,
511  const xmlChar *filename);
512 
513 
520 extern void
521  tk_setup_chain_yin (tk_chain_t *tkc,
522  const xmlChar *filename);
523 
524 
532 extern void
533  tk_setup_chain_json_file (tk_chain_t *tkc,
534  FILE *fp,
535  const xmlChar *filename);
536 
537 
544 extern void
545  tk_setup_chain_json_buffer (tk_chain_t *tkc,
546  xmlChar *buff);
547 
548 
556 extern void
557  tk_setup_chain_json_buffs (tk_chain_t *tkc,
558  tk_getline_fn_t getline_fn,
559  void *cookie);
560 
561 
567 extern void
568  tk_setup_chain_docmode (tk_chain_t *tkc);
569 
570 
577 extern void
578  tk_setup_chain_cli_line (tk_chain_t *tkc,
579  xmlChar *str);
580 
581 
587 extern void
588  tk_free_chain (tk_chain_t *tkc);
589 
590 
599 extern ncx_btype_t
600  tk_get_yang_btype_id (const xmlChar *buff,
601  uint32 len);
602 
603 
610 extern const char *
611  tk_get_token_name (tk_type_t ttyp);
612 
613 
620 extern const char *
621  tk_get_token_sym (tk_type_t ttyp);
622 
623 
630 extern const char *
631  tk_get_btype_sym (ncx_btype_t btyp);
632 
633 
640 extern tk_type_t
641  tk_next_typ (tk_chain_t *tkc);
642 
643 
650 extern tk_type_t
651  tk_next_typ2 (tk_chain_t *tkc);
652 
653 
660 extern boolean
661  tk_next_is_null (tk_chain_t *tkc);
662 
663 
670 extern const xmlChar *
671  tk_next_val (tk_chain_t *tkc);
672 
673 
680 extern void
681  tk_dump_token (const tk_token_t *tk);
682 
683 
690 extern void
691  tk_dump_chain (const tk_chain_t *tkc);
692 
693 
701 extern boolean
702  tk_is_wsp_string (const tk_token_t *tk);
703 
704 
734 extern status_t
735  tk_tokenize_input (tk_chain_t *tkc,
736  ncx_module_t *mod);
737 
738 
749 extern status_t
750  tk_retokenize_cur_string (tk_chain_t *tkc,
751  ncx_module_t *mod);
752 
753 
765 extern tk_chain_t *
766  tk_tokenize_metadata_string (ncx_module_t *mod,
767  xmlChar *str,
768  status_t *res);
769 
770 
783 extern tk_chain_t *
784  tk_tokenize_xpath_string (ncx_module_t *mod,
785  xmlChar *str,
786  uint32 curlinenum,
787  uint32 curlinepos,
788  status_t *res);
789 
790 
797 extern uint32
798  tk_token_count (const tk_chain_t *tkc);
799 
800 
806 extern void
807  tk_reset_chain (tk_chain_t *tkc);
808 
809 
818 extern tk_chain_t *
819  tk_clone_chain (tk_chain_t *oldtkc);
820 
821 
829 extern status_t
830  tk_add_id_token (tk_chain_t *tkc,
831  const xmlChar *valstr);
832 
833 
844 extern status_t
845  tk_add_pid_token (tk_chain_t *tkc,
846  const xmlChar *prefix,
847  uint32 prefixlen,
848  const xmlChar *valstr);
849 
850 
858 extern status_t
859  tk_add_string_token (tk_chain_t *tkc,
860  const xmlChar *valstr);
861 
862 
869 extern status_t
870  tk_add_lbrace_token (tk_chain_t *tkc);
871 
872 
879 extern status_t
880  tk_add_rbrace_token (tk_chain_t *tkc);
881 
882 
889 extern status_t
890  tk_add_semicol_token (tk_chain_t *tkc);
891 
892 
902 extern status_t
903  tk_check_save_origstr (tk_chain_t *tkc,
904  tk_token_t *tk,
905  const void *field);
906 
907 
923 extern const xmlChar *
924  tk_get_first_origstr (const tk_token_ptr_t *tkptr,
925  boolean *dquote,
926  boolean *morestr);
927 
928 
935 extern const tk_origstr_t *
936  tk_first_origstr_rec (const tk_token_ptr_t *tkptr);
937 
938 
945 extern const tk_origstr_t *
946  tk_next_origstr_rec (const tk_origstr_t *origstr);
947 
948 
964 extern const xmlChar *
965  tk_get_origstr_parts (const tk_origstr_t *origstr,
966  boolean *dquote,
967  boolean *newline);
968 
969 
977 extern const tk_token_ptr_t *
978  tk_find_tkptr (const tk_chain_t *tkc,
979  const void *field);
980 
981 
989 extern uint32
990  tk_tkptr_quotes (const tk_token_ptr_t *tkptr);
991 
992 
999 extern boolean
1000  tk_cur_is_first (const tk_chain_t *tkc);
1001 
1002 
1006 #ifdef __cplusplus
1007 } /* end extern 'C' */
1008 #endif
1009 
1010 #endif /* _H_tk */
TK_FL_DOCMODE
#define TK_FL_DOCMODE
== 1: DOC mode: the tk->origtkQ field will be used to preserve pre-string concat and processing == 0:...
Definition: tk.h:233
NCX_MAX_HEXCHAR
#define NCX_MAX_HEXCHAR
max hex digits in the value part of a hex number
Definition: ncxconst.h:422
xml_strlen
uint32 xml_strlen(const xmlChar *str)
Get the String len for xmlChar.
Definition: xml_util.c:1406
TK_TT_RBRACK
@ TK_TT_RBRACK
right bracket ']'
Definition: tk.h:292
TK_TT_TSTRING
@ TK_TT_TSTRING
token string
Definition: tk.h:319
tk_token_t_::valbuff
xmlChar valbuff[TK_VALBUFF_LEN]
value buff if fits
Definition: tk.h:383
tk_next_typ
tk_type_t tk_next_typ(tk_chain_t *tkc)
Get the token type of the next token.
Definition: tk.c:3349
TK_TT_DNUM
@ TK_TT_DNUM
decimal number
Definition: tk.h:331
NCX_QSTRING_CH
#define NCX_QSTRING_CH
start of a double quoted string in NCX text
Definition: ncxconst.h:410
NCX_BT_INT32
@ NCX_BT_INT32
int32
Definition: ncxtypes.h:209
TK_TT_PLUS
@ TK_TT_PLUS
plus mark '+'
Definition: tk.h:298
tk_add_semicol_token
status_t tk_add_semicol_token(tk_chain_t *tkc)
Allocatate a new semi-colon token and add it to the parse chain.
Definition: tk.c:4332
tk_tokenize_xpath_string
tk_chain_t * tk_tokenize_xpath_string(ncx_module_t *mod, xmlChar *str, uint32 curlinenum, uint32 curlinepos, status_t *res)
The specified XPath string is parsed into tokens.
Definition: tk.c:3980
xml_strncpy
uint32 xml_strncpy(xmlChar *copyTo, const xmlChar *copyFrom, uint32 maxlen)
String copy for xmlChar – checks for buffer overflow.
Definition: xml_util.c:1518
NCX_BT_CASE
@ NCX_BT_CASE
internal, not a real type
Definition: ncxtypes.h:227
tk_check_save_origstr
status_t tk_check_save_origstr(tk_chain_t *tkc, tk_token_t *tk, const void *field)
Check the docmode and the specified token; Save a tk_origptr_t if needed with the field address.
Definition: tk.c:4368
TK_SOURCE_JSON
@ TK_SOURCE_JSON
JSON.
Definition: tk.h:342
NCX_BT_BINARY
@ NCX_BT_BINARY
binary (base64)
Definition: ncxtypes.h:218
tk_chain_t_::filename
const xmlChar * filename
filename when source is file
Definition: tk.h:422
tk_origstr_t_
each entry in the origstrQ is the 2nd through Nth string to be concated.
Definition: tk.h:363
tk_setup_chain_json_file
void tk_setup_chain_json_file(tk_chain_t *tkc, FILE *fp, const xmlChar *filename)
Setup a previously allocated chain for a JSON input stream.
Definition: tk.c:3091
tk_get_token_name
const char * tk_get_token_name(tk_type_t ttyp)
Get the symbolic token name.
Definition: tk.c:3280
tk_new_chain
tk_chain_t * tk_new_chain(void)
Allocatate a new token parse chain.
Definition: tk.c:2919
xml_strdup
xmlChar * xml_strdup(const xmlChar *copyFrom)
String duplicate for xmlChar.
Definition: xml_util.c:1553
tk_add_rbrace_token
status_t tk_add_rbrace_token(tk_chain_t *tkc)
Allocatate a new right brace token and add it to the parse chain.
Definition: tk.c:4299
TK_FL_VAL_MALLOC
#define TK_FL_VAL_MALLOC
start flags for the tk->flags field == 1: VAL malloc: the tk->val field is malloced == 0: VAL buffer:...
Definition: tk.h:259
tk_chain_t_::source
tk_source_t source
source context
Definition: tk.h:429
tk_token_ptr_t_::field
const void * field
saved cookie
Definition: tk.h:394
tk_chain_t_::linepos
uint32 linepos
current line position
Definition: tk.h:427
TK_TT_COMMA
@ TK_TT_COMMA
comma ','
Definition: tk.h:293
TK_TT_STAR
@ TK_TT_STAR
star '*'
Definition: tk.h:296
TK_SOURCE_FEATURE
@ TK_SOURCE_FEATURE
YANG 1.1 feature expr.
Definition: tk.h:344
tk_setup_chain_json_buffs
void tk_setup_chain_json_buffs(tk_chain_t *tkc, tk_getline_fn_t getline_fn, void *cookie)
Setup a previously allocated chain for a JSON buffer chain.
Definition: tk.c:3139
NCX_BT_BOOLEAN
@ NCX_BT_BOOLEAN
boolean
Definition: ncxtypes.h:206
NCX_BT_INSTANCE_ID
@ NCX_BT_INSTANCE_ID
instance-identifier
Definition: ncxtypes.h:219
tk_clone_chain
tk_chain_t * tk_clone_chain(tk_chain_t *oldtkc)
Allocatate and a new token parse chain and fill it with the specified token chain contents.
Definition: tk.c:4068
tk_next_val
const xmlChar * tk_next_val(tk_chain_t *tkc)
Get the token type of the next token.
Definition: tk.c:3464
xml_util.h
XML Utilities.
tk_chain_t_::curerr
ncx_error_t * curerr
error token pointer
Definition: tk.h:421
NCX_BT_IDREF
@ NCX_BT_IDREF
identityref
Definition: ncxtypes.h:222
tk_add_string_token
status_t tk_add_string_token(tk_chain_t *tkc, const xmlChar *valstr)
Allocatate a new string token and add it to the parse chain.
Definition: tk.c:4216
tk_free_chain
void tk_free_chain(tk_chain_t *tkc)
Cleanup and deallocate a tk_chain_t.
Definition: tk.c:3205
NCX_BT_INTERN
@ NCX_BT_INTERN
not a real type, string buffer for contents
Definition: ncxtypes.h:231
TK_SET_ESCERR
#define TK_SET_ESCERR(TK)
SET access the escaped string error fields.
Definition: tk.h:205
tk_token_t_::origstrQ
dlq_hdr_t origstrQ
Q of tk_origstr_t only used in DOCMODE.
Definition: tk.h:382
tk_chain_t_::getline_fn
tk_getline_fn_t getline_fn
getline callback
Definition: tk.h:430
NCX_BT_LEAFREF
@ NCX_BT_LEAFREF
leafref (needs special processing)
Definition: ncxtypes.h:221
tk_get_origstr_parts
const xmlChar * tk_get_origstr_parts(const tk_origstr_t *origstr, boolean *dquote, boolean *newline)
Get the fields from the original string record.
Definition: tk.c:4500
tk.h
NCX Syntax Token Handler.
log_debug3
void void void void void void void void void void void log_debug3(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG3 log entry.
tk_token_t_::origval
xmlChar * origval
used in DOCMODE for yangdump
Definition: tk.h:377
tk_dump_chain
void tk_dump_chain(const tk_chain_t *tkc)
Debug printf the token chain !!! Very verbose !!!
Definition: tk.c:3532
NCX_VARBIND_CH
#define NCX_VARBIND_CH
start of an NCX or XPath varbind
Definition: ncxconst.h:416
TK_SOURCE_YANG
@ TK_SOURCE_YANG
YANG.
Definition: tk.h:339
ERR_NCX_UNENDED_COMMENT
@ ERR_NCX_UNENDED_COMMENT
319
Definition: status_enum.h:362
tk_token_t_::len
uint32 len
length of value
Definition: tk.h:378
TK_TT_RNUM
@ TK_TT_RNUM
real number
Definition: tk.h:333
ERR_NCX_INVALID_CONCAT
@ ERR_NCX_INVALID_CONCAT
320
Definition: status_enum.h:363
TK_FL_MALLOC
#define TK_FL_MALLOC
== 1: the tkc->buff field is malloced by this module and will be freed in tk_free_chain == 0: the tkc...
Definition: tk.h:225
NCX_BT_ANYDATA
@ NCX_BT_ANYDATA
YANG 1.1 anydata.
Definition: ncxtypes.h:229
NCX_SQSTRING_CH
#define NCX_SQSTRING_CH
start of a single quoted string in NCX text
Definition: ncxconst.h:413
tk_next_origstr_rec
const tk_origstr_t * tk_next_origstr_rec(const tk_origstr_t *origstr)
Get the next tk_origstr_t struct (if any)
Definition: tk.c:4472
ncxconst.h
Contains NCX constants.
tk_retokenize_cur_string
status_t tk_retokenize_cur_string(tk_chain_t *tkc, ncx_module_t *mod)
The current token is some sort of a string Reparse it according to the full YANG token list,...
Definition: tk.c:3865
xml_isspace
boolean xml_isspace(uint32 ch)
Check if an xmlChar is a space char.
Definition: xml_util.c:1901
TK_TT_SQSTRING
@ TK_TT_SQSTRING
single quoted string
Definition: tk.h:323
tk_chain_t_::escerr_ch
xmlChar escerr_ch
first bad escaped char if escerr
Definition: tk.h:432
TK_ORIGSTR_DQUOTE
@ TK_ORIGSTR_DQUOTE
double quote
Definition: tk.h:352
TK_ORIGSTR_SQUOTE
@ TK_ORIGSTR_SQUOTE
single quote
Definition: tk.h:354
ncx_check_warn_linelen
void ncx_check_warn_linelen(tk_chain_t *tkc, ncx_module_t *mod, const xmlChar *line)
Check if the line display length is greater than the specified amount.
Definition: ncx.c:9238
ncx_print_errormsg
void ncx_print_errormsg(tk_chain_t *tkc, ncx_module_t *mod, status_t res)
Print an parse error message to STDOUT.
Definition: ncx.c:7048
tk_chain_t_::tkQ
dlq_hdr_t tkQ
Q of tk_token_t.
Definition: tk.h:417
TK_CUR_VAL
#define TK_CUR_VAL(T)
return the current token value
Definition: tk.h:128
NCX_BT_UINT8
@ NCX_BT_UINT8
uint8
Definition: ncxtypes.h:211
tk_setup_chain_docmode
void tk_setup_chain_docmode(tk_chain_t *tkc)
Setup a previously allocated chain for a yangdump docmode output.
Definition: tk.c:3163
tk_token_t_::mod
xmlChar * mod
only used if prefix found
Definition: tk.h:374
xmlns_id_t
uint16 xmlns_id_t
integer handle for registered namespaces
Definition: xmlns.h:89
ncx_valid_fname_ch
boolean ncx_valid_fname_ch(uint32 ch)
Check if an xmlChar is a valid NCX name string first char.
Definition: ncx.c:7573
TK_TT_COLON
@ TK_TT_COLON
colon char ':'
Definition: tk.h:299
tk_chain_t_::bptr
xmlChar * bptr
current read buffer pointer
Definition: tk.h:425
TK_TT_FSLASH
@ TK_TT_FSLASH
forward slash char '/'
Definition: tk.h:301
tk_token_t_::linenum
uint32 linenum
token source line number
Definition: tk.h:379
log_debug2
void void void void void void void void void log_debug2(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG2 log entry.
TK_TT_LEQUAL
@ TK_TT_LEQUAL
less than or equal '<='
Definition: tk.h:311
NCX_MODSCOPE_CH
#define NCX_MODSCOPE_CH
prefix scoped identifier field separator token
Definition: ncxconst.h:407
NCX_BT_ENUM
@ NCX_BT_ENUM
enumeration
Definition: ncxtypes.h:204
NO_ERR
@ NO_ERR
000
Definition: status_enum.h:188
NCX_BT_LIST
@ NCX_BT_LIST
internal, YANG list
Definition: ncxtypes.h:228
TK_TT_RBRACE
@ TK_TT_RBRACE
right brace '}'
Definition: tk.h:287
tk_token_t_
single YANG language token type
Definition: tk.h:371
tk_get_first_origstr
const xmlChar * tk_get_first_origstr(const tk_token_ptr_t *tkptr, boolean *dquote, boolean *morestr)
Get the first original string to use.
Definition: tk.c:4417
TK_TT_LPAREN
@ TK_TT_LPAREN
left paren '('
Definition: tk.h:289
NCX_BT_UINT64
@ NCX_BT_UINT64
uint64
Definition: ncxtypes.h:214
tk_source_t_
tk_source_t_
token source context
Definition: tk.h:337
tk_token_t_::typ
tk_type_t typ
token type
Definition: tk.h:373
NCX_MAX_NLEN
#define NCX_MAX_NLEN
all name fields in YANG can be 1 to N bytes set a limit based on likely malloc failure CHANGE TO MATC...
Definition: ncxconst.h:149
tk_chain_t_
token parsing chain (main parser control block)
Definition: tk.h:415
xml_strndup
xmlChar * xml_strndup(const xmlChar *copyFrom, uint32 maxlen)
String duplicate for max N xmlChars.
Definition: xml_util.c:1663
tk_find_tkptr
const tk_token_ptr_t * tk_find_tkptr(const tk_chain_t *tkc, const void *field)
Find the specified token pointer record.
Definition: tk.c:4531
TK_SOURCE_FIELDS
@ TK_SOURCE_FIELDS
RESTCONF fields parameter.
Definition: tk.h:343
TK_TT_DBLFSLASH
@ TK_TT_DBLFSLASH
2 fwd slashes '//'
Definition: tk.h:309
tk_token_ptr_t_
token backptr to get at original token chain for strings used only by yangdump –format=yang|html
Definition: tk.h:391
ERR_NCX_INVALID_REALNUM
@ ERR_NCX_INVALID_REALNUM
243
Definition: status_enum.h:282
tk_setup_chain_conf
void tk_setup_chain_conf(tk_chain_t *tkc, FILE *fp, const xmlChar *filename)
Setup a previously allocated chain for a text config file.
Definition: tk.c:2945
tk_setup_chain_yin
void tk_setup_chain_yin(tk_chain_t *tkc, const xmlChar *filename)
Setup a previously allocated chain for a YIN file.
Definition: tk.c:3069
log_debug4
void void void void void void void void void void void void void log_debug4(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG4 log entry.
ERR_NCX_OPERATION_FAILED
@ ERR_NCX_OPERATION_FAILED
274
Definition: status_enum.h:315
TK_TT_DBLCOLON
@ TK_TT_DBLCOLON
2 colon chars '::'
Definition: tk.h:308
LOGDEBUG2
#define LOGDEBUG2
Check if at least log-level=debug2.
Definition: log.h:292
dlq_createSQue
void dlq_createSQue(dlq_hdrT *queAddr)
create a static queue header
Definition: dlq.c:177
ERR_INTERNAL_VAL
@ ERR_INTERNAL_VAL
004
Definition: status_enum.h:194
TK_TT_NEWLINE
@ TK_TT_NEWLINE
is significant in conf files
Definition: tk.h:336
ncx_valid_name
boolean ncx_valid_name(const xmlChar *str, uint32 len)
Check if an xmlChar string is a valid YANG identifier value.
Definition: ncx.c:7596
dlq_remove
void dlq_remove(void *nodeP)
remove the queue entry from its queue list entry MUST have been enqueued somehow before this function...
Definition: dlq.c:519
TK_FL_ORIGVAL_MALLOC
#define TK_FL_ORIGVAL_MALLOC
== 1: ORIGVAL malloc: the tk->origval field is malloced == 0: ORIGVAL buffer: tk->origval points to t...
Definition: tk.h:266
NCX_MAX_DCHAR
#define NCX_MAX_DCHAR
max decimal digits in a plain int
Definition: ncxconst.h:429
TK_DOCMODE
#define TK_DOCMODE(TKC)
return non-zero if token preservation docmode
Definition: tk.h:197
NCX_BT_INT64
@ NCX_BT_INT64
int64
Definition: ncxtypes.h:210
TK_TT_HNUM
@ TK_TT_HNUM
hex number
Definition: tk.h:332
TK_FL_BINARYMODE
#define TK_FL_BINARYMODE
== 1: BINARY mode: the tkc->buff buffer is allowed to contain binary characters == 0: TEXT mode: the ...
Definition: tk.h:242
ERR_NCX_UNENDED_QSTRING
@ ERR_NCX_UNENDED_QSTRING
239
Definition: status_enum.h:278
NCX_BT_EMPTY
@ NCX_BT_EMPTY
empty
Definition: ncxtypes.h:205
NCX_BT_UINT16
@ NCX_BT_UINT16
uint16
Definition: ncxtypes.h:212
tk_getline_fn_t
status_t(* tk_getline_fn_t)(xmlChar *fillbuff, uint32 fillbuffsize, void *cookie)
callback function to read a line into a buffer
Definition: tk.h:408
ERR_INTERNAL_MEM
@ ERR_INTERNAL_MEM
003
Definition: status_enum.h:193
tk_origstr_t_::str
xmlChar * str
original string
Definition: tk.h:366
xml_strncmp
int xml_strncmp(const xmlChar *s1, const xmlChar *s2, uint32 maxlen)
String compare for xmlChar for at most 'maxlen' xmlChars.
Definition: xml_util.c:1824
tk_chain_t_::flags
uint32 flags
parser state flags
Definition: tk.h:428
tk_setup_chain_feature
void tk_setup_chain_feature(tk_chain_t *tkc, xmlChar *str)
Setup a previously allocated chain for 'if-feature' YANG 1.1.
Definition: tk.c:3021
tk_chain_t_::linenum
uint32 linenum
current line number
Definition: tk.h:426
ERR_INTERNAL_PTR
@ ERR_INTERNAL_PTR
002
Definition: status_enum.h:192
TK_ORIGSTR_DQUOTE_NL
@ TK_ORIGSTR_DQUOTE_NL
souble quote + newline
Definition: tk.h:353
tk_setup_chain_fields
void tk_setup_chain_fields(tk_chain_t *tkc, xmlChar *str)
Setup a previously allocated chain for 'fields' RESTCONF query parameter str value.
Definition: tk.c:2997
NCX_BT_CONTAINER
@ NCX_BT_CONTAINER
internal container
Definition: ncxtypes.h:225
TK_TT_MINUS
@ TK_TT_MINUS
minus char '-'
Definition: tk.h:302
typ.h
Parameter Type Handler.
TK_CUR_STR
#define TK_CUR_STR(T)
return TRUE if the current token type is a string
Definition: tk.h:140
tk_get_btype_sym
const char * tk_get_btype_sym(ncx_btype_t btyp)
Get the symbolic token symbol for one of the base types.
Definition: tk.c:3324
dlq_count
unsigned int dlq_count(const dlq_hdrT *listP)
get the number of queue entries in the listP queue list
Definition: dlq.c:994
TK_TT_NOTEQUAL
@ TK_TT_NOTEQUAL
not equal '!='
Definition: tk.h:310
tk_add_id_token
status_t tk_add_id_token(tk_chain_t *tkc, const xmlChar *valstr)
Allocatate a new ID token and add it to the parse chain.
Definition: tk.c:4131
TK_TT_LINE
@ TK_TT_LINE
raw command line
Definition: tk.h:317
ERR_NCX_EOF
@ ERR_NCX_EOF
244
Definition: status_enum.h:283
dlq_nextEntry
#define dlq_nextEntry(nodeP)
get the next queue entry after the current entry
Definition: dlq.h:265
tk_dump_token
void tk_dump_token(const tk_token_t *tk)
Debug printf the specified token !!! Very verbose !!!
Definition: tk.c:3492
ERR_NCX_INVALID_NAME
@ ERR_NCX_INVALID_NAME
228
Definition: status_enum.h:267
TK_TT_RPAREN
@ TK_TT_RPAREN
right paren ')'
Definition: tk.h:290
tk_get_token_sym
const char * tk_get_token_sym(tk_type_t ttyp)
Get the symbolic token symbol.
Definition: tk.c:3302
ERR_NCX_UNENDED_BLOCK
@ ERR_NCX_UNENDED_BLOCK
386
Definition: status_enum.h:429
TK_TT_BAR
@ TK_TT_BAR
bar '|'
Definition: tk.h:295
tk_reset_chain
void tk_reset_chain(tk_chain_t *tkc)
Reset the token chain current pointer to the start.
Definition: tk.c:4042
TK_TT_LBRACK
@ TK_TT_LBRACK
left bracket '['
Definition: tk.h:291
tk_cur_is_first
boolean tk_cur_is_first(const tk_chain_t *tkc)
Check if the current token is the first token.
Definition: tk.c:4596
tk_next_is_null
boolean tk_next_is_null(tk_chain_t *tkc)
Get the special sequence [null] is next.
Definition: tk.c:3411
tk_token_t_::modlen
uint32 modlen
length of 'mod'; not Z-string!
Definition: tk.h:375
tk_origstr_t_::qhdr
dlq_hdr_t qhdr
queue header
Definition: tk.h:364
TK_TT_SEMICOL
@ TK_TT_SEMICOL
semi-colon ';'
Definition: tk.h:288
tk_setup_chain_cli
void tk_setup_chain_cli(tk_chain_t *tkc, xmlChar *line)
Setup a previously allocated chain for a CLI command line.
Definition: tk.c:2970
TK_SOURCE_CONF
@ TK_SOURCE_CONF
config file
Definition: tk.h:338
tk_is_wsp_string
boolean tk_is_wsp_string(const tk_token_t *tk)
Check if the current token is a string with whitespace in it.
Definition: tk.c:3582
ERR_NCX_BINARY_FILE
@ ERR_NCX_BINARY_FILE
395
Definition: status_enum.h:438
NCX_BT_UNION
@ NCX_BT_UNION
union (needs special processing)
Definition: ncxtypes.h:220
tk_chain_t_::cur
tk_token_t * cur
current token pointer
Definition: tk.h:419
tk_tokenize_metadata_string
tk_chain_t * tk_tokenize_metadata_string(ncx_module_t *mod, xmlChar *str, status_t *res)
The specified ncx:metadata string is parsed into tokens convert the ncx:metadata content to 1 or 2 to...
Definition: tk.c:3938
ERR_NCX_INVALID_NUM
@ ERR_NCX_INVALID_NUM
241
Definition: status_enum.h:280
tk_chain_t_::buff
xmlChar * buff
buffer when source is buffer
Definition: tk.h:424
NCX_BT_ANY
@ NCX_BT_ANY
anyxml
Definition: ncxtypes.h:202
NCX_BT_SLIST
@ NCX_BT_SLIST
ncx:xsdlist extension (internal, deprecated)
Definition: ncxtypes.h:223
NCX_COMMENT_CH
#define NCX_COMMENT_CH
start of comment token in all NCX text
Definition: ncxconst.h:398
EMPTY_STRING
#define EMPTY_STRING
empty string used to get const xmlChar * cast
Definition: ncxconst.h:289
TK_ORIGSTR_SQUOTE_NL
@ TK_ORIGSTR_SQUOTE_NL
single quote + newline
Definition: tk.h:355
TK_TT_EQUAL
@ TK_TT_EQUAL
equal sign '='
Definition: tk.h:294
tk_chain_t_::fp
FILE * fp
file when source is file
Definition: tk.h:423
xml_strcmp
int xml_strcmp(const xmlChar *s1, const xmlChar *s2)
String compare for xmlChar.
Definition: xml_util.c:1746
TK_TT_STRING
@ TK_TT_STRING
unquoted string
Definition: tk.h:316
ERR_NCX_LEN_EXCEEDED
@ ERR_NCX_LEN_EXCEEDED
237
Definition: status_enum.h:276
ncx_valid_name_ch
boolean ncx_valid_name_ch(uint32 ch)
Check if the character is a valid YANG identifier chara.
Definition: ncx.c:7549
TK_TT_LBRACE
@ TK_TT_LBRACE
left brace '{'
Definition: tk.h:286
TK_TT_QVARBIND
@ TK_TT_QVARBIND
XPath varbind '$prefix:NCName'.
Definition: tk.h:326
LOGDEBUG4
#define LOGDEBUG4
Check if at least log-level=debug4.
Definition: log.h:302
log.h
NCX System Logging Manager.
tk_token_t_::val
xmlChar * val
value string for token if buffer too snall
Definition: tk.h:376
ncxtypes.h
YANG module data structures Many internal representations of YANG module constructs.
TK_TT_LT
@ TK_TT_LT
less than char '<'
Definition: tk.h:303
tk_next_typ2
tk_type_t tk_next_typ2(tk_chain_t *tkc)
Get the token type of the token after the next token.
Definition: tk.c:3374
tk_token_t_::qhdr
dlq_hdr_t qhdr
queue header
Definition: tk.h:372
NCX_SCOPE_CH
#define NCX_SCOPE_CH
scoped identifier field separator token
Definition: ncxconst.h:401
TK_TT_GEQUAL
@ TK_TT_GEQUAL
greater than or equal '>='
Definition: tk.h:312
NCX_BT_BITS
@ NCX_BT_BITS
bits
Definition: ncxtypes.h:203
NCX_BT_FLOAT64
@ NCX_BT_FLOAT64
hidden: just for XPath
Definition: ncxtypes.h:216
NCX_BT_UINT32
@ NCX_BT_UINT32
uint32
Definition: ncxtypes.h:213
dlq_deque
void * dlq_deque(dlq_hdrT *listP)
remove the first queue node from the queue list
Definition: dlq.c:286
tk_add_lbrace_token
status_t tk_add_lbrace_token(tk_chain_t *tkc)
Allocatate a new left brace token and add it to the parse chain.
Definition: tk.c:4266
TK_TT_GT
@ TK_TT_GT
greater than char '>'
Definition: tk.h:304
tk_tokenize_input
status_t tk_tokenize_input(tk_chain_t *tkc, ncx_module_t *mod)
Parse the input (FILE or buffer) into tk_token_t structs.
Definition: tk.c:3641
dlq_empty
#define dlq_empty(listP)
check if queue list is empty
Definition: dlq.h:367
tk_get_yang_btype_id
ncx_btype_t tk_get_yang_btype_id(const xmlChar *buff, uint32 len)
Check if the specified string is a YANG builtin type name checks for valid YANG data type name.
Definition: tk.c:3241
ncx_get_max_strlen
int32 ncx_get_max_strlen(void)
Get the –max-strlen parameter.
Definition: ncx.c:14799
xml_strcpy
uint32 xml_strcpy(xmlChar *copyTo, const xmlChar *copyFrom)
String copy for xmlChar.
Definition: xml_util.c:1486
TK_TT_RANGESEP
@ TK_TT_RANGESEP
range sep, parent node '..'
Definition: tk.h:307
tk_token_t_::linepos
uint32 linepos
token source line osition
Definition: tk.h:380
TK_TT_MSSTRING
@ TK_TT_MSSTRING
module-qualified scoped string
Definition: tk.h:321
tk_token_t_::flags
uint8 flags
parsing state flags
Definition: tk.h:384
dlq_firstEntry
#define dlq_firstEntry(listP)
get the first entry in the queue list
Definition: dlq.h:337
tk_token_ptr_t_::tk
tk_token_t * tk
token
Definition: tk.h:393
ncx.h
YANG module utility functions.
TK_SOURCE_XPATH
@ TK_SOURCE_XPATH
XPath.
Definition: tk.h:340
tk_setup_chain_json_buffer
void tk_setup_chain_json_buffer(tk_chain_t *tkc, xmlChar *buff)
Setup a previously allocated chain for a JSON buffer.
Definition: tk.c:3116
TK_TT_QSTRING
@ TK_TT_QSTRING
double quoted string
Definition: tk.h:322
NCX_MAX_STRLEN
#define NCX_MAX_STRLEN
Maximum string length (2^^31 - 1)
Definition: ncxconst.h:435
tk_type_t_
tk_type_t_
different types of tokens parsed during 1st pass
Definition: tk.h:279
TK_TT_VARBIND
@ TK_TT_VARBIND
XPath varbind '$NCName'.
Definition: tk.h:325
tk_setup_chain_cli_line
void tk_setup_chain_cli_line(tk_chain_t *tkc, xmlChar *str)
Setup a previously allocated chain for yangcli CLI line of input.
Definition: tk.c:3181
tk_chain_t_::tkptrQ
dlq_hdr_t tkptrQ
Q of tk_token_ptr_t.
Definition: tk.h:418
TK_TT_NCNAME_STAR
@ TK_TT_NCNAME_STAR
XPath NCName:* sequence.
Definition: tk.h:328
NCX_BT_EXTERN
@ NCX_BT_EXTERN
not a real type, points fo file for contents
Definition: ncxtypes.h:230
tk_token_ptr_t_::qhdr
dlq_hdr_t qhdr
queue header
Definition: tk.h:392
dlq_enque
void dlq_enque(REG void *newP, REG dlq_hdrT *listP)
add a queue node to the end of a queue list Add newP to listP
Definition: dlq.c:246
tk_origstr_t_::origtyp
tk_origstr_typ_t origtyp
original source type
Definition: tk.h:365
TK_TYP_STR
#define TK_TYP_STR(T)
return TRUE if the specified token type is a string
Definition: tk.h:144
ERR_NCX_INVALID_HEXNUM
@ ERR_NCX_INVALID_HEXNUM
242
Definition: status_enum.h:281
SET_ERROR
#define SET_ERROR(E)
macro SET_ERROR
Definition: status_enum.h:103
tk_chain_t_::qhdr
dlq_hdr_t qhdr
queue header
Definition: tk.h:416
TK_SOURCE_REDO
@ TK_SOURCE_REDO
redo internal mode
Definition: tk.h:341
tk_setup_chain_yang
void tk_setup_chain_yang(tk_chain_t *tkc, FILE *fp, const xmlChar *filename)
Setup a previously allocated chain for a YANG file.
Definition: tk.c:3046
tk_chain_t_::escerr_tk
tk_token_t * escerr_tk
backptr into tkQ
Definition: tk.h:420
val_need_quotes
boolean val_need_quotes(const xmlChar *str)
Check if a string needs to be quoted to be output within a conf file or ncxcli stdout output.
Definition: val.c:11685
tk_token_count
uint32 tk_token_count(const tk_chain_t *tkc)
Get the number of tokens in the queue.
Definition: tk.c:4017
NCX_BT_DECIMAL64
@ NCX_BT_DECIMAL64
decimal64
Definition: ncxtypes.h:215
tk_origstr_typ_t_
tk_origstr_typ_t_
preserve the original string type
Definition: tk.h:350
TK_TT_ATSIGN
@ TK_TT_ATSIGN
at sign '@'
Definition: tk.h:297
NCX_BT_CHOICE
@ NCX_BT_CHOICE
internal choice, not really used
Definition: ncxtypes.h:226
NCX_BT_STRING
@ NCX_BT_STRING
string
Definition: ncxtypes.h:217
tk_token_t_::nsid
xmlns_id_t nsid
only used for TK_TT_MSTRING tokens
Definition: tk.h:381
TK_TT_PERIOD
@ TK_TT_PERIOD
period char '.
Definition: tk.h:300
dlq_block_insertAfter
void dlq_block_insertAfter(dlq_hdrT *srcP, void *dstP)
insert all the entries in the srcP queue list after the dstP queue entry
Definition: dlq.c:863
NCX_BT_INT8
@ NCX_BT_INT8
int8
Definition: ncxtypes.h:207
tk_first_origstr_rec
const tk_origstr_t * tk_first_origstr_rec(const tk_token_ptr_t *tkptr)
Get the first tk_origstr_t struct (if any)
Definition: tk.c:4450
xmlns.h
XML namespace support.
TK_TT_MSTRING
@ TK_TT_MSTRING
module-qualified token string
Definition: tk.h:320
status.h
Global error messages for status code enumerations.
NCX_BT_NONE
@ NCX_BT_NONE
base type not set
Definition: ncxtypes.h:201
NCX_MAX_RCHAR
#define NCX_MAX_RCHAR
max digits in a real number
Definition: ncxconst.h:432
tk_chain_t_::cookie
void * cookie
getline callback cookie
Definition: tk.h:431
dlq.h
dlq provides general double-linked list and queue support:
NCX_IS_HEX_CH
#define NCX_IS_HEX_CH(c)
Standard 0x0 syntax to indicate a HEX number is specified.
Definition: ncxconst.h:419
LOGDEBUG3
#define LOGDEBUG3
Check if at least log-level=debug3.
Definition: log.h:297
TK_TT_SSTRING
@ TK_TT_SSTRING
scoped token string
Definition: tk.h:318
tk_add_pid_token
status_t tk_add_pid_token(tk_chain_t *tkc, const xmlChar *prefix, uint32 prefixlen, const xmlChar *valstr)
Allocatate a new prefixed ID token and add it to the parse chain.
Definition: tk.c:4175
tk_tkptr_quotes
uint32 tk_tkptr_quotes(const tk_token_ptr_t *tkptr)
Get the specified token pointer record token ID type Use the first string or only string.
Definition: tk.c:4567
NCX_BT_INT16
@ NCX_BT_INT16
int16
Definition: ncxtypes.h:208