5 // the universe is bound in equal parts by arrogance and altruism, any attempt to alter this would be suicide
7 int _sd2txt_len(const char *key, char *val)
16 void _sd2txt_count(xht h, const char *key, void *val, void *arg)
18 int *count = (int*)arg;
19 *count += _sd2txt_len(key,(char*)val) + 1;
22 void _sd2txt_write(xht h, const char *key, void *val, void *arg)
24 unsigned char **txtp = (unsigned char **)arg;
25 char *cval = (char*)val;
27 // copy in lengths, then strings
28 **txtp = _sd2txt_len(key,(char*)val);
30 memcpy(*txtp,key,strlen(key));
35 memcpy(*txtp,cval,strlen(cval));
36 *txtp += strlen(cval);
39 unsigned char *sd2txt(xht h, int *len)
41 unsigned char *buf, *raw;
44 xht_walk(h,_sd2txt_count,(void*)len);
48 buf = (unsigned char *)malloc(1);
52 raw = buf = (unsigned char *)malloc(*len);
53 xht_walk(h,_sd2txt_write,&buf);
57 xht txt2sd(unsigned char *txt, int len)
62 if(txt == 0 || len == 0 || *txt == 0) return 0;
65 // loop through data breaking out each block, storing into hashtable
66 for(;*txt <= len && len > 0; len -= *txt, txt += *txt + 1)
69 memcpy(key,txt+1,*txt);
71 if((val = strchr(key,'=')) != 0)
76 xht_store(h, key, strlen(key), val, val ? strlen(val) : 0);