1 /*	$Id: arms_methods.h 20800 2012-01-19 05:13:45Z m-oki $	*/
2 
3 /*
4  * Copyright (c) 2012, Internet Initiative Japan, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef __ARMS_METHODS_H__
31 #define __ARMS_METHODS_H__
32 
33 /*
34  * If new method is added,
35  *  (1) imprement it
36  *  (2) add method HERE.
37  *  (3) add method to arms_method_init() in arms_methods.c
38  */
39 enum arms_transaction_args {
40 	ARMS_TR_ARG_NONE = 0,
41 	ARMS_TR_ARG_MODID,
42 	ARMS_TR_ARG_MODSUBID,
43 
44 	ARMS_TR_ARG_LAST
45 };
46 
47 enum arms_transaction_types {
48 	ARMS_TR_NONE = 0,
49 	ARMS_TR_GENERIC_ERROR,
50 
51 	ARMS_TR_LSPULL,
52 	ARMS_TR_RSPULL,
53 	ARMS_TR_PUSH_READY,
54 	ARMS_TR_METHOD_QUERY,
55 	ARMS_TR_CONFIRM_START,
56 	ARMS_TR_CONFIRM_DONE,
57 
58 	ARMS_TR_READ_STATUS,
59 	ARMS_TR_REBOOT,
60 	ARMS_TR_CONFIGURE,
61 	ARMS_TR_READ_STORAGE,
62 	ARMS_TR_CHECK_TRANSACTION,
63 	ARMS_TR_DUMP_DEBUG,
64 	ARMS_TR_PING,
65 	ARMS_TR_TRACEROUTE,
66 	ARMS_TR_READ_MODULE_LIST,
67 	ARMS_TR_CLEAR_STATUS,
68 	ARMS_TR_PULL_CONFIG,
69 	ARMS_TR_MD_COMMAND,
70 
71 	ARMS_TR_LAST
72 };
73 
74 /* Transaction Types */
75 typedef struct push_tr_type {
76 	int type;
77 	const char *str;
78 } push_tr_type_t;
79 
80 /* Encodings */
81 enum {
82 	ARMS_DATA_TEXT = 0,
83 	ARMS_DATA_BINARY
84 };
85 
86 /*
87  * ARMS Method Table
88  *
89  * basic sequence for push:
90  * 1. pm_context (allocate context structure)
91  * 2. pm_copyarg (parse (*-start-)request message)
92  * 3. pm_response (build (*-start-)response message)
93  * 4. (send response message and wait for sent)
94  * 5. pm_exec (executing request)
95  * 6. pm_done (build *-done-request message)
96  * 7. (send request message and wait for response)
97  * 8. pm_rollback if configure and no response.
98  * 9. pm_release (release context structure and related resources)
99  */
100 
101 typedef struct arms_method {
102 	uint32_t pm_type;
103 	char *pm_string;
104 	/* schema for message */
105 	struct axp_schema *pm_schema;
106 
107 	uint32_t pm_flags;
108 
109 	/* generate push start-response XML */
110 	int (*pm_response)(transaction *, char *, int, int *);
111 	/* generate done-request XML */
112 	int (*pm_done)(transaction *, char *, int, int *);
113 	/* execute push */
114 	int (*pm_exec) (transaction *);
115 	/* copy and check argument */
116 	int (*pm_copyarg) (AXP *, uint32_t, int tag, const char *, size_t, tr_ctx_t *);
117 	/* rollback */
118 	int (*pm_rollback) (transaction *);
119 	/* create context */
120 	void *(*pm_context) (tr_ctx_t *);
121 	/* release context */
122 	void (*pm_release) (tr_ctx_t *);
123 	/* response parser for pull */
124 	int (*pm_parse)(transaction *, const char *, int);
125 } arms_method_t;
126 
127 
128 /*
129  * implemantations are found at protocol/
130  */
131 extern arms_method_t generic_error_methods;
132 
133 extern arms_method_t rs_sol_methods;
134 extern arms_method_t conf_sol_methods;
135 extern arms_method_t push_ready_methods;
136 extern arms_method_t method_query_methods;
137 
138 extern arms_method_t configure_methods;
139 extern arms_method_t read_status_methods;
140 extern arms_method_t reboot_methods;
141 extern arms_method_t read_storage_methods;
142 extern arms_method_t check_transaction_methods;
143 extern arms_method_t dump_debug_methods;
144 extern arms_method_t ping_methods;
145 extern arms_method_t traceroute_methods;
146 extern arms_method_t read_module_list_methods;
147 extern arms_method_t clear_status_methods;
148 extern arms_method_t pull_config_methods;
149 extern arms_method_t md_command_methods;
150 extern arms_method_t confirm_start_methods;
151 extern arms_method_t confirm_done_methods;
152 
153 void arms_method_init(void);
154 void free_arms_method_table(void);
155 
156 arms_method_t *type2method(uint32_t);
157 int pushstr2type(const char *);
158 const char *pushtype2str(int);
159 int push_add_schema(int, const char *, struct axp_schema *);
160 int push_default_hook(AXP *, int, int, int, const char *, size_t, void *);
161 
162 int arms_req_parser(transaction *, const char *, int);
163 int arms_res_parser(transaction *, const char *, int);
164 
165 int arms_req_builder(transaction *, char *, int, int *);
166 int arms_res_builder(transaction *, char *, int, int *);
167 
168 int build_generic_res(transaction *, char *, int, int *);
169 
170 int arms_write_begin_message(transaction *, char *, int);
171 int arms_write_end_message(transaction *, char *, int);
172 int arms_write_empty_message(transaction *, char *, int);
173 
174 const char * arms_escape(const char *);
175 int arms_get_encoding(AXP *, int);
176 
177 #endif /* __ARMS_METHODS_H__ */
178