char * dispatch_docstring (const char *text) { mu_stream_t str; struct mutool_action_tab *p; mu_off_t size; size_t n; char *ret; mu_memory_stream_create (&str, MU_STREAM_RDWR); mu_stream_printf (str, "%s\n%s\n\n", text, _("Commands are:")); for (p = mutool_action_tab; p->name; p++) mu_stream_printf (str, " %s %-16s - %s\n", mu_program_name, p->name, gettext (p->docstring)); mu_stream_printf (str, _("\nTry `%s COMMAND --help' to get help on a particular " "COMMAND.\n\n"), mu_program_name); mu_stream_printf (str, "%s\n", _("Options are:")); mu_stream_flush (str); mu_stream_size (str, &size); ret = mu_alloc (size + 1); mu_stream_seek (str, 0, MU_SEEK_SET, NULL); mu_stream_read (str, ret, size, &n); ret[n] = 0; mu_stream_destroy (&str); return ret; }
struct imap4d_tokbuf * imap4d_tokbuf_init () { struct imap4d_tokbuf *tok = mu_alloc (sizeof (tok[0])); memset (tok, 0, sizeof (*tok)); return tok; }
static void pop3d_append_capa_string (struct pop3d_session *sess, const char *name, const char *value) { struct pop3d_capa *cp; cp = mu_alloc (sizeof (*cp)); cp->type = capa_string; cp->name = name; cp->value.string = value ? mu_strdup (value) : NULL; if (mu_list_append (sess->capa, cp)) mu_alloc_die (); }
static void pop3d_append_capa_func (struct pop3d_session *sess, const char *name, void (*func) (const char *, struct pop3d_session *)) { struct pop3d_capa *cp; if (!func) return; cp = mu_alloc (sizeof (*cp)); cp->type = capa_func; cp->name = name; cp->value.func = func; if (mu_list_append (sess->capa, cp)) mu_alloc_die (); }
void auth_add (char *name, imap4d_auth_handler_fp handler) { struct imap_auth *p = mu_alloc (sizeof (*p)); p->name = name; p->handler = handler; if (!imap_auth_list) { mu_list_create (&imap_auth_list); mu_list_set_comparator (imap_auth_list, comp); mu_list_set_destroy_item (imap_auth_list, mu_list_free_item); } mu_list_append (imap_auth_list, (void*)p); }
static fn_t *fn_realize(struct fnparse *fnparse, eh_t *eh) { // this is a bit tricky since fn and p->fn share memory fn_t *fn = (fn_t *)fnparse; tbl_t *vars = fnparse->vars; tbl_t *fns = fnparse->fns; fn->vcount = vars->len; fn->fcount = fns->len; fn->stack = 25; // TODO make this reasonable fn->vars = mu_alloc(fn->vcount*sizeof(var_t) + fn->fcount*sizeof(fn_t *), eh); tbl_for_begin (k, v, vars) { fn->vars[getraw(v)] = k; } tbl_for_end; int i = 0; fn->fns = (fn_t**)&fn->vars[fn->vcount]; tbl_for_begin (k, v, fns) { fn->fns[i++] = (fn_t*)getraw(v); } tbl_for_end;
const char * alias_iterate_first (const char *prefix, alias_iterator_t *pc) { mu_iterator_t itr; alias_iterator_t atr; if (!aliases) { *pc = NULL; return NULL; } if (mu_assoc_get_iterator (aliases, &itr)) return NULL; mu_iterator_first (itr); atr = mu_alloc (sizeof *atr); atr->prefix = prefix; atr->prefixlen = strlen (prefix); atr->pos = 0; atr->itr = itr; *pc = atr; return alias_iterate_next (atr); }
/* The main part of the daemon. This function reads input from the client and executes the proper functions. Also handles the bulk of error reporting. Arguments: ifd -- input descriptor ofd -- output descriptor tls -- initiate encrypted connection */ int pop3d_mainloop (int ifd, int ofd, enum tls_mode tls) { int status = OK; char buffer[512]; static int sigtab[] = { SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGSTOP, SIGPIPE, SIGABRT, SIGINT, SIGQUIT, SIGTERM, SIGHUP, SIGALRM }; struct pop3d_session session; mu_set_signals (pop3d_child_signal, sigtab, MU_ARRAY_SIZE (sigtab)); if (tls == tls_unspecified) tls = tls_available ? tls_ondemand : tls_no; else if (tls != tls_no && !tls_available) { mu_error (_("TLS is not configured, but requested in the " "configuration")); tls = tls_no; } pop3d_setio (ifd, ofd, tls == tls_connection); if (tls == tls_required) initial_state = INITIAL; state = tls == tls_connection ? AUTHORIZATION : initial_state; pop3d_session_init (&session); session.tls = tls; /* FIXME: state should also be in the session? */ /* Prepare the shared secret for APOP. */ { char *local_hostname; status = mu_get_host_name (&local_hostname); if (status) { mu_diag_funcall (MU_DIAG_ERROR, "mu_get_host_name", NULL, status); exit (EXIT_FAILURE); } md5shared = mu_alloc (strlen (local_hostname) + 51); snprintf (md5shared, strlen (local_hostname) + 50, "<%u.%u@%s>", getpid (), (unsigned)time (NULL), local_hostname); free (local_hostname); } /* Lets boogie. */ pop3d_outf ("+OK POP3 Ready %s\n", md5shared); while (state != UPDATE && state != ABORT) { char *buf; char *arg, *cmd; pop3d_command_handler_t handler; pop3d_flush_output (); status = OK; buf = pop3d_readline (buffer, sizeof (buffer)); pop3d_parse_command (buf, &cmd, &arg); if (state == TRANSACTION && !mu_mailbox_is_updated (mbox)) { static mu_off_t mailbox_size; mu_off_t newsize = 0; mu_mailbox_get_size (mbox, &newsize); /* Did we shrink? First time save the size. */ if (!mailbox_size) mailbox_size = newsize; else if (newsize < mailbox_size) /* FIXME: Should it be a != ? */ pop3d_abquit (ERR_MBOX_SYNC); /* Out of sync, Bail out. */ } /* Refresh the Lock. */ manlock_touchlock (mbox); if ((handler = pop3d_find_command (cmd)) != NULL) status = handler (arg, &session); else status = ERR_BAD_CMD; if (status != OK) pop3d_outf ("-ERR %s\n", pop3d_error_string (status)); } pop3d_session_free (&session); pop3d_bye (); return status; }