yumapro  23.10T-8
YumaPro SDK
Loading...
Searching...
No Matches
agt_restcmn.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 - 2012, Andy Bierman, All Rights Reserved.
3 * Copyright (c) 2012 - 2023, 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_agt_restcmn
13#define _H_agt_restcmn
14
15
16/* FILE: agt_restcmn.h
17*********************************************************************
18* *
19* P U R P O S E *
20* *
21*********************************************************************/
22
29/*********************************************************************
30* *
31* C H A N G E H I S T O R Y *
32* *
33*********************************************************************
34
35date init comment
36----------------------------------------------------------------------
3730-jul-15 abb Begun.
38
39
40*********************************************************************
41* *
42* I N C L U D E F I L E S *
43* *
44*********************************************************************/
45
46#ifndef _H_ses
47#include "ses.h"
48#endif
49
50#ifndef _H_status
51#include "status.h"
52#endif
53
54#ifndef _H_yangapi
55#include "yangapi.h"
56#endif
57
58#ifndef _H_yang_patch
59#include "yang_patch.h"
60#endif
61
62#ifndef _H_getcb
63#include "getcb.h"
64#endif
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70
71/********************************************************************
72* *
73* C O N S T A N T S *
74* *
75*********************************************************************/
76/* YANG-API specific consts */
77#define YANG_API_MODULE NCXMOD_YANG_API
78#define YANGAPI_WRAPPER_NODE NCX_EL_DATA
79#define YANGPATCH_WRAPPER_NODE (const xmlChar *)"yang-patch-status"
80#define YANG_API_REVISION NULL
81
82#define YANG_API_ROOT (const xmlChar *)"yang-api"
83#define YANG_API_VERSION (const xmlChar *)"1.0"
84#define YANG_YANG \
85 (const xmlChar *)"Please specify module name and revision"
86
87/* RESTCONF specific const */
88#define RESTCONF_REVISION (const xmlChar *)"2017-01-26"
89#define RESTCONF_YUMA_REVISION (const xmlChar *)"2015-12-03"
90
91#define RESTCONF_ROOT (const xmlChar *)"restconf"
92#define RESTCONF_QMAX (const xmlChar *)"1.0"
93
94#define RESTCONF_CONTENT_JSON (const xmlChar *)"application/json"
95#define RESTCONF_CONTENT_XML (const xmlChar *)"application/xml"
96#define RESTCONF_CONTENT_TEXT_XML (const xmlChar *)"text/xml"
97#define RESTCONF_DEF_ACCEPT_TYPE (const xmlChar *)"application/yang-data"
98#define RESTCONF_HEADER_WILDCARD (const xmlChar *)"*/*"
99
100/* YANG-PATCH const */
101#define RESTCONF_CONTENT_PATCH_XML \
102 (const xmlChar *)"application/yang-patch+xml"
103#define RESTCONF_CONTENT_PATCH_JSON \
104 (const xmlChar *)"application/yang-patch+json"
105
106/* common consts */
107
108/* used by parse_path to URL decode a key value inline
109 * instead of mallocing the buffer
110 */
111#define TEMP_BUFF_SIZE 1024
112
113#define YL_FS_SEP (const xmlChar *)"/"
114
115#define YANG_XRD_MEDIA (const xmlChar *)"application/xrd"
116#define YANG_YANG_MEDIA (const xmlChar *)"application/yang"
117#define YANG_EVENT_MEDIA (const xmlChar *)"text/event"
118#define YANG_STREAM_SUBMEDIA (const xmlChar *)"stream"
119#define YANG_PATCH_SUBMEDIA (const xmlChar *)"patch"
120#define YANG_DATA_SUBMEDIA (const xmlChar *)"data"
121#define YANG_XRD_SUBMEDIA (const xmlChar *)"xrd"
122
123
124#define RESTCONF_YANG_SCHEMA (const xmlChar *)"schema"
125/*
126Depricated
127#define YANG_API_SUBMEDIA (const xmlChar *)"api"
128#define YANG_DATASTORE_SUBMEDIA (const xmlChar *)"datastore"
129#define YANG_OPERATION_SUBMEDIA (const xmlChar *)"operation"
130#define YANG_ERRORS_SUBMEDIA (const xmlChar *)"errors"
131#define YANG_PATCHSTAT_SUBMEDIA (const xmlChar *)"patch-status"
132#define YANG_PATCHSTAT_MEDIA (const xmlChar *)"application/yang.patch-status"
133*/
134
135
136/* heading only */
137
138
139
161/********************************************************************
162* *
163* T Y P E S *
164* *
165*********************************************************************/
166
170typedef struct agt_yangapi_context_t_ {
174 uint32 cap_changes;
175 uint32 requests;
179
180
183typedef struct agt_restconf_data_t_ {
188 uint32 cap_changes;
189 uint32 requests;
193
194
195
196/********************************************************************
197* *
198* F U N C T I O N S *
199* *
200*********************************************************************/
201
202
209extern const xmlChar *
211
212
222extern status_t
224 xmlChar *uri,
225 uint32 *retlen);
226
227
239extern status_t
241 rpc_msg_t *msg,
242 yangapi_cb_t *rcb,
243 xmlChar *uri,
244 uint32 *retlen);
245
246
258extern xmlChar *
260 const xmlChar *name,
261 boolean *found);
262
263
274extern status_t
276 rpc_msg_t *msg,
277 yangapi_cb_t *rcb);
278
279
301extern status_t
303 rpc_msg_t *msg,
304 yangapi_cb_t *rcb,
305 val_value_t *root,
306 const xmlChar *path);
307
308
322extern status_t
324 yangapi_cb_t *rcb,
325 rpc_msg_t *msg,
326 int content_len);
327
328
345extern status_t
347 yangapi_cb_t *rcb,
348 rpc_msg_t *msg);
349
350
358extern boolean
360
361
372extern status_t
374 yangapi_cb_t *rcb,
375 rpc_msg_t *msg);
376
377
390extern status_t
392 yangapi_cb_t *rcb,
393 rpc_msg_t *msg);
394
395
405extern boolean
407
408
421extern status_t
423 getcb_mode_t cbmode,
424 const val_value_t *virval,
425 val_value_t *dstval);
426
427
434extern int
436
437
452extern status_t
454 yangapi_cb_t *rcb,
455 rpc_msg_t *msg);
456
457
471extern status_t
473 yangapi_cb_t *rcb,
474 rpc_msg_t *msg,
475 const xmlChar *parmname);
476
477
484extern yangapi_method_t
485 agt_restcmn_get_method (const xmlChar *method);
486
487
494extern boolean
496
497
498
532extern boolean
534 yangapi_cb_t *rcb,
535 rpc_msg_t *msg,
536 boolean error_recorded,
537 status_t *res);
538
539
546extern xmlns_id_t
548
549
555extern void
557
558
565extern void
567 yangapi_cb_t *rcb);
568
569
579extern boolean
581 val_value_t *context_node);
582
583
590extern val_value_t *
592
593
605extern xmlChar *
607 const xmlChar *target,
608 const xmlChar *edit_target);
609
610
618extern xmlChar *
619 agt_restcmn_decode_url (const xmlChar *url,
620 status_t *res);
621
622
634extern void
636 rpc_msg_t *msg,
637 status_t res,
638 obj_template_t *errobj,
639 const xmlChar *badval);
640
641
651extern void
653 xml_msg_hdr_t *mhdr,
654 status_t res,
655 val_value_t *errnode,
656 const xmlChar *badval);
657
658
670extern void
672 xml_msg_hdr_t *mhdr,
673 status_t res,
674 val_value_t *errnode,
675 const xmlChar *badval,
676 const ncx_errinfo_t *errinfo);
677
678
689extern void
691 xml_msg_hdr_t *mhdr,
692 status_t res,
693 obj_template_t *errobj,
694 const xmlChar *badval);
695
696
707extern void
709 xml_msg_hdr_t *mhdr,
710 status_t res,
711 val_value_t *errval,
712 const xmlChar *badval);
713
714
720extern const xmlChar *
722
723
732extern void
734
735
745extern status_t
747 rpc_msg_t *msg,
748 yangapi_cb_t *rcb);
749
750
758extern val_value_t *
760
764#ifdef __cplusplus
765} /* end extern 'C' */
766#endif
767
768#endif /* _H_agt_restcmn */
GET1 and GET2 Callback Support.
boolean agt_restcmn_validate_accept_header(ses_cb_t *scb, yangapi_cb_t *rcb, rpc_msg_t *msg, boolean error_recorded, status_t *res)
Validate the client Accept header.
Definition: agt_restcmn.c:6705
boolean agt_restcmn_check_unmodified_return(yangapi_cb_t *rcb)
Check if the context node(s) will match the filters (if any)
Definition: agt_restcmn.c:5811
xmlns_id_t agt_restcmn_get_nsid(ncx_protocol_t proto)
Get the XML namespace ID for specific proto.
Definition: agt_restcmn.c:7163
status_t agt_restcmn_get_http_input(ses_cb_t *scb, yangapi_cb_t *rcb, rpc_msg_t *msg, int content_len)
Get the input from the session input buffers and parse it as the specified target object type.
Definition: agt_restcmn.c:5678
boolean agt_restcmn_method_is_read(yangapi_method_t method)
Check if this is a read method.
Definition: agt_restcmn.c:6641
status_t agt_restcmn_set_content_encoding(ses_cb_t *scb, yangapi_cb_t *rcb, rpc_msg_t *msg)
Get the content encoding used.
Definition: agt_restcmn.c:5765
val_value_t * get_active_root(yangapi_cb_t *rcb)
Select the active CFG and return its root val.
Definition: agt_restcmn.c:8015
status_t agt_restcmn_setup_read_params(ses_cb_t *scb, yangapi_cb_t *rcb, rpc_msg_t *msg)
Setup the message parameters from the yangapi_cb values.
Definition: agt_restcmn.c:5988
int agt_restcmn_get_content_len(yangapi_cb_t *rcb)
Get the content length for the input request message body.
Definition: agt_restcmn.c:6220
status_t agt_restcmn_validate_method(ses_cb_t *scb, yangapi_cb_t *rcb, rpc_msg_t *msg)
validate that the method is supported for the URI given.
Definition: agt_restcmn.c:6253
status_t agt_restcmn_parse_path(ses_cb_t *scb, rpc_msg_t *msg, yangapi_cb_t *rcb, val_value_t *root, const xmlChar *path)
parse the request URI path
Definition: agt_restcmn.c:4756
const xmlChar * agt_restcmn_entry_point(void)
Get the RESTCONF entry point name.
Definition: agt_restcmn.c:7802
void agt_restcmn_record_error(ses_cb_t *scb, xml_msg_hdr_t *mhdr, status_t res, val_value_t *errnode, const xmlChar *badval)
Record an rpc-error for YANG-API/RESTCONF response translation.
Definition: agt_restcmn.c:7646
void agt_restcmn_record_obj_error(ses_cb_t *scb, rpc_msg_t *msg, status_t res, obj_template_t *errobj, const xmlChar *badval)
Record an rpc-error for YANG-API/RESTCONF response translation the error node is an object,...
Definition: agt_restcmn.c:7602
status_t agt_restcmn_parse_query_string(ses_cb_t *scb, rpc_msg_t *msg, yangapi_cb_t *rcb, xmlChar *uri, uint32 *retlen)
parse the request URI query string
Definition: agt_restcmn.c:4076
void agt_restcmn_setup_launch_point(yangapi_cb_t *rcb)
check the parseed request URI path set the API launch point data
Definition: agt_restcmn.c:7823
status_t agt_restcmn_setup_notifications(ses_cb_t *scb, yangapi_cb_t *rcb, rpc_msg_t *msg)
setup the notification delivery on this GET request
Definition: agt_restcmn.c:5877
xmlChar * agt_restcmn_decode_url(const xmlChar *url, status_t *res)
Decode URL encoded string value into string.
Definition: agt_restcmn.c:7542
xmlChar * agt_restcmn_get_param(yangapi_cb_t *rcb, const xmlChar *name, boolean *found)
Find a query parameter and return its value.
Definition: agt_restcmn.c:4190
status_t agt_restcmn_check_metpar_error(ses_cb_t *scb, yangapi_cb_t *rcb, rpc_msg_t *msg, const xmlChar *parmname)
validate that the URI parameters given are supported for the method
Definition: agt_restcmn.c:6581
yangapi_method_t agt_restcmn_get_method(const xmlChar *method)
Get the HTTP method enum from the string.
Definition: agt_restcmn.c:6606
boolean agt_restcmn_operation_supports_json(obj_template_t *rpcobj)
Check if the NETCONF operation supports JSON output.
Definition: agt_restcmn.c:6134
boolean agt_restcmn_get_config_parm(yangapi_cb_t *rcb, val_value_t *context_node)
Get the value of the config parm to use.
Definition: agt_restcmn.c:7410
void agt_restcmn_record_error_errinfo(ses_cb_t *scb, xml_msg_hdr_t *mhdr, status_t res, val_value_t *errnode, const xmlChar *badval, const ncx_errinfo_t *errinfo)
Record an rpc-error for YANG-API/RESTCONF response translation.
Definition: agt_restcmn.c:7677
status_t agt_restcmn_get_operations(ses_cb_t *scb, getcb_mode_t cbmode, const val_value_t *virval, val_value_t *dstval)
GET1 operation handler for the /operations container.
Definition: agt_restcmn.c:6165
const xmlChar * get_launchpoint_name(yangapi_launchpt_t launchpt)
Get the keyword for the specified launchpt.
Definition: agt_restcmn.c:3983
void agt_restcmn_obj_error(ses_cb_t *scb, xml_msg_hdr_t *mhdr, status_t res, obj_template_t *errobj, const xmlChar *badval)
Record an rpc-error for YANG-API/RESTCONF response translation.
Definition: agt_restcmn.c:7709
status_t agt_rescmn_setup_action_request(ses_cb_t *scb, rpc_msg_t *msg, yangapi_cb_t *rcb)
Setup the data needed to invoke a YANG action.
Definition: agt_restcmn.c:7924
void agt_restcmn_print_debug_line(ses_cb_t *scb, yangapi_cb_t *rcb)
Print the message received debug line.
Definition: agt_restcmn.c:7227
xmlChar * agt_restcmn_make_uri(ses_cb_t *scb, const xmlChar *target, const xmlChar *edit_target)
Make a URI string.
Definition: agt_restcmn.c:7479
status_t agt_restcmn_parse_fragment(yangapi_cb_t *rcb, xmlChar *uri, uint32 *retlen)
parse the request URI fragment
Definition: agt_restcmn.c:4039
void agt_restcmn_val_error(ses_cb_t *scb, xml_msg_hdr_t *mhdr, status_t res, val_value_t *errval, const xmlChar *badval)
Record an rpc-error for YANG-API/RESTCONF response translation.
Definition: agt_restcmn.c:7758
void agt_restcmn_free_msg(rpc_msg_t *msg)
Free an rpc_msg_t.
Definition: agt_restcmn.c:7209
val_value_t * agt_restcmn_new_config_wrapper(void)
Create a <config> wrapper val and return it.
Definition: agt_restcmn.c:7441
status_t agt_restcmn_validate_query_string(ses_cb_t *scb, rpc_msg_t *msg, yangapi_cb_t *rcb)
Validate the parameters in the request URI query string.
Definition: agt_restcmn.c:4224
getcb_mode_t
get callback retrieval types; only get2 supports getnext
Definition: getcb.h:257
yangapi_launchpt_t
describes the type of node indicated by the RequestURI path Used internally in the server to process ...
Definition: yangapi.h:126
yangapi_method_t
HTTP methods used by YANG-API and RESTCONF.
Definition: yangapi.h:111
status_t
global error return code
Definition: status_enum.h:210
uint16 xmlns_id_t
integer handle for registered namespaces
Definition: xmlns.h:89
ncx_protocol_t
NCX session protocol versions supported.
Definition: ncxtypes.h:997
NETCONF Session Common definitions module.
Global error messages for status code enumerations.
RESTCONF structure for data.
Definition: agt_restcmn.h:183
obj_template_t * obj
/restconf container
Definition: agt_restcmn.h:186
ncx_module_t * yuma_mod
yumaworks-restconf module
Definition: agt_restcmn.h:185
boolean restconf_enabled
RESTCONF protocol OK.
Definition: agt_restcmn.h:190
xmlns_id_t mod_nsid
module namespace iD
Definition: agt_restcmn.h:191
uint32 cap_changes
capability set
Definition: agt_restcmn.h:188
uint32 requests
limit in the EVAL_VERSION
Definition: agt_restcmn.h:189
ncx_module_t * mod
ietf-restconf module
Definition: agt_restcmn.h:184
val_value_t * root
template for retrieval
Definition: agt_restcmn.h:187
module context node with cached schema tree and API template for retrieval (root)
Definition: agt_restcmn.h:170
obj_template_t * obj
/yang-api container
Definition: agt_restcmn.h:172
boolean yangapi_enabled
YANG-API protocol OK.
Definition: agt_restcmn.h:176
xmlns_id_t mod_nsid
module namespace ID
Definition: agt_restcmn.h:177
uint32 cap_changes
not used yet
Definition: agt_restcmn.h:174
uint32 requests
limit in the EVAL_VERSION
Definition: agt_restcmn.h:175
ncx_module_t * mod
yang-api module
Definition: agt_restcmn.h:171
val_value_t * root
template for retrieval
Definition: agt_restcmn.h:173
YANG error info statement struct used to override default error handling in the server.
Definition: ncxtypes.h:1362
representation of one module or submodule during and after parsing
Definition: ncxtypes.h:1134
One YANG data-def-stmt.
Definition: obj.h:1220
NETCONF Server and Client RPC Request/Reply Message Header.
Definition: rpc.h:181
Session Control Block.
Definition: ses.h:573
one value to match one type
Definition: val.h:911
Common Encoding Message Header No longer XML specific!! Used by JSON and CBOR parsing as well!...
Definition: xml_msg.h:397
Restapi Control Block Used by RESTCONF to hold parse and request processing state.
Definition: yangapi.h:226
YANG Patch Media Type.
YANG-API definitions (pre-RESTCONF)