xmldb
This commit is contained in:
parent
ca18b7f49e
commit
0a812696c2
47 changed files with 1818 additions and 1783 deletions
|
|
@ -58,52 +58,6 @@
|
|||
#include "clixon_proto.h"
|
||||
#include "clixon_proto_encode.h"
|
||||
|
||||
/* Generic encode/decode functions for exactly one C-string (str)
|
||||
*/
|
||||
static struct clicon_msg *
|
||||
clicon_msg_1str_encode(char *str, enum clicon_msg_type op, const char *label)
|
||||
{
|
||||
struct clicon_msg *msg;
|
||||
int hdrlen = sizeof(*msg);
|
||||
uint16_t len;
|
||||
int p;
|
||||
|
||||
assert(str);
|
||||
p = 0;
|
||||
len = sizeof(*msg) + strlen(str) + 1;
|
||||
if ((msg = (struct clicon_msg *)chunk(len, label)) == NULL){
|
||||
clicon_err(OE_PROTO, errno, "%s: chunk", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
memset(msg, 0, len);
|
||||
/* hdr */
|
||||
msg->op_type = htons(op);
|
||||
msg->op_len = htons(len);
|
||||
/* body */
|
||||
strncpy(msg->op_body+p, str, len-p-hdrlen);
|
||||
p += strlen(str)+1;
|
||||
return msg;
|
||||
}
|
||||
|
||||
static int
|
||||
clicon_msg_1str_decode(struct clicon_msg *msg,
|
||||
char **str,
|
||||
const char *label)
|
||||
{
|
||||
int p;
|
||||
|
||||
p = 0;
|
||||
/* body */
|
||||
if ((*str = chunk_sprintf(label, "%s", msg->op_body+p)) == NULL){
|
||||
clicon_err(OE_PROTO, errno, "%s: chunk_sprintf",
|
||||
__FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
p += strlen(*str)+1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
struct clicon_msg *
|
||||
clicon_msg_commit_encode(char *dbsrc, char *dbdst,
|
||||
uint32_t snapshot, uint32_t startup,
|
||||
|
|
@ -544,141 +498,6 @@ clicon_msg_load_decode(struct clicon_msg *msg,
|
|||
return 0;
|
||||
}
|
||||
|
||||
struct clicon_msg *
|
||||
clicon_msg_initdb_encode(char *filename, const char *label)
|
||||
{
|
||||
clicon_debug(2, "%s: db: %s", __FUNCTION__, filename);
|
||||
return clicon_msg_1str_encode(filename, CLICON_MSG_INITDB, label);
|
||||
}
|
||||
|
||||
int
|
||||
clicon_msg_initdb_decode(struct clicon_msg *msg,
|
||||
char **filename,
|
||||
const char *label)
|
||||
{
|
||||
int retval;
|
||||
|
||||
retval = clicon_msg_1str_decode(msg, filename, label);
|
||||
clicon_debug(2, "%s: db: %s", __FUNCTION__, *filename);
|
||||
return retval;
|
||||
}
|
||||
|
||||
struct clicon_msg *
|
||||
clicon_msg_rm_encode(char *filename, const char *label)
|
||||
{
|
||||
clicon_debug(2, "%s: db: %s", __FUNCTION__, filename);
|
||||
return clicon_msg_1str_encode(filename, CLICON_MSG_RM, label);
|
||||
}
|
||||
|
||||
int
|
||||
clicon_msg_rm_decode(struct clicon_msg *msg,
|
||||
char **filename,
|
||||
const char *label)
|
||||
{
|
||||
int retval;
|
||||
|
||||
retval = clicon_msg_1str_decode(msg, filename, label);
|
||||
clicon_debug(2, "%s: db: %s", __FUNCTION__, *filename);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
struct clicon_msg *
|
||||
clicon_msg_copy_encode(char *filename_src, char *filename_dst,
|
||||
const char *label)
|
||||
{
|
||||
struct clicon_msg *msg;
|
||||
int hdrlen = sizeof(*msg);
|
||||
uint16_t len;
|
||||
int p;
|
||||
|
||||
clicon_debug(2, "%s: filename_src: %s filename_dst: %s",
|
||||
__FUNCTION__,
|
||||
filename_src, filename_dst);
|
||||
p = 0;
|
||||
len = hdrlen + strlen(filename_src) + 1 + strlen(filename_dst) + 1;
|
||||
if ((msg = (struct clicon_msg *)chunk(len, label)) == NULL){
|
||||
clicon_err(OE_PROTO, errno, "%s: chunk", __FUNCTION__);
|
||||
return NULL;
|
||||
}
|
||||
memset(msg, 0, len);
|
||||
/* hdr */
|
||||
msg->op_type = htons(CLICON_MSG_COPY);
|
||||
msg->op_len = htons(len);
|
||||
/* body */
|
||||
strncpy(msg->op_body+p, filename_src, len-p-hdrlen);
|
||||
p += strlen(filename_src)+1;
|
||||
strncpy(msg->op_body+p, filename_dst, len-p-hdrlen);
|
||||
p += strlen(filename_dst)+1;
|
||||
return msg;
|
||||
}
|
||||
|
||||
int
|
||||
clicon_msg_copy_decode(struct clicon_msg *msg,
|
||||
char **filename_src, char **filename_dst,
|
||||
const char *label)
|
||||
{
|
||||
int p;
|
||||
|
||||
p = 0;
|
||||
/* body */
|
||||
if ((*filename_src = chunk_sprintf(label, "%s", msg->op_body+p)) == NULL){
|
||||
clicon_err(OE_PROTO, errno, "%s: chunk_sprintf",
|
||||
__FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
p += strlen(*filename_src)+1;
|
||||
|
||||
if ((*filename_dst = chunk_sprintf(label, "%s", msg->op_body+p)) == NULL){
|
||||
clicon_err(OE_PROTO, errno, "%s: chunk_sprintf",
|
||||
__FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
p += strlen(*filename_dst)+1;
|
||||
clicon_debug(2, "%s: filename_src: %s filename_dst: %s",
|
||||
__FUNCTION__,
|
||||
*filename_src, *filename_dst);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct clicon_msg *
|
||||
clicon_msg_lock_encode(char *db, const char *label)
|
||||
{
|
||||
clicon_debug(2, "%s: db: %s", __FUNCTION__, db);
|
||||
return clicon_msg_1str_encode(db, CLICON_MSG_LOCK, label);
|
||||
}
|
||||
|
||||
int
|
||||
clicon_msg_lock_decode(struct clicon_msg *msg,
|
||||
char **db,
|
||||
const char *label)
|
||||
{
|
||||
int retval;
|
||||
|
||||
retval = clicon_msg_1str_decode(msg, db, label);
|
||||
clicon_debug(2, "%s: db: %s", __FUNCTION__, *db);
|
||||
return retval;
|
||||
}
|
||||
|
||||
struct clicon_msg *
|
||||
clicon_msg_unlock_encode(char *db, const char *label)
|
||||
{
|
||||
clicon_debug(2, "%s: db: %s", __FUNCTION__, db);
|
||||
return clicon_msg_1str_encode(db, CLICON_MSG_UNLOCK, label);
|
||||
}
|
||||
|
||||
int
|
||||
clicon_msg_unlock_decode(struct clicon_msg *msg,
|
||||
char **db,
|
||||
const char *label)
|
||||
{
|
||||
int retval;
|
||||
|
||||
retval = clicon_msg_1str_decode(msg, db, label);
|
||||
clicon_debug(2, "%s: db: %s", __FUNCTION__, *db);
|
||||
return retval;
|
||||
}
|
||||
|
||||
struct clicon_msg *
|
||||
clicon_msg_kill_encode(uint32_t session_id, const char *label)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue