void freetransfer(struct transfer *transfer)
{
- struct transarg *ta;
-
if(transfer == transfers)
transfers = transfer->next;
if(transfer->next != NULL)
CBCHAINFREE(transfer, trans_p);
CBCHAINFREE(transfer, trans_destroy);
CBCHAINFREE(transfer, trans_filterout);
- while((ta = transfer->args) != NULL)
- {
- transfer->args = ta->next;
- free(ta->rec);
- free(ta->val);
- free(ta);
- }
+ while(transfer->args != NULL)
+ freewcspair(transfer->args, &transfer->args);
if(transfer->filter != -1)
killfilter(transfer);
if(transfer->etimer != NULL)
return(new);
}
-void transferaddarg(struct transfer *transfer, wchar_t *rec, wchar_t *val)
-{
- struct transarg *ta;
-
- ta = smalloc(sizeof(*ta));
- ta->rec = swcsdup(rec);
- ta->val = swcsdup(val);
- ta->next = transfer->args;
- transfer->args = ta;
-}
-
void transferattach(struct transfer *transfer, struct transferiface *iface, void *data)
{
if(transfer->iface != NULL)
char **argv;
size_t argvsize, argvdata;
struct socket *insock, *outsock;
- struct transarg *ta;
+ struct wcspair *ta;
char *rec, *val;
wfilename = transfer->path;
}
for(ta = transfer->args; ta != NULL; ta = ta->next)
{
- if((rec = icwcstombs(ta->rec, NULL)) == NULL)
+ if((rec = icwcstombs(ta->key, NULL)) == NULL)
continue;
if((val = icwcstombs(ta->val, NULL)) == NULL)
continue;
void (*wantdata)(struct transfer *transfer, void *data);
};
-struct transarg
-{
- struct transarg *next;
- wchar_t *rec;
- wchar_t *val;
-};
-
struct transfer
{
struct transfer *next, *prev;
struct fnetnode *fn;
void *ifacedata;
struct socket *localend;
- struct transarg *args;
+ struct wcspair *args;
pid_t filter;
struct authhandle *auth;
struct socket *filterout;
void resettransfer(struct transfer *transfer);
void transfersetlocalend(struct transfer *transfer, struct socket *sk);
void *transfergetdata(struct transfer *transfer, size_t *size);
-void transferaddarg(struct transfer *transfer, wchar_t *rec, wchar_t *val);
int forkfilter(struct transfer *transfer);
void transferputdata(struct transfer *transfer, void *buf, size_t size);
size_t transferdatasize(struct transfer *transfer);
{
transfersethash(transfer, parsehash(argv[i + 1]));
} else {
- transferaddarg(transfer, argv[i], argv[i + 1]);
+ newwcspair(argv[i], argv[i + 1], &transfer->args);
}
}
}
static void cmd_lstrarg(struct socket *sk, struct uidata *data, int argc, wchar_t **argv)
{
struct transfer *transfer;
- struct transarg *ta;
+ struct wcspair *ta;
haveargs(2);
havepriv(PERM_TRANS);
sq(sk, 0, L"201", L"Transfer has no arguments", NULL);
} else {
for(ta = transfer->args; ta != NULL; ta = ta->next)
- sq(sk, ta->next != NULL, L"200", L"%%ls", ta->rec, L"%%ls", ta->val, NULL);
+ sq(sk, ta->next != NULL, L"200", L"%%ls", ta->key, L"%%ls", ta->val, NULL);
}
}
}
return(NULL);
}
+
+struct wcspair *newwcspair(wchar_t *key, wchar_t *val, struct wcspair **list)
+{
+ struct wcspair *pair;
+
+ pair = smalloc(sizeof(*pair));
+ memset(pair, 0, sizeof(*pair));
+ if(key != NULL)
+ pair->key = swcsdup(key);
+ if(val != NULL)
+ pair->val = swcsdup(val);
+ if(list == NULL)
+ {
+ pair->next = NULL;
+ } else {
+ pair->next = *list;
+ *list = pair;
+ }
+ return(pair);
+}
+
+void freewcspair(struct wcspair *pair, struct wcspair **list)
+{
+ if(list != NULL)
+ {
+ if(*list == pair)
+ *list = pair->next;
+ }
+ free(pair->key);
+ free(pair->val);
+ free(pair);
+}
#include <malloc.h>
#include "log.h"
+struct wcspair {
+ struct wcspair *next;
+ wchar_t *key;
+ wchar_t *val;
+};
+
/* "Safe" functions */
#define smalloc(size) ({void *__result__; ((__result__ = malloc(size)) == NULL)?({LOGOOM(size); abort(); (void *)0;}):__result__;})
#define srealloc(ptr, size) ({void *__result__; ((__result__ = realloc((ptr), (size))) == NULL)?({LOGOOM(size); abort(); (void *)0;}):__result__;})
#if defined(__GNUC__) && 0
__attribute__ ((format (printf, 1, 2)))
#endif
-
;
wchar_t *vswprintf2(wchar_t *format, va_list al);
wchar_t *swprintf2(wchar_t *format, ...);
void _freeparr(void **arr);
int _parrlen(void **arr);
char *findfile(char *gname, char *uname, char *homedir);
+struct wcspair *newwcspair(wchar_t *key, wchar_t *val, struct wcspair **list);
+void freewcspair(struct wcspair *pair, struct wcspair **list);
#define sizebuf(b, bs, rs, es, a) _sizebuf((void **)(b), (bs), (rs), (es), (a))
#define sizebuf2(b, rs, a) _sizebuf((void **)(&(b)), &(b ## size), (rs), sizeof(*(b)), (a))