yumapro  23.10T-10
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 - 2024, 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
271extern yangapi_param_t *
273
274
282extern yangapi_param_t *
284
285
296extern status_t
298 rpc_msg_t *msg,
299 yangapi_cb_t *rcb);
300
301
323extern status_t
325 rpc_msg_t *msg,
326 yangapi_cb_t *rcb,
327 val_value_t *root,
328 const xmlChar *path);
329
330
344extern status_t
346 yangapi_cb_t *rcb,
347 rpc_msg_t *msg,
348 int content_len);
349
350
367extern status_t
369 yangapi_cb_t *rcb,
370 rpc_msg_t *msg);
371
372
380extern boolean
382
383
394extern status_t
396 yangapi_cb_t *rcb,
397 rpc_msg_t *msg);
398
399
412extern status_t
414 yangapi_cb_t *rcb,
415 rpc_msg_t *msg);
416
417
427extern boolean
429
430
443extern status_t
445 getcb_mode_t cbmode,
446 const val_value_t *virval,
447 val_value_t *dstval);
448
449
456extern int
458
459
474extern status_t
476 yangapi_cb_t *rcb,
477 rpc_msg_t *msg);
478
479
493extern status_t
495 yangapi_cb_t *rcb,
496 rpc_msg_t *msg,
497 const xmlChar *parmname);
498
499
506extern yangapi_method_t
507 agt_restcmn_get_method (const xmlChar *method);
508
509
516extern boolean
518
519
520
554extern boolean
556 yangapi_cb_t *rcb,
557 rpc_msg_t *msg,
558 boolean error_recorded,
559 status_t *res);
560
561
568extern xmlns_id_t
570
571
577extern void
579
580
587extern void
589 yangapi_cb_t *rcb);
590
591
601extern boolean
603 val_value_t *context_node);
604
605
612extern val_value_t *
614
615
627extern xmlChar *
629 const xmlChar *target,
630 const xmlChar *edit_target);
631
632
640extern xmlChar *
641 agt_restcmn_decode_url (const xmlChar *url,
642 status_t *res);
643
644
656extern void
658 rpc_msg_t *msg,
659 status_t res,
660 obj_template_t *errobj,
661 const xmlChar *badval);
662
663
673extern void
675 xml_msg_hdr_t *mhdr,
676 status_t res,
677 val_value_t *errnode,
678 const xmlChar *badval);
679
680
692extern void
694 xml_msg_hdr_t *mhdr,
695 status_t res,
696 val_value_t *errnode,
697 const xmlChar *badval,
698 const ncx_errinfo_t *errinfo);
699
700
711extern void
713 xml_msg_hdr_t *mhdr,
714 status_t res,
715 obj_template_t *errobj,
716 const xmlChar *badval);
717
718
729extern void
731 xml_msg_hdr_t *mhdr,
732 status_t res,
733 val_value_t *errval,
734 const xmlChar *badval);
735
736
742extern const xmlChar *
744
745
754extern void
756
757
767extern status_t
769 rpc_msg_t *msg,
770 yangapi_cb_t *rcb);
771
772
780extern val_value_t *
782
786#ifdef __cplusplus
787} /* end extern 'C' */
788#endif
789
790#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:6722
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:5828
yangapi_param_t * agt_restcmn_get_first_param(yangapi_cb_t *rcb)
Get the first query parameter entry from the parameter queue.
Definition: agt_restcmn.c:4185
xmlns_id_t agt_restcmn_get_nsid(ncx_protocol_t proto)
Get the XML namespace ID for specific proto.
Definition: agt_restcmn.c:7180
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:5695
boolean agt_restcmn_method_is_read(yangapi_method_t method)
Check if this is a read method.
Definition: agt_restcmn.c:6658
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:5782
val_value_t * get_active_root(yangapi_cb_t *rcb)
Select the active CFG and return its root val.
Definition: agt_restcmn.c:8032
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:6005
int agt_restcmn_get_content_len(yangapi_cb_t *rcb)
Get the content length for the input request message body.
Definition: agt_restcmn.c:6237
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:6270
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:4773
const xmlChar * agt_restcmn_entry_point(void)
Get the RESTCONF entry point name.
Definition: agt_restcmn.c:7819
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:7663
yangapi_param_t * agt_restcmn_get_next_param(yangapi_param_t *param)
Get the next query parameter entry from the parameter queue.
Definition: agt_restcmn.c:4206
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:7619
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:4042
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:7840
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:5894
xmlChar * agt_restcmn_decode_url(const xmlChar *url, status_t *res)
Decode URL encoded string value into string.
Definition: agt_restcmn.c:7559
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:4156
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:6598
yangapi_method_t agt_restcmn_get_method(const xmlChar *method)
Get the HTTP method enum from the string.
Definition: agt_restcmn.c:6623
boolean agt_restcmn_operation_supports_json(obj_template_t *rpcobj)
Check if the NETCONF operation supports JSON output.
Definition: agt_restcmn.c:6151
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:7427
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:7694
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:6182
const xmlChar * get_launchpoint_name(yangapi_launchpt_t launchpt)
Get the keyword for the specified launchpt.
Definition: agt_restcmn.c:3949
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:7726
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:7941
void agt_restcmn_print_debug_line(ses_cb_t *scb, yangapi_cb_t *rcb)
Print the message received debug line.
Definition: agt_restcmn.c:7244
xmlChar * agt_restcmn_make_uri(ses_cb_t *scb, const xmlChar *target, const xmlChar *edit_target)
Make a URI string.
Definition: agt_restcmn.c:7496
status_t agt_restcmn_parse_fragment(yangapi_cb_t *rcb, xmlChar *uri, uint32 *retlen)
parse the request URI fragment
Definition: agt_restcmn.c:4005
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:7775
void agt_restcmn_free_msg(rpc_msg_t *msg)
Free an rpc_msg_t.
Definition: agt_restcmn.c:7226
val_value_t * agt_restcmn_new_config_wrapper(void)
Create a <config> wrapper val and return it.
Definition: agt_restcmn.c:7458
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:4236
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:912
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:241
YANG-API Query string parameter.
Definition: yangapi.h:183
YANG Patch Media Type.
YANG-API definitions (pre-RESTCONF)