CliXoN
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions | Variables
clixon_proto.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <syslog.h>
#include <signal.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <arpa/inet.h>
#include <cligen/cligen.h>
#include "clixon_err.h"
#include "clixon_log.h"
#include "clixon_queue.h"
#include "clixon_chunk.h"
#include "clixon_sig.h"
#include "clixon_xml.h"
#include "clixon_xsl.h"
#include "clixon_proto.h"

Functions

char * format_int2str (enum format_enum showas)
 
enum format_enum format_str2int (char *str)
 
struct clicon_msg * clicon_msg_encode (char *format,...)
 
int clicon_msg_decode (struct clicon_msg *msg, cxobj **xml)
 
int clicon_connect_unix (char *sockpath)
 
static void atomicio_sig_handler (int arg)
 
static ssize_t atomicio (ssize_t(*fn)(int, void *, size_t), int fd, void *_s, size_t n)
 
static int msg_dump (struct clicon_msg *msg)
 
int clicon_msg_send (int s, struct clicon_msg *msg)
 
int clicon_msg_rcv (int s, struct clicon_msg **msg, int *eof)
 
int clicon_rpc_connect_unix (struct clicon_msg *msg, char *sockpath, char **retdata, int *sock0)
 
int clicon_rpc_connect_inet (struct clicon_msg *msg, char *dst, uint16_t port, char **retdata, int *sock0)
 
int clicon_rpc (int s, struct clicon_msg *msg, char **ret)
 
int send_msg_reply (int s, char *data, uint16_t datalen)
 
int send_msg_notify (int s, int level, char *event)
 

Variables

static int _atomicio_sig = 0
 
struct formatvec _YYERROR
 
static struct formatvec _FORMATS []
 

Function Documentation

static ssize_t atomicio ( ssize_t(*)(int, void *, size_t)  fn,
int  fd,
void *  _s,
size_t  n 
)
static

Ensure all of data on socket comes through. fn is either read or write

static void atomicio_sig_handler ( int  arg)
static
int clicon_connect_unix ( char *  sockpath)

Open local connection using unix domain sockets

int clicon_msg_decode ( struct clicon_msg *  msg,
cxobj **  xml 
)

Decode a clicon netconf message

struct clicon_msg* clicon_msg_encode ( char *  format,
  ... 
)

Encode a clicon netconf message

Parameters
[in]paramVariable agrument list format an XML netconf string
Return values
msgClicon message to send to eg clicon_msg_send()
int clicon_msg_rcv ( int  s,
struct clicon_msg **  msg,
int *  eof 
)

Receive a CLICON message on a UNIX domain socket

XXX: timeout? and signals? There is rudimentary code for turning on signals and handling them so that they can be interrupted by ^C. But the problem is that this is a library routine and such things should be set up in the cli application for example: a daemon calling this function will want another behaviour. Now, ^C will interrupt the whole process, and this may not be what you want.

Parameters
[in]sUNIX domain socket to communicate with backend
[out]msgCLICON msg data reply structure. Free with free()
[out]eofSet if eof encountered Note: caller must ensure that s is closed if eof is set after call.
int clicon_msg_send ( int  s,
struct clicon_msg *  msg 
)
int clicon_rpc ( int  s,
struct clicon_msg *  msg,
char **  ret 
)

Send a clicon_msg message and wait for result.

TBD: timeout, interrupt? retval may be -1 and errno set to ENOTCONN which means that socket is now closed probably due to remote peer disconnecting. The caller may have to do something,...

Parameters
[in]sSocket to communicate with backend
[in]msgCLICON msg data structure. It has fixed header and variable body.
[out]xretReturned data as netconf xml tree.
Return values
0OK
-1Error
int clicon_rpc_connect_inet ( struct clicon_msg *  msg,
char *  dst,
uint16_t  port,
char **  retdata,
int *  sock0 
)

Connect to server, send a clicon_msg message and wait for result using an inet socket This uses unix domain socket communication

Parameters
[in]msgCLICON msg data structure. It has fixed header and variable body.
[in]dstIPv4 address
[in]portTCP port
[out]retdataReturned data as string netconf xml tree.
[out]sock0Return socket in case of asynchronous notify
Return values
0OK
-1Error
See Also
clicon_rpc But this is one-shot rpc: open, send, get reply and close.
int clicon_rpc_connect_unix ( struct clicon_msg *  msg,
char *  sockpath,
char **  retdata,
int *  sock0 
)

Connect to server, send a clicon_msg message and wait for result using unix socket

Parameters
[in]msgCLICON msg data structure. It has fixed header and variable body.
[in]sockpathUnix domain file path
[out]retdataReturned data as string netconf xml tree.
[out]sock0Return socket in case of asynchronous notify
Return values
0OK
-1Error
See Also
clicon_rpc But this is one-shot rpc: open, send, get reply and close.
char* format_int2str ( enum format_enum  showas)

Translate from numeric error to string representation

enum format_enum format_str2int ( char *  str)
static int msg_dump ( struct clicon_msg *  msg)
static
int send_msg_notify ( int  s,
int  level,
char *  event 
)

Send a clicon_msg NOTIFY message asynchronously to client

Parameters
[in]sSocket to communicate with client
[in]level
[in]event
Return values
0OK
-1Error
int send_msg_reply ( int  s,
char *  data,
uint16_t  datalen 
)

Send a clicon_msg message as reply to a clicon rpc request

Parameters
[in]sSocket to communicate with client
[in]dataReturned data as byte-string.
[in]datalenLength of returned data XXX may be unecessary if always string?
Return values
0OK
-1Error

Variable Documentation

int _atomicio_sig = 0
static
struct formatvec _FORMATS[]
static
Initial value:
= {
{"xml", FORMAT_XML},
{"text", FORMAT_TEXT},
{"json", FORMAT_JSON},
{"cli", FORMAT_CLI},
{"netconf", FORMAT_NETCONF},
{NULL, -1}
}
input_stmt NULL
Definition: clixon_yang_parse.y:899
struct formatvec _YYERROR