Swapped to use chunked framing in internal protocol
This commit is contained in:
parent
e4834b9896
commit
5fa82dcea7
5 changed files with 414 additions and 742 deletions
|
|
@ -48,6 +48,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int detect_endtag(char *tag, char ch, int *state);
|
||||
ssize_t netconf_input_read2(int s, unsigned char *buf, ssize_t buflen, int *eof);
|
||||
int netconf_input_msg2(unsigned char **bufp, size_t *lenp, cbuf *cbmsg,
|
||||
netconf_framing_type framing, int *frame_state, size_t *frame_size,
|
||||
|
|
|
|||
|
|
@ -44,7 +44,9 @@
|
|||
* Types
|
||||
*/
|
||||
|
||||
/* Protocol message header */
|
||||
/*! Protocol message header (histoorical)
|
||||
* Current use is a shim layer for sending packets
|
||||
*/
|
||||
struct clicon_msg {
|
||||
uint32_t op_len; /* length of whole message: body+header, network byte order. */
|
||||
uint32_t op_id; /* session-id. network byte order. 1..max(u32), can be zero in client hello */
|
||||
|
|
@ -56,45 +58,26 @@ struct clicon_msg {
|
|||
*/
|
||||
char *format_int2str(enum format_enum showas);
|
||||
enum format_enum format_str2int(char *str);
|
||||
int clixon_inet2sin(const char *addrtype, const char *addrstr, uint16_t port, struct sockaddr *sa, size_t *sa_len);
|
||||
|
||||
struct clicon_msg *clicon_msg_encode(uint32_t id, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
|
||||
int clicon_msg_decode(struct clicon_msg *msg, yang_stmt *yspec, uint32_t *id, cxobj **xml, cxobj **xerr);
|
||||
|
||||
int clicon_connect_unix(clixon_handle h, char *sockpath);
|
||||
|
||||
|
||||
int clicon_rpc_connect_unix(clixon_handle h,
|
||||
char *sockpath,
|
||||
int *sock0);
|
||||
|
||||
int clicon_rpc_connect_inet(clixon_handle h,
|
||||
char *dst,
|
||||
uint16_t port,
|
||||
int *sock0);
|
||||
/* NETCONF 1.0 */
|
||||
int clixon_msg_rcv10(int s, const char *descr, cbuf *cb, int *eof);
|
||||
int clixon_msg_send10(int s, const char *descr, cbuf *cb);
|
||||
int clixon_rpc10(int sock, const char *descr, cbuf *msgin, cbuf *msgret, int *eof);
|
||||
|
||||
/* NETCONF 1.1 */
|
||||
int clixon_msg_rcv11(int s, const char *descr, cbuf **cb, int *eof);
|
||||
int clicon_rpc(int sock, const char *descr, struct clicon_msg *msg, char **xret, int *eof);
|
||||
|
||||
int clicon_rpc1(int sock, const char *descr, cbuf *msgin, cbuf *msgret, int *eof);
|
||||
|
||||
int clicon_msg_send(int s, const char *descr, struct clicon_msg *msg);
|
||||
|
||||
int clicon_msg_send1(int s, const char *descr, cbuf *cb);
|
||||
|
||||
#ifdef NETCONF_INPUT_UNIFIED_INTERNAL
|
||||
int clixon_msg_send2(int s, const char *descr, cbuf *cb);
|
||||
int clixon_msg_rcv2(int s, const char *descr, cbuf **cb, int *eof);
|
||||
#endif
|
||||
|
||||
int clicon_msg_rcv(int s, const char *descr, int intr, struct clicon_msg **msg, int *eof);
|
||||
|
||||
int clicon_msg_rcv1(int s, const char *descr, cbuf *cb, int *eof);
|
||||
|
||||
int send_msg_reply(int s, const char *descr, char *data, uint32_t datalen);
|
||||
int send_msg_notify_xml(clixon_handle h, int s, const char *descr, cxobj *xev);
|
||||
|
||||
int send_msg_reply(int s, const char *descr, char *data, uint32_t datalen);
|
||||
|
||||
int detect_endtag(char *tag, char ch, int *state);
|
||||
|
||||
int clixon_inet2sin(const char *addrtype, const char *addrstr, uint16_t port, struct sockaddr *sa, size_t *sa_len);
|
||||
|
||||
#endif /* _CLIXON_PROTO_H_ */
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ clixon_client_lock(clixon_handle h,
|
|||
NETCONF_BASE_NAMESPACE,
|
||||
NETCONF_MESSAGE_ID_ATTR,
|
||||
lock?"":"un", db, lock?"":"un");
|
||||
if (clicon_rpc1(sock, descr, msg, msgret, &eof) < 0)
|
||||
if (clixon_rpc10(sock, descr, msg, msgret, &eof) < 0)
|
||||
goto done;
|
||||
if (eof){
|
||||
close(sock);
|
||||
|
|
@ -242,7 +242,7 @@ clixon_client_hello(int sock,
|
|||
cprintf(msg, "</capabilities>");
|
||||
cprintf(msg, "</hello>");
|
||||
cprintf(msg, "]]>]]>");
|
||||
if (clicon_msg_send1(sock, descr, msg) < 0)
|
||||
if (clixon_msg_send10(sock, descr, msg) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -529,9 +529,9 @@ clixon_client_get_xdata(clixon_handle h,
|
|||
cprintf(msg, "</get-config></rpc>");
|
||||
if (netconf_output_encap(0, msg) < 0) // XXX configurable session
|
||||
goto done;
|
||||
if (clicon_msg_send1(sock, descr, msg) < 0)
|
||||
if (clixon_msg_send10(sock, descr, msg) < 0)
|
||||
goto done;
|
||||
if (clicon_msg_rcv1(sock, descr, msgret, &eof) < 0)
|
||||
if (clixon_msg_rcv10(sock, descr, msgret, &eof) < 0)
|
||||
goto done;
|
||||
if (eof){
|
||||
close(sock);
|
||||
|
|
|
|||
|
|
@ -76,6 +76,43 @@
|
|||
#include "clixon_proto.h"
|
||||
#include "clixon_netconf_input.h"
|
||||
|
||||
/*! Look for a text pattern in an input string, one char at a time
|
||||
*
|
||||
* @param[in] tag What to look for
|
||||
* @param[in] ch New input character
|
||||
* @param[in,out] state A state integer holding how far we have parsed.
|
||||
* @retval 1 Yes, we have detected end tag!
|
||||
* @retval 0 No, we havent detected end tag
|
||||
* @code
|
||||
* int state = 0;
|
||||
* char ch;
|
||||
* while (1) {
|
||||
* // read ch
|
||||
* if (detect_endtag("mypattern", ch, &state)) {
|
||||
* // mypattern is matched
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
int
|
||||
detect_endtag(char *tag,
|
||||
char ch,
|
||||
int *state)
|
||||
{
|
||||
int retval = 0;
|
||||
|
||||
if (tag[*state] == ch){
|
||||
(*state)++;
|
||||
if (*state == strlen(tag)){
|
||||
*state = 0;
|
||||
retval = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
*state = 0;
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Read from socket and append to cbuf
|
||||
*
|
||||
* @param[in] s Socket where input arrives. Read from this.
|
||||
|
|
@ -194,9 +231,10 @@ netconf_input_msg2(unsigned char **bufp,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Process incoming frame, ie a char message framed by ]]>]]>
|
||||
/*! Parse incoming frame (independent of framing)
|
||||
*
|
||||
* Parse string to xml, check only one netconf message within a frame
|
||||
* A relatively high-level function.
|
||||
* @param[in] cb Packet buffer
|
||||
* @param[in] yb Yang binding: Y_RPC for server-side, Y_NONE for client-side (for now)
|
||||
* @param[in] yspec Yang spec
|
||||
|
|
@ -268,4 +306,3 @@ netconf_input_frame2(cbuf *cb,
|
|||
retval = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue