yumapro  20.10-12
YumaPro SDK
ses_msg.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_ses_msg
13 #define _H_ses_msg
14 /* FILE: ses_msg.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 20-jan-07 abb Begun.
36 */
37 
38 #include <xmlstring.h>
39 #include <xmlreader.h>
40 
41 #ifndef _H_dlq
42 #include "dlq.h"
43 #endif
44 
45 #ifndef _H_log
46 #include "log.h"
47 #endif
48 
49 #ifndef _H_ses
50 #include "ses.h"
51 #endif
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 /********************************************************************
58 * *
59 * C O N S T A N T S *
60 * *
61 *********************************************************************/
62 
63 
64 
65 /********************************************************************
66 * *
67 * T Y P E S *
68 * *
69 *********************************************************************/
70 
82 typedef struct ses_msg_tempchunk_t_ {
83  dlq_hdr_t qhdr;
84  xmlChar *chunk;
85  uint32 chunklen;
86 } ses_msg_tempchunk_t;
87 
88 
89 
90 /********************************************************************
91 * *
92 * F U N C T I O N S *
93 * *
94 *********************************************************************/
95 
96 
101 extern void
102  ses_msg_init (void);
103 
104 
105 
110 extern void
111  ses_msg_cleanup (void);
112 
113 
121 extern status_t
122  ses_msg_new_msg (ses_msg_t **msg);
123 
124 
131 extern void
132  ses_msg_free_msg (ses_cb_t *scb,
133  ses_msg_t *msg);
134 
135 
149 extern status_t
150  ses_msg_new_buff (ses_cb_t *scb,
151  boolean outbuff,
152  ses_msg_buff_t **buff);
153 
154 
161 extern void
162  ses_msg_free_buff (ses_cb_t *scb,
163  ses_msg_buff_t *buff);
164 
165 
174 extern status_t
175  ses_msg_write_buff (ses_cb_t *scb,
176  ses_msg_buff_t *buff,
177  xmlChar ch);
178 
179 
190 extern status_t
191  ses_msg_send_buffs (ses_cb_t *scb,
192  boolean *anyout);
193 
194 
209 extern status_t
210  ses_msg_new_output_buff (ses_cb_t *scb,
211  boolean start_chunk_mode);
212 
213 
220 extern void
221  ses_msg_make_inready (ses_cb_t *scb);
222 
223 
230 extern void
231  ses_msg_make_outready (ses_cb_t *scb);
232 
233 
240 extern void
241  ses_msg_make_outready_ycontrol (ses_cb_t *scb);
242 
243 
252 extern void
253  ses_msg_finish_outmsg (ses_cb_t *scb);
254 
255 
263 extern ses_ready_t *
264  ses_msg_get_first_inready (boolean ycontrol);
265 
266 
272 extern ses_ready_t *
274 
275 
281 extern ses_ready_t *
283 
284 
291 extern ses_ready_t *
293 
294 
302 extern void
303  ses_msg_dump (log_debug_t lvl,
304  const ses_msg_t *msg,
305  const xmlChar *text);
306 
307 
316  extern void
317  ses_msg_add_framing (ses_cb_t *scb,
318  ses_msg_buff_t *buff);
319 
320 
328 extern void
329  ses_msg_init_buff (ses_cb_t *scb,
330  boolean outbuff,
331  ses_msg_buff_t *buff);
332 
333 
345 extern status_t
346  ses_msg_reset_message (ses_cb_t *scb,
347  ses_msg_t *msg,
348  dlq_hdr_t *tempchunkQ);
349 
350 
358 extern ses_msg_tempchunk_t *
359  ses_msg_new_tempchunk (xmlChar *chunk,
360  uint32 chunklen);
361 
362 
368 extern void
369  ses_msg_free_tempchunk (ses_msg_tempchunk_t *tc);
370 
371 
377 extern void
378  ses_msg_clean_tempchunkQ (dlq_hdr_t *tempchunkQ);
379 
380 
387 extern uint32
388  ses_msg_size_tempchunkQ (dlq_hdr_t *tempchunkQ);
389 
390 
397 extern ses_msg_buff_t *
398  ses_msg_first_outbuff (ses_cb_t *scb);
399 
400 
408 extern ses_msg_buff_t *
409  ses_msg_next_outbuff (ses_cb_t *scb,
410  ses_msg_buff_t *curbuff);
411 
412 
419 extern size_t
420  ses_msg_buff_size (ses_msg_buff_t *buff);
421 
422 
431 extern size_t
432  ses_msg_copy_buff (ses_msg_buff_t *buff,
433  xmlChar *retbuff,
434  size_t retbuff_size);
435 
436 
442 extern void
443  ses_msg_clean_outbuffs (ses_cb_t *scb);
444 
445 
457 extern xmlChar *
458  ses_msg_convert_outbuffs (ses_cb_t *scb,
459  uint32 *len);
460 
461 
475 extern status_t
476  ses_msg_add_input_msg (ses_cb_t *scb,
477  xmlChar *data,
478  size_t datalen);
479 
487 extern void
488  ses_msg_clean_msgQ (ses_cb_t *scb);
489 
490 
494 #ifdef __cplusplus
495 } /* end extern 'C' */
496 #endif
497 
498 #endif /* _H_ses_msg */
thd_unlock_inreadyQ_mutex
int thd_unlock_inreadyQ_mutex(ses_id_t sid)
Unlock mutex for access to the inreadyQ (pending input).
Definition: thd.c:1308
ses.h
NETCONF Session Common definitions module.
ses_msg_clean_msgQ
void ses_msg_clean_msgQ(ses_cb_t *scb)
Clean all the input messages use by the scb Used by YP-COAP.
Definition: ses_msg.c:1778
xml_strncpy
uint32 xml_strncpy(xmlChar *copyTo, const xmlChar *copyFrom, uint32 maxlen)
String copy for xmlChar – checks for buffer overflow.
Definition: xml_util.c:1518
ses_msg_send_buffs
status_t ses_msg_send_buffs(ses_cb_t *scb, boolean *anyout)
Send multiple buffers to the session client socket Tries to send one packet at maximum MTU.
Definition: ses_msg.c:569
SES_ENDCHUNK_PAD
#define SES_ENDCHUNK_PAD
leave enough room at the end for EOChunks for framing11 or http_chunk_mode
Definition: ses.h:278
tstamp.h
Timestamp utilities.
ses_msg_init_buff
void ses_msg_init_buff(ses_cb_t *scb, boolean outbuff, ses_msg_buff_t *buff)
Init the buffer fields.
Definition: ses_msg.c:1266
ses_msg_tempchunk_t_::chunk
xmlChar * chunk
chunk
Definition: ses_msg.h:84
log_error
void log_error(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_ERROR log entry.
val.h
Value Node Basic Support.
ses_msg_buff_size
size_t ses_msg_buff_size(ses_msg_buff_t *buff)
Get the number of bytes in the buffer (not the buffer size)
Definition: ses_msg.c:1561
ses_msg_get_first_inready
ses_ready_t * ses_msg_get_first_inready(boolean ycontrol)
Dequeue the first entry in the inreadyQ, if any.
Definition: ses_msg.c:971
log_debug3
void void void void void void void void void void void log_debug3(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG3 log entry.
ses_msg_make_inready
void ses_msg_make_inready(ses_cb_t *scb)
Put the session on the inreadyQ if it is not already there.
Definition: ses_msg.c:834
ses_msg_add_framing
void ses_msg_add_framing(ses_cb_t *scb, ses_msg_buff_t *buff)
Add the base:1.1 framing chars to the buffer and adjust the buffer size pointers.
Definition: ses_msg.c:1176
ses_msg_free_tempchunk
void ses_msg_free_tempchunk(ses_msg_tempchunk_t *tc)
Free a temp chunk.
Definition: ses_msg.c:1444
ses_msg_new_msg
status_t ses_msg_new_msg(ses_msg_t **msg)
Malloc a new session message control header.
Definition: ses_msg.c:281
ses_msg_free_buff
void ses_msg_free_buff(ses_cb_t *scb, ses_msg_buff_t *buff)
Free the session buffer chunk.
Definition: ses_msg.c:460
ses_msg_dump
void ses_msg_dump(log_debug_t lvl, const ses_msg_t *msg, const xmlChar *text)
Dump the message contents.
Definition: ses_msg.c:1100
ses_msg.h
NETCONF Session Message Common definitions module.
SES_MAX_BYTESEND
#define SES_MAX_BYTESEND
max number of bytes to try to send in one call to the write_fn
Definition: ses.h:251
ses_id_t
uint32 ses_id_t
Session ID.
Definition: ses.h:306
SES_TRANSPORT_COAP
@ SES_TRANSPORT_COAP
CoAP UDP socket.
Definition: ses.h:343
log_info
void void void void void log_info(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_INFO log entry.
log_debug2
void void void void void void void void void log_debug2(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG2 log entry.
ses_msg_tempchunk_t_::qhdr
dlq_hdr_t qhdr
queue header
Definition: ses_msg.h:83
errno_to_status
status_t errno_to_status(void)
Get the errno variable and convert it to a status_t.
Definition: status.c:968
NO_ERR
@ NO_ERR
000
Definition: status_enum.h:188
NC_SSH_END_CHUNKS_LEN
#define NC_SSH_END_CHUNKS_LEN
Length of NETCONF SSH End of Chunks Marker.
Definition: ncxconst.h:112
log_debug4
void void void void void void void void void void void void void log_debug4(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG4 log entry.
ERR_NCX_OPERATION_FAILED
@ ERR_NCX_OPERATION_FAILED
274
Definition: status_enum.h:315
LOGDEBUG2
#define LOGDEBUG2
Check if at least log-level=debug2.
Definition: log.h:292
dlq_createSQue
void dlq_createSQue(dlq_hdrT *queAddr)
create a static queue header
Definition: dlq.c:177
ERR_INTERNAL_VAL
@ ERR_INTERNAL_VAL
004
Definition: status_enum.h:194
dlq_remove
void dlq_remove(void *nodeP)
remove the queue entry from its queue list entry MUST have been enqueued somehow before this function...
Definition: dlq.c:519
SES_MAX_FREE_BUFFERS
#define SES_MAX_FREE_BUFFERS
max number of buffers a session is allowed to cache in its freeQ
Definition: ses.h:242
ERR_NCX_INVALID_VALUE
@ ERR_NCX_INVALID_VALUE
258
Definition: status_enum.h:299
ses_msg_make_outready
void ses_msg_make_outready(ses_cb_t *scb)
Put the session on the outreadyQ if it is not already there.
Definition: ses_msg.c:858
ERR_INTERNAL_MEM
@ ERR_INTERNAL_MEM
003
Definition: status_enum.h:193
ses_msg_free_msg
void ses_msg_free_msg(ses_cb_t *scb, ses_msg_t *msg)
Free the session message and all its buffer chunks.
Definition: ses_msg.c:325
get_error_string
const char * get_error_string(status_t res)
Get the error message for a specific internal error.
Definition: status.c:239
log_debug
void void void void void void void log_debug(const char *fstr,...) __attribute__((format(printf
Generate a new LOG_DEBUG_DEBUG log entry.
ses_msg_copy_buff
size_t ses_msg_copy_buff(ses_msg_buff_t *buff, xmlChar *retbuff, size_t retbuff_size)
Copy the buffer data to another buffer.
Definition: ses_msg.c:1585
ses_msg_tempchunk_t_::chunklen
uint32 chunklen
chunk length
Definition: ses_msg.h:85
LOGINFO
#define LOGINFO
Check if at least log-level=info.
Definition: log.h:279
dlq_nextEntry
#define dlq_nextEntry(nodeP)
get the next queue entry after the current entry
Definition: dlq.h:265
ses_msg_tempchunk_t_
save the chunks before putting them back into ses_buff_t structs
Definition: ses_msg.h:82
NCX_PROTO_YCONTROL
@ NCX_PROTO_YCONTROL
YumaPro Internal Control 1.0.
Definition: ncxtypes.h:787
ses_msg_size_tempchunkQ
uint32 ses_msg_size_tempchunkQ(dlq_hdr_t *tempchunkQ)
Get the size of the message in the tempchunks.
Definition: ses_msg.c:1489
ERR_NCX_RESOURCE_DENIED
@ ERR_NCX_RESOURCE_DENIED
269
Definition: status_enum.h:310
ses_msg_first_outbuff
ses_msg_buff_t * ses_msg_first_outbuff(ses_cb_t *scb)
Get the first outQ buffer.
Definition: ses_msg.c:1516
ses_msg_get_first_inready_ses
ses_ready_t * ses_msg_get_first_inready_ses(ses_id_t sid)
Dequeue the first matching session entry in the inreadyQ, if any.
Definition: ses_msg.c:1005
ses_msg_write_buff
status_t ses_msg_write_buff(ses_cb_t *scb, ses_msg_buff_t *buff, xmlChar ch)
Add some text to the message buffer.
Definition: ses_msg.c:523
ses_dropped
boolean ses_dropped(const ses_cb_t *scb)
Check if the session has been dropped by the client.
Definition: ses.c:4860
SES_ST_SHUTDOWN_REQ
@ SES_ST_SHUTDOWN_REQ
session shutdown requested
Definition: ses.h:360
NC_SSH_END_CHUNKS
#define NC_SSH_END_CHUNKS
NETCONF SSH End of Chunks Marker.
Definition: ncxconst.h:109
SES_MAX_BUFFERS
#define SES_MAX_BUFFERS
max number of buffer chunks a session can have allocated at once This is an arbitrary limit – no stat...
Definition: ses.h:238
LOGDEBUG4
#define LOGDEBUG4
Check if at least log-level=debug4.
Definition: log.h:302
log.h
NCX System Logging Manager.
log_flush
void log_flush(void)
Flush output buffers.
Definition: log.c:1880
ERR_BUFF_OVFL
@ ERR_BUFF_OVFL
106
Definition: status_enum.h:218
ses_msg_reset_message
status_t ses_msg_reset_message(ses_cb_t *scb, ses_msg_t *msg, dlq_hdr_t *tempchunkQ)
Reset a message to the provided buffer.
Definition: ses_msg.c:1301
LOGDEBUG
#define LOGDEBUG
Check if at least log-level=debug.
Definition: log.h:287
SES_MAX_BUFFSEND
#define SES_MAX_BUFFSEND
max number of buffers to try to send in one call to the write fn
Definition: ses.h:248
dlq_deque
void * dlq_deque(dlq_hdrT *listP)
remove the first queue node from the queue list
Definition: dlq.c:286
dlq_empty
#define dlq_empty(listP)
check if queue list is empty
Definition: dlq.h:367
thd.h
Thread support (for now limited to netconfd)
log_debug2_append
void void void void void void void void void void log_debug2_append(const char *fstr,...) __attribute__((format(printf
Append to a LOG_DEBUG_DEBUG2 log entry.
SES_STARTCHUNK_PAD
#define SES_STARTCHUNK_PAD
padding at start of buffer for chunk tagging
Definition: ses.h:273
ses_msg_convert_outbuffs
xmlChar * ses_msg_convert_outbuffs(ses_cb_t *scb, uint32 *len)
Clean the message out buffers for next use.
Definition: ses_msg.c:1656
ses_msg_add_input_msg
status_t ses_msg_add_input_msg(ses_cb_t *scb, xmlChar *data, size_t datalen)
Make a ses_msg_t to fool the session handler into thinking the HTTP code path filled in a session inp...
Definition: ses_msg.c:1722
ses_msg_get_first_outready
ses_ready_t * ses_msg_get_first_outready(void)
Dequeue the first entry in the outreadyQ, if any.
Definition: ses_msg.c:1044
dlq_firstEntry
#define dlq_firstEntry(listP)
get the first entry in the queue list
Definition: dlq.h:337
ncx.h
YANG module utility functions.
send_buff.h
Send buffer utility.
SES_MAX_CHUNKNUM_SIZE
#define SES_MAX_CHUNKNUM_SIZE
max size of the chunk size number in the chunk start tag
Definition: ses.h:260
SES_MY_SID
#define SES_MY_SID(S)
get session-id
Definition: ses.h:105
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
ses_msg_new_tempchunk
ses_msg_tempchunk_t * ses_msg_new_tempchunk(xmlChar *chunk, uint32 chunklen)
Create a new temp chunk.
Definition: ses_msg.c:1420
ses_msg_clean_outbuffs
void ses_msg_clean_outbuffs(ses_cb_t *scb)
Clean the message out buffers for next use.
Definition: ses_msg.c:1617
ses_msg_finish_outmsg
void ses_msg_finish_outmsg(ses_cb_t *scb)
Put the outbuff in the outQ if non-empty.
Definition: ses_msg.c:907
ses_msg_new_buff
status_t ses_msg_new_buff(ses_cb_t *scb, boolean outbuff, ses_msg_buff_t **buff)
Malloc a new session buffer chuck.
Definition: ses_msg.c:378
dlq_enque
void dlq_enque(REG void *newP, REG dlq_hdrT *listP)
add a queue node to the end of a queue list Add newP to listP
Definition: dlq.c:246
ses_msg_get_first_outready_ycontrol
ses_ready_t * ses_msg_get_first_outready_ycontrol(void)
Dequeue the first entry in the outreadyQ, if any Get a ycontrol entry.
Definition: ses_msg.c:1071
SET_ERROR
#define SET_ERROR(E)
macro SET_ERROR
Definition: status_enum.h:103
ERR_NCX_SESSION_DROPPED
@ ERR_NCX_SESSION_DROPPED
400
Definition: status_enum.h:443
ses_msg_make_outready_ycontrol
void ses_msg_make_outready_ycontrol(ses_cb_t *scb)
Put the session on the outreadyQ if it is not already there.
Definition: ses_msg.c:882
ses_msg_init
void ses_msg_init(void)
Initialize the session message manager module data structures.
Definition: ses_msg.c:218
thd_lock_inreadyQ_mutex
int thd_lock_inreadyQ_mutex(ses_id_t sid)
Request mutex lock for access to the inreadyQ (pending input).
Definition: thd.c:1277
status.h
Global error messages for status code enumerations.
ses_msg_clean_tempchunkQ
void ses_msg_clean_tempchunkQ(dlq_hdr_t *tempchunkQ)
Clean a Q of ses_msg_tempchunk_t structs.
Definition: ses_msg.c:1465
dlq.h
dlq provides general double-linked list and queue support:
LOGDEBUG3
#define LOGDEBUG3
Check if at least log-level=debug3.
Definition: log.h:297
ses_msg_new_output_buff
status_t ses_msg_new_output_buff(ses_cb_t *scb, boolean start_chunk_mode)
Put the current outbuff on the outQ.
Definition: ses_msg.c:771
ses_msg_next_outbuff
ses_msg_buff_t * ses_msg_next_outbuff(ses_cb_t *scb, ses_msg_buff_t *curbuff)
Get the next outQ buffer.
Definition: ses_msg.c:1538
SES_MSG_BUFFSIZE
#define SES_MSG_BUFFSIZE
controls the size of each buffer chunk
Definition: ses.h:232
ses_msg_cleanup
void ses_msg_cleanup(void)
Cleanup the session message manager module data structures.
Definition: ses_msg.c:242