diff options
author | Felipe Contreras <felipe.contreras@gmail.com> | 2010-06-13 02:47:56 +0300 |
---|---|---|
committer | Felipe Contreras <felipe.contreras@gmail.com> | 2010-06-14 02:47:15 +0300 |
commit | d9bfd9b8d15c4acaad97bc15bd08541c2515ece5 (patch) | |
tree | fe686d9010cf6053612c8495b76f0c0ab96b4b2d | |
parent | 89202e739442f2ab435c69159610ca4e0269f114 (diff) |
Add pn_trans
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
-rw-r--r-- | Makefile | 1 | ||||
-rw-r--r-- | pn_trans.c | 35 | ||||
-rw-r--r-- | pn_trans.h | 14 |
3 files changed, 50 insertions, 0 deletions
@@ -18,6 +18,7 @@ QUIET_CLEAN = @echo ' CLEAN '$@; endif test: test.o pn_core.o pn_session.o pn_node.o \ + pn_trans.o \ pn_log.o pn_printf.o test: override CFLAGS += $(GIO_CFLAGS) test: override LIBS += $(GIO_LIBS) diff --git a/pn_trans.c b/pn_trans.c new file mode 100644 index 0000000..08d9aa2 --- /dev/null +++ b/pn_trans.c @@ -0,0 +1,35 @@ +#include "pn_trans.h" + +#include <glib.h> + +struct pn_trans * +pn_trans_new(void) +{ + return g_new0(struct pn_trans, 1); +} + +void +pn_trans_free(struct pn_trans *trans) +{ + if (!trans) + return; + + g_free(trans->command); + g_free(trans->params); + g_free(trans); +} + +char * +pn_trans_to_string(struct pn_trans *trans) +{ + char *str; + + if (trans->params) + str = g_strdup_printf("%s %u %s\r\n", + trans->command, trans->id, trans->params); + else + str = g_strdup_printf("%s %u\r\n", + trans->command, trans->id); + + return str; +} diff --git a/pn_trans.h b/pn_trans.h new file mode 100644 index 0000000..397efb8 --- /dev/null +++ b/pn_trans.h @@ -0,0 +1,14 @@ +#ifndef PN_TRANS_H +#define PN_TRANS_H + +struct pn_trans { + int id; + char *command; + char *params; +}; + +struct pn_trans *pn_trans_new(void); +void pn_trans_free(struct pn_trans *trans); +char *pn_trans_to_string(struct pn_trans *trans); + +#endif /* PN_TRANS_H */ |