X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-mx%2Fpop-new.c;h=a7e135d50361b8afdc977d8034bd9e526c430121;hp=3936cbbfc6d44efa11af2c21a5bc22cae6a3bb2a;hb=a833478d0bab31dd0016520da5049bdf45b29736;hpb=6b4475312b058043257fba4526817f60d9e26baf diff --git a/lib-mx/pop-new.c b/lib-mx/pop-new.c index 3936cbb..a7e135d 100644 --- a/lib-mx/pop-new.c +++ b/lib-mx/pop-new.c @@ -21,14 +21,17 @@ #include #include "pop.h" +#include "account.h" typedef struct pop_data_t { int refcnt; job_t *w; + + ACCOUNT account; } pop_data_t; DO_INIT(pop_data_t, pop_data); DO_WIPE(pop_data_t, pop_data); -DO_REFCNT(pop_data_t, pop_data); +static void pop_data_delete(pop_data_t **tp); DO_ARRAY_TYPE(pop_data_t, pop_data); DO_ARRAY_FUNCS(pop_data_t, pop_data, pop_data_delete); @@ -38,6 +41,33 @@ DO_ARRAY_FUNCS(pop_data_t, pop_data, pop_data_delete); static pop_data_array conns; +static inline pop_data_t *pop_data_new(void) { + pop_data_t *res = pop_data_init(p_new(pop_data_t, 1)); + res->refcnt = 1; + pop_data_array_append(&conns, res); + return res; +} +static inline pop_data_t *pop_data_dup(pop_data_t *t) { + t->refcnt++; + return t; +} +static void pop_data_delete(pop_data_t **tp) { + if (!*tp) + return; + if (--(*tp)->refcnt > 0) { + *tp = NULL; + } else { + for (int i = 0; i < conns.len; i++) { + if (conns.arr[i] == *tp) { + pop_data_array_take(&conns, i); + break; + } + } + pop_data_wipe(*tp); + p_delete(tp); + } +} + static __init void pop_initialize(void) { pop_data_array_init(&conns); @@ -53,11 +83,14 @@ static __fini void pop_shutdown(void) static int pop_setup(job_t *w, void *cfg) { + w->ptr = cfg; + /* FIXME */ return el_job_release(w, EL_ERROR); return 0; } static void pop_finalize(job_t *w, el_status reason) { + pop_data_delete((pop_data_t **)(void *)&w->ptr); } static machine_t const pop_machine = { @@ -71,17 +104,5 @@ static machine_t const pop_machine = { /****************************************************************************/ mx_t const pop_mx_ng = { - M_POP, - 0, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, + .type = M_POP, };