yumapro  20.10-12
YumaPro SDK
subsys_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 - 2012, 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_subsys_util
13 #define _H_subsys_util
14 
15 /* FILE: subsys_util.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 24-oct-12 abb Begun; split from subsystem.c
37 
38 */
39 
40 #ifndef _H_subsystem
41 #include "subsystem.h"
42 #endif
43 
44 #ifndef _H_status
45 #include "status.h"
46 #endif
47 
48 #ifndef _H_subsys_magic
49 #include "subsys_magic.h"
50 #endif
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 /********************************************************************
57 * *
58 * C O N S T A N T S *
59 * *
60 *********************************************************************/
61 
62 
76 /********************************************************************
77 * *
78 * T Y P E S *
79 * *
80 *********************************************************************/
81 
82 
84 typedef struct subsys_cb_t_ {
85 
87  const char *request_uri;
88 
90  const char *request_method;
91 
93  const char *content_type;
94 
96  const char *content_length;
97 
99  const char *modified_since;
100 
102  const char *unmodified_since;
103 
105  const char *match;
106 
108  const char *none_match;
109 
111  const char *http_accept;
112 
114  const char *user;
115 
117  const char *ha_server_id;
118 
119 
126  const char *ha_server_addr;
127 
132  uint16 ha_server_port;
133 
136 
139 
141  int32 content_len;
142 
144  char *client_addr;
145 
147  char *port;
148 
150  int ncxsock;
151 
153  boolean ncxconnect;
154 
156  boolean nonblocking;
157 
159  boolean nonblocking_set_ok;
160 
162  boolean no_connect;
163 
165  boolean yp_ha_mode;
166 
168  boolean extern_mode;
169 
171  proto_id_t proto_id;
172 
174  const char *subsys_id;
175 
177  int traceLevel;
178 
180  FILE *errfile;
181 
183  fd_set fds;
184 
186  char msgbuff[SUBSYS_BUFFLEN];
187 
188 } subsys_cb_t;
189 
190 
191 /********************************************************************
192 * *
193 * F U N C T I O N S *
194 * *
195 *********************************************************************/
196 
197 
204 extern status_t
205  get_ssh_parms (subsys_cb_t *cb);
206 
207 
214 extern status_t
215  start_connection (subsys_cb_t *cb);
216 
217 
224 extern status_t
225  send_cli_ncxconnect (subsys_cb_t *cb);
226 
227 
233 extern void
234  init_subsys_cb (subsys_cb_t *cb);
235 
236 
242 extern void
243  clean_subsys_cb (subsys_cb_t *cb);
244 
245 
258 extern void
259  configure_cli_parms(subsys_cb_t *cb,
260  int argc,
261  char **argv);
262 
263 
275 extern status_t
276  start_subsys_ypshell (int *retfd);
277 
278 
291 extern status_t
292  start_subsys_tcp_ncx (int *retfd,
293  const char *user);
294 
295 
311 extern status_t
312  start_subsys_extern_tcp_ncx (int *retfd,
313  const char *user,
314  const char *addr,
315  unsigned int portnum);
316 
317 
321 #ifdef __cplusplus
322 } /* end extern 'C' */
323 #endif
324 
325 #endif /* _H_subsys_util */
SUBSYS_BUFFLEN
#define SUBSYS_BUFFLEN
max length of an <ncx-connect> message
Definition: subsystem.h:80
ERR_NCX_SKIPPED
@ ERR_NCX_SKIPPED
2001
Definition: status_enum.h:551
subsys_cb_t_::ncxsock
int ncxsock
socket number
Definition: subsys_util.h:154
subsys_cb_t_::port
char * port
client port
Definition: subsys_util.h:151
start_connection
status_t start_connection(subsys_cb_t *cb)
Start the connection to the server.
Definition: subsys_util.c:482
configure_cli_parms
void configure_cli_parms(subsys_cb_t *cb, int argc, char **argv)
Configure CLI parameters.
Definition: subsys_util.c:624
PROTO_ID_RESTCONF
@ PROTO_ID_RESTCONF
RESTCONF.
Definition: subsystem.h:141
start_subsys_tcp_ncx
status_t start_subsys_tcp_ncx(int *retfd, const char *user)
Start the subsystem for a tcp-ncx transport connection.
Definition: subsys_util.c:759
subsys_cb_t_::ha_server_addr
const char * ha_server_addr
YP-HA support; this address will override the AF_LOCAL or the TCP socket file read by subsys_info_rea...
Definition: subsys_util.h:130
status_enum.h
global error status code enumerations
subsys_cb_t_::ha_server_port
uint16 ha_server_port
HA server port number The ha_server_port is also used by the extern tcp-ncx mode (extern_mode == TRUE...
Definition: subsys_util.h:136
ERR_NCX_CONNECT_FAILED
@ ERR_NCX_CONNECT_FAILED
315
Definition: status_enum.h:358
subsys_cb_t_::proto_id
proto_id_t proto_id
protocol in use
Definition: subsys_util.h:175
start_subsys_extern_tcp_ncx
status_t start_subsys_extern_tcp_ncx(int *retfd, const char *user, const char *addr, unsigned int portnum)
Start the subsystem to connect to an external tcp-ncx socket.
Definition: subsys_util.c:839
subsys_cb_t_::ha_server_id
const char * ha_server_id
The HA server-id.
Definition: subsys_util.h:121
subsys_cb_t_
one subsystem control block for session
Definition: subsys_util.h:84
subsys_cb_t_::nonblocking_set_ok
boolean nonblocking_set_ok
Flag non-blocking failed.
Definition: subsys_util.h:163
ncxconst.h
Contains NCX constants.
subsys_cb_t_::ncxconnect
boolean ncxconnect
Use ncxconnect.
Definition: subsys_util.h:157
subsys_cb_t_::client_addr
char * client_addr
client address
Definition: subsys_util.h:148
subsys_util.h
Thin client IO handler for YumaPro server (utility functions)
start_subsys_ypshell
status_t start_subsys_ypshell(int *retfd)
Start the subsystem for yp-shell.
Definition: subsys_util.c:701
SUBSYS_TRACE2
#define SUBSYS_TRACE2(cb, fmt,...)
SUBSYS_TRACE Level 2 log debug trace macro.
Definition: subsystem.h:90
ERR_NCX_MISSING_PARM
@ ERR_NCX_MISSING_PARM
233
Definition: status_enum.h:272
NO_ERR
@ NO_ERR
000
Definition: status_enum.h:188
subsys_cb_t_::user
const char * user
User ID for the session.
Definition: subsys_util.h:118
subsys_cb_t_::subsys_id
const char * subsys_id
subsystem ID to use
Definition: subsys_util.h:178
NCX_SERVER_VERSION
#define NCX_SERVER_VERSION
ncxserver version
Definition: ncxconst.h:183
subsys_cb_t_::match
const char * match
Match if a RESTCONF session.
Definition: subsys_util.h:109
subsys_cb_t_::none_match
const char * none_match
None-Match if a RESTCONF session.
Definition: subsys_util.h:112
subsys_stdout_fn_t
status_t(* subsys_stdout_fn_t)(const char *buff, size_t bufflen)
STDOUT FUNCTION TEMPLATE subsys_stdout_fn_t.
Definition: subsystem.h:149
ERR_NCX_INVALID_VALUE
@ ERR_NCX_INVALID_VALUE
258
Definition: status_enum.h:299
subsys_cb_t_::modified_since
const char * modified_since
Modified-Since if a RESTCONF session.
Definition: subsys_util.h:103
ERR_INTERNAL_MEM
@ ERR_INTERNAL_MEM
003
Definition: status_enum.h:193
subsys_stdin_fn_t
ssize_t(* subsys_stdin_fn_t)(char *buff, size_t bufflen)
STDIN FUNCTION TEMPLATE subsys_stdin_fn_t.
Definition: subsystem.h:162
subsys_cb_t_::content_type
const char * content_type
content-type if a RESTCONF session
Definition: subsys_util.h:97
subsys_cb_t_::errfile
FILE * errfile
error file
Definition: subsys_util.h:184
subsys_cb_t_::unmodified_since
const char * unmodified_since
Unmodified-Since if a RESTCONF session.
Definition: subsys_util.h:106
subsys_cb_t_::no_connect
boolean no_connect
flag no connection
Definition: subsys_util.h:166
subsys_cb_t_::extern_mode
boolean extern_mode
flag external mode
Definition: subsys_util.h:172
NCXSERVER_SOCKNAME
#define NCXSERVER_SOCKNAME
Default ncx-connect socket is AFLOCAL.
Definition: ncxconst.h:88
init_subsys_cb
void init_subsys_cb(subsys_cb_t *cb)
Initialize the fields of a subsystem control block.
Definition: subsys_util.c:585
ERR_FIL_READ
@ ERR_FIL_READ
101
Definition: status_enum.h:213
subsystem.h
Thin client IO handler for YumaPro server.
SUBSYS_TRACE1
#define SUBSYS_TRACE1(cb, fmt,...)
SUBSYS_TRACE Level 1 log debug trace macro.
Definition: subsystem.h:83
subsys_cb_t_::yp_ha_mode
boolean yp_ha_mode
flag YP-HA mode
Definition: subsys_util.h:169
subsys_cb_t_::nonblocking
boolean nonblocking
Use non-blocking.
Definition: subsys_util.h:160
get_ssh_parms
status_t get_ssh_parms(subsys_cb_t *cb)
Get the SSH environment parameters.
Definition: subsys_util.c:395
subsys_cb_t_::content_length
const char * content_length
Content-Length if a RESTCONF session.
Definition: subsys_util.h:100
ERR_BUFF_OVFL
@ ERR_BUFF_OVFL
106
Definition: status_enum.h:218
subsys_cb_t_::request_uri
const char * request_uri
request URI if a RESTCONF session
Definition: subsys_util.h:91
subsys_cb_t_::stdin_fn
subsys_stdin_fn_t stdin_fn
override STDIN function
Definition: subsys_util.h:139
subsys_cb_t_::msgbuff
char msgbuff[SUBSYS_BUFFLEN]
message buffer
Definition: subsys_util.h:190
NCXSERVER_FHS_SOCKNAME
#define NCXSERVER_FHS_SOCKNAME
Default ncx-connect socket when fileloc-fhs=true.
Definition: ncxconst.h:91
NC_SSH_END
#define NC_SSH_END
NETCONF SSH End of Message Marker.
Definition: ncxconst.h:103
subsys_cb_t_::fds
fd_set fds
file descriptors
Definition: subsys_util.h:187
subsys_cb_t_::stdout_fn
subsys_stdout_fn_t stdout_fn
override STDOUT function
Definition: subsys_util.h:142
XML_START_MSG
#define XML_START_MSG
copied from ncx/xml_util.h to avoid inluding that file and all the files it includes
Definition: subsystem.h:106
send_buff.h
Send buffer utility.
send_buff
status_t send_buff(int fd, const char *buffer, size_t cnt)
Send the buffer to the network peer.
Definition: send_buff.c:94
send_cli_ncxconnect
status_t send_cli_ncxconnect(subsys_cb_t *cb)
Send the <ncx-connect> message to the ncxserver for CLI protocol.
Definition: subsys_util.c:519
clean_subsys_cb
void clean_subsys_cb(subsys_cb_t *cb)
Clean the fields of a subsystem control block.
Definition: subsys_util.c:601
subsys_cb_t_::request_method
const char * request_method
request method if a RESTCONF session
Definition: subsys_util.h:94
subsys_cb_t_::traceLevel
int traceLevel
debug trace level set (0 - 3)
Definition: subsys_util.h:181
subsys_cb_t_::http_accept
const char * http_accept
Accept a RESTCONF session.
Definition: subsys_util.h:115
ERR_FIL_OPEN
@ ERR_FIL_OPEN
system errors start at 100
Definition: status_enum.h:212
ERR_NCX_UNKNOWN_HOST
@ ERR_NCX_UNKNOWN_HOST
316
Definition: status_enum.h:359
subsys_cb_t_::content_len
int32 content_len
content length
Definition: subsys_util.h:145
NCX_URN
#define NCX_URN
URN for NCX extensions.
Definition: ncxconst.h:196
status.h
Global error messages for status code enumerations.
subsys_magic.h
Define magic string value for <ncx-connect> messages.
PROTO_ID_YANGAPI
@ PROTO_ID_YANGAPI
YANG-API.
Definition: subsystem.h:129
NCX_DEF_SUBSYS_INFO_FILE
#define NCX_DEF_SUBSYS_INFO_FILE
subsystem info file
Definition: ncxconst.h:322