yumapro  21.10T-8
YumaPro SDK
agt_rpc.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 - 2012, Andy Bierman, All Rights Reserved.
3  * Copyright (c) 2012 - 2022, 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_rpc
13 #define _H_agt_rpc
14 /* FILE: agt_rpc.h
15 *********************************************************************
16 * *
17 * P U R P O S E *
18 * *
19 *********************************************************************/
20 
27 /*********************************************************************
28 * *
29 * C H A N G E H I S T O R Y *
30 * *
31 *********************************************************************
32 
33 date init comment
34 ----------------------------------------------------------------------
35 30-apr-05 abb Begun.
36 */
37 
38 #ifndef _H_cfg
39 #include "cfg.h"
40 #endif
41 
42 #ifndef _H_rpc
43 #include "rpc.h"
44 #endif
45 
46 #ifndef _H_rpc_err
47 #include "rpc_err.h"
48 #endif
49 
50 #ifndef _H_ses
51 #include "ses.h"
52 #endif
53 
54 #ifndef _H_status_enum
55 #include "status_enum.h"
56 #endif
57 
58 #ifndef _H_xml_util
59 #include "xml_util.h"
60 #endif
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
77 /********************************************************************
78 * *
79 * C O N S T A N T S *
80 * *
81 *********************************************************************/
82 
89 #define AGT_RPC_NUM_CALLBACK_PHASES 3
90 
91 /********************************************************************
92 * *
93 * T Y P E S *
94 * *
95 *********************************************************************/
96 
109 typedef enum agt_rpc_phase_t_ {
112 
115 
118 
121 
125 
126 
146 typedef status_t
148  rpc_msg_t *msg,
149  xml_node_t *methnode);
150 
151 
153 typedef struct agt_rpc_cbset_t_ {
156 
158  boolean regdone;
159 
160 #ifdef WITH_YCONTROL
161  dlq_hdr_t subsysQ;
162 #endif
163 
165 
166 
177 typedef status_t
179  rpc_msg_t *msg,
180  uint32 indent);
181 
182 
187 typedef struct agt_rpc_subsys_t_ {
189  dlq_hdr_t qhdr;
190 
192  const xmlChar *subsys_id;
193 
197 
198 
199 /********************************************************************
200 * *
201 * F U N C T I O N S *
202 * *
203 *********************************************************************/
204 
205 
215 extern status_t
216  agt_rpc_init (void);
217 
218 
225 extern void
226  agt_rpc_cleanup (void);
227 
228 
241 extern status_t
242  agt_rpc_register_method (const xmlChar *module,
243  const xmlChar *method_name,
244  agt_rpc_phase_t phase,
245  agt_rpc_method_t method);
246 
247 
256 extern void
257  agt_rpc_support_method (const xmlChar *module,
258  const xmlChar *method_name);
259 
260 
269 extern void
270  agt_rpc_unsupport_method (const xmlChar *module,
271  const xmlChar *method_name);
272 
273 
281 extern void
282  agt_rpc_unregister_method (const xmlChar *module,
283  const xmlChar *method_name);
284 
285 
298 extern boolean
300  xml_node_t *top);
301 
302 
326 extern status_t
327  agt_rpc_load_config_file (const xmlChar *filespec,
328  cfg_template_t *cfg,
329  boolean isload,
330  ses_id_t use_sid,
331  dlq_hdr_t *errQ);
332 
333 
359 extern val_value_t *
360  agt_rpc_get_config_file (const xmlChar *filespec,
361  cfg_template_t *targetcfg,
362  ses_id_t use_sid,
363  dlq_hdr_t *errorQ,
364  status_t *res);
365 
366 
389 extern status_t
390  agt_rpc_load_config_file_val (const xmlChar *filespec,
391  ses_id_t use_sid,
392  val_value_t **configval,
393  dlq_hdr_t *errorQ);
394 
395 
413 extern status_t
414  agt_rpc_replay_config (void);
415 
416 
429 extern status_t
431  val_value_t *rpcerror);
432 
433 
442 extern void
444  status_t retres);
445 
446 
458 extern status_t
460  xml_msg_hdr_t *msg,
461  const rpc_err_rec_t *err,
462  int32 indent,
463  boolean isfirst,
464  boolean islast);
465 
466 
473 extern ncx_backptr_t *
475 
476 
484 extern ncx_backptr_t *
486 
487 
496 extern status_t
498  rpc_msg_t *msg,
499  obj_template_t *rpcobj);
500 
501 
511 extern status_t
513  rpc_msg_t *msg,
514  obj_template_t *rpcobj,
515  xml_node_t *method);
516 
517 
528 extern status_t
530  rpc_msg_t *msg,
531  status_t psdres);
532 
533 
546 extern status_t
548  rpc_msg_t *msg,
549  xml_node_t *method_node);
550 
551 
566 extern status_t
568  rpc_msg_t *msg,
569  xml_node_t *method_node,
570  val_value_t *action_val);
571 
572 
578 extern rpc_msg_t *
579  agt_rpc_new_dummy_msg (void);
580 
581 
589 extern boolean
591 
592 
598 extern void
600 
601 
608 extern boolean
610 
611 
612 #ifdef WITH_YCONTROL
613 
622 extern status_t
623  agt_rpc_register_subsys_callback (const xmlChar *subsys_id,
624  const xmlChar *modname,
625  const xmlChar *rpcname);
626 
627 
636 extern void
637  agt_rpc_unregister_subsys_callback (const xmlChar *subsys_id,
638  const xmlChar *modname,
639  const xmlChar *rpcname);
640 
641 #endif // WITH_YCONTROL
642 
643 
650 extern void
651  agt_rpc_add_return_val (val_value_t *return_val,
652  rpc_msg_t *msg);
653 
654 
661 extern void
662  agt_rpc_add_return_vals (dlq_hdr_t *return_valQ,
663  rpc_msg_t *msg);
664 
665 
671 extern void
673 
674 
675 #ifdef WITH_YCONTROL
676 
691 extern status_t
692  agt_rpc_handle_subsys_request (void *sil_sa_cb,
693  ses_cb_t *scb,
694  const xmlChar *modname,
695  const xmlChar *rpcname,
696  val_value_t *rpc_input_val,
697  dlq_hdr_t *return_dataQ);
698 
699 
713 extern status_t
714  agt_rpc_handle_subsys_action (void *sil_sa_cb,
715  ses_cb_t *scb,
716  const xmlChar *path,
717  val_value_t *action_input_val,
718  dlq_hdr_t *return_dataQ);
719 #endif // WITH_YCONTROL
720 
721 
730 extern void
731  agt_rpc_finish_reply (uint32 sid,
732  void *msg);
733 
734 
748 extern void
750 
751 
752 #ifdef WITH_YCONTROL
753 
758 extern void
760 
761 
768 extern agt_rpc_subsys_t *
769  agt_rpc_new_subsys (const xmlChar *subsys_id);
770 
771 
779 extern agt_rpc_subsys_t *
780  agt_rpc_find_subsys (dlq_hdr_t *subsysQ,
781  const xmlChar *subsys_id);
782 
783 
800 extern status_t
802  rpc_msg_t *msg,
803  const xmlChar *rpc_module,
804  const xmlChar *rpc_name,
805  val_value_t *rpc_method,
806  const xmlChar *out_filespec);
807 
808 #endif // WITH_YCONTROL
809 
810 
818 extern void
820 
821 
824 #ifdef __cplusplus
825 } /* end extern 'C' */
826 #endif
827 
828 #endif /* _H_agt_rpc */
ncx_backptr_t * agt_rpc_get_next_backptr(ncx_backptr_t *curptr)
Get the next backptr to the registered and supported RPC methods on the server.
Definition: agt_rpc.c:3791
Common Encoding Message Header No longer XML specific!! Used by JSON parsing as well!! Allows common ...
Definition: xml_msg.h:351
gather node data into a simple struct.
Definition: xml_util.h:204
used with various structs to cache back-ptrs the 'node' pointer may or may not be malloced! the ncx_f...
Definition: ncxtypes.h:1390
void agt_rpc_support_method(const xmlChar *module, const xmlChar *method_name)
mark an RPC method or action as supported within the server
Definition: agt_rpc.c:2619
@ brief NCX configuration database manager
status_t agt_rpc_parse_rpc_input(ses_cb_t *scb, rpc_msg_t *msg, obj_template_t *rpcobj, xml_node_t *method)
RPC received, parse parameters against rpcio for 'input'.
Definition: agt_rpc.c:3864
status_t(* agt_rpc_method_t)(ses_cb_t *scb, rpc_msg_t *msg, xml_node_t *methnode)
Template for RPC server callbacks.
Definition: agt_rpc.h:147
NETCONF Server and Client RPC Request/Reply Message Header.
Definition: rpc.h:181
status_t agt_rpc_load_config_file_val(const xmlChar *filespec, ses_id_t use_sid, val_value_t **configval, dlq_hdr_t *errorQ)
Dispatch an internal <load-config> request used for COPY-CONFIG for URL to Candidate.
Definition: agt_rpc.c:5181
void agt_rpc_callback_regdone(obj_template_t *obj)
Set the RPC as register done.
Definition: agt_rpc.c:4112
void agt_rpc_add_return_vals(dlq_hdr_t *return_valQ, rpc_msg_t *msg)
Add a Q of return values to the msg.
Definition: agt_rpc.c:4358
status_t agt_rpc_post_psd_state(ses_cb_t *scb, rpc_msg_t *msg, status_t psdres)
Fixup parmset after parse phase.
Definition: agt_rpc.c:3942
NETCONF protocol standard error definitions.
status_t(* agt_rpc_data_cb_t)(ses_cb_t *scb, rpc_msg_t *msg, uint32 indent)
Callback template for RPCs that use an inline callback function instead of generating a malloced val_...
Definition: agt_rpc.h:178
void agt_rpc_add_return_val(val_value_t *return_val, rpc_msg_t *msg)
Add a return value to the msg.
Definition: agt_rpc.c:4337
(2) cb after the input is parsed
Definition: agt_rpc.h:111
One YANG data-def-stmt.
Definition: obj.h:1140
void agt_rpc_free_subsys(agt_rpc_subsys_t *cb)
Clean and free a subsys record.
Definition: agt_rpc.c:4821
NETCONF Session Common definitions module.
agt_rpc_phase_t
There are 3 different callbacks possible in the server processing chain.
Definition: agt_rpc.h:109
void agt_rpc_unload_module(ncx_module_t *mod)
Check all the rpc objects from this module and clean any callbacks because the module is being unload...
Definition: agt_rpc.c:5126
(1) NO CB FOR THIS STATE
Definition: agt_rpc.h:120
void agt_rpc_send_error_reply(ses_cb_t *scb, status_t retres)
Operation failed or was never attempted.
Definition: agt_rpc.c:3620
boolean agt_rpc_callback_set(obj_template_t *obj)
Check if an RPC callback is registered for this object for SIL-SA usage.
Definition: agt_rpc.c:4080
representation of one module or submodule during and after parsing
Definition: ncxtypes.h:1052
status_t agt_rpc_invoke_rpc(ses_cb_t *scb, rpc_msg_t *msg, xml_node_t *method_node)
Invoke an RPC – need to call following functions first:
Definition: agt_rpc.c:3973
#define AGT_RPC_NUM_CALLBACK_PHASES
this constant is for the number of callback slots allocated in a &#39;cbset&#39;, and only includes the RPC p...
Definition: agt_rpc.h:89
uint32 ses_id_t
Session ID.
Definition: ses.h:306
boolean agt_rpc_callback_is_regdone(obj_template_t *obj)
Set the RPC as register done.
Definition: agt_rpc.c:4141
One RPC error record built by the server before an <rpc-error> element is generated.
Definition: rpc_err.h:484
boolean agt_rpc_dispatch(ses_cb_t *scb, xml_node_t *top)
Dispatch an incoming <rpc> request.
Definition: agt_rpc.c:2792
(4) NO CB FOR THIS STATE
Definition: agt_rpc.h:123
status_t agt_rpc_invoke_action(ses_cb_t *scb, rpc_msg_t *msg, xml_node_t *method_node, val_value_t *action_val)
Invoke an Action – need to call following functions first:
Definition: agt_rpc.c:4014
status_t agt_rpc_init(void)
Initialize the agt_rpc module.
Definition: agt_rpc.c:2478
status_t res
subsystem status
Definition: agt_rpc.h:195
struct representing 1 configuration database
Definition: cfg.h:225
status_t agt_rpc_handle_subsys_action(void *sil_sa_cb, ses_cb_t *scb, const xmlChar *path, val_value_t *action_input_val, dlq_hdr_t *return_dataQ)
Handles incoming <action-request> server request messages.
Definition: agt_rpc.c:4555
boolean regdone
registration done flag
Definition: agt_rpc.h:158
rpc_msg_t * agt_rpc_new_dummy_msg(void)
Create a dummy rpc_msg_t.
Definition: agt_rpc.c:4047
(3) cb to invoke the requested method
Definition: agt_rpc.h:114
XML Utilities.
status_t agt_rpc_load_config_file(const xmlChar *filespec, cfg_template_t *cfg, boolean isload, ses_id_t use_sid, dlq_hdr_t *errQ)
Dispatch an internal <load-config> request.
Definition: agt_rpc.c:3260
status_t agt_rpc_register_subsys_callback(const xmlChar *subsys_id, const xmlChar *modname, const xmlChar *rpcname)
Register an object specific RPC callback function.
Definition: agt_rpc.c:4177
void agt_rpc_unregister_subsys_callback(const xmlChar *subsys_id, const xmlChar *modname, const xmlChar *rpcname)
Unregister an object specific RPC callback function.
Definition: agt_rpc.c:4258
status_t agt_rpc_send_rpc_error(ses_cb_t *scb, xml_msg_hdr_t *msg, const rpc_err_rec_t *err, int32 indent, boolean isfirst, boolean islast)
Send one <rpc-error> element on the specified session.
Definition: agt_rpc.c:3734
status_t agt_rpc_check_rpc_invoke(ses_cb_t *scb, rpc_msg_t *msg, obj_template_t *rpcobj)
Some RPC node parsed, check if it can be invoked or not.
Definition: agt_rpc.c:3811
void agt_rpc_unsupport_method(const xmlChar *module, const xmlChar *method_name)
mark an RPC method or action as unsupported within the server
Definition: agt_rpc.c:2665
one value to match one type
Definition: val.h:870
const xmlChar * subsys_id
backptr to agt_sil_state->subsys_id
Definition: agt_rpc.h:192
agt_rpc_subsys_t * agt_rpc_find_subsys(dlq_hdr_t *subsysQ, const xmlChar *subsys_id)
Find a subsystem control block.
Definition: agt_rpc.c:4861
void agt_rpc_finish_reply(uint32 sid, void *msg)
Finish the rpc-reply for a remote operation.
Definition: agt_rpc.c:4718
(5) cb after the reply is generated
Definition: agt_rpc.h:117
status_t agt_rpc_replay_config(void)
Dispatch an internal <replay-config> request used for OP_EDITOP_LOAD to load the running from startup...
Definition: agt_rpc.c:3373
Session Control Block.
Definition: ses.h:542
status_t agt_rpc_fill_rpc_error(const rpc_err_rec_t *err, val_value_t *rpcerror)
Fill one <rpc-error> like element using the specified namespace and name, which may be different than...
Definition: agt_rpc.c:3488
void agt_rpc_reorder_dataQ(rpc_msg_t *msg)
Reorder the dataQ.
Definition: agt_rpc.c:4755
status_t
global error return code
Definition: status_enum.h:186
void agt_rpc_clear_return_data(rpc_msg_t *msg)
Clear the return data Q.
Definition: agt_rpc.c:4378
agt_rpc_subsys_t * agt_rpc_new_subsys(const xmlChar *subsys_id)
Malloc and Initialize a subsys record.
Definition: agt_rpc.c:4839
status_t agt_rpc_handle_subsys_request(void *sil_sa_cb, ses_cb_t *scb, const xmlChar *modname, const xmlChar *rpcname, val_value_t *rpc_input_val, dlq_hdr_t *return_dataQ)
Handles incoming <rpc-request> server request messages from a subsystem.
Definition: agt_rpc.c:4405
NETCONF protocol remote procedure call common definitions.
status_t agt_rpc_register_method(const xmlChar *module, const xmlChar *method_name, agt_rpc_phase_t phase, agt_rpc_method_t method)
add callback for 1 phase of RPC processing
Definition: agt_rpc.c:2539
status_t agt_rpc_subrpc_dispatch(ses_cb_t *scb, rpc_msg_t *msg, const xmlChar *rpc_module, const xmlChar *rpc_name, val_value_t *rpc_method, const xmlChar *out_filespec)
Dispatch an incoming <subrpc-request> request.
Definition: agt_rpc.c:4901
header for 1 subsystem that has a SIL-SA callback function registered for the RPC method in the agt_r...
Definition: agt_rpc.h:187
ncx_backptr_t * agt_rpc_get_first_backptr(void)
Get the first backptr to the registered and supported RPC methods on the server.
Definition: agt_rpc.c:3774
val_value_t * agt_rpc_get_config_file(const xmlChar *filespec, cfg_template_t *targetcfg, ses_id_t use_sid, dlq_hdr_t *errorQ, status_t *res)
Dispatch an internal <load-config> request except skip the INVOKE phase and just remove the &#39;config&#39; ...
Definition: agt_rpc.c:3326
the agt_rpc module stores a set of callbacks for each RPC
Definition: agt_rpc.h:153
void agt_rpc_unregister_method(const xmlChar *module, const xmlChar *method_name)
remove the callback functions for all phases of RPC or Action processing for the specified RPC method...
Definition: agt_rpc.c:2741
void agt_rpc_cleanup(void)
Cleanup the agt_rpc module.
Definition: agt_rpc.c:2513
global error status code enumerations