summaryrefslogtreecommitdiffstats
path: root/jacs/roster.c
diff options
context:
space:
mode:
Diffstat (limited to 'jacs/roster.c')
-rw-r--r--jacs/roster.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/jacs/roster.c b/jacs/roster.c
new file mode 100644
index 0000000..d4cc372
--- /dev/null
+++ b/jacs/roster.c
@@ -0,0 +1,102 @@
+/*
+ * Copy me if you can.
+ * by 20h
+ */
+
+#include <u.h>
+#include <libc.h>
+#include "dat.h"
+#include "roster.h"
+
+void
+freeilist(ilist *i)
+{
+ while(i != nil){
+ if(i->name != nil)
+ free(i->name);
+ if(i->val != nil)
+ free(i->val);
+ if(i->n != nil){
+ i = i->n;
+ free(i->p);
+ } else {
+ free(i);
+ i = nil;
+ }
+ }
+}
+
+
+void
+freejabberc(jabberc *j)
+{
+ if(j != nil){
+ if(j->stat != nil)
+ free(j->stat);
+ if(j->name != nil)
+ free(j->name);
+ if(j->reso != nil)
+ free(j->reso);
+ if(j->serv != nil)
+ free(j->serv);
+ if(j->jid != nil)
+ free(j->jid);
+ if(j->show != nil)
+ free(j->show);
+ if(j->dest != nil)
+ free(j->dest);
+ if(j->list != nil)
+ freeilist(j->list);
+ free(j);
+ }
+ return;
+}
+
+jabberc *
+mkjabberc(void)
+{
+ return reallocj(nil, sizeof(jabberc), 2);
+}
+
+ilist *
+lastilist(ilist *i)
+{
+ if(i != nil)
+ while(i->n != nil)
+ i = i->n;
+
+ return i;
+}
+
+ilist *
+mkilist(char *name, char *val)
+{
+ ilist *ret;
+
+ ret = reallocj(nil, sizeof(ilist), 2);
+ if(name != nil)
+ ret->name = strdup(name);
+ if(val != nil)
+ ret->val = strdup(val);
+
+ return ret;
+}
+
+ilist *
+addilist(ilist *i, char *name, char *val)
+{
+ ilist *ret;
+
+ ret = lastilist(i);
+ if(ret == nil)
+ return mkilist(name, val);
+ else {
+ ret->n = mkilist(name, val);
+ ret->n->p = ret;
+ }
+ ret->n->n = nil;
+
+ return i;
+}
+
+ \ No newline at end of file