コード例 #1
0
ファイル: dm_capa.c プロジェクト: Alexander-KI/dbmail
T Capa_new(Mempool_T pool)
{
	Field_T val;
        char maxcapa[MAX_CAPASIZE];
	T A;
	A = mempool_pop(pool, sizeof(*A));
	A->pool = pool;
	char **v, **h;

	memset(&maxcapa,0,sizeof(maxcapa));

	GETCONFIGVALUE("capability", "IMAP", val);
	if (strlen(val) > 0)
		strncpy((char *)maxcapa, val, MAX_CAPASIZE-1);
	else
		strncpy((char *)maxcapa, IMAP_CAPABILITY_STRING, MAX_CAPASIZE-1);

	A->max_set = p_list_new(A->pool);
	A->current_set = p_list_new(A->pool);

	h = v = g_strsplit(maxcapa, " ", -1);
	while (*v) {
		String_T S = p_string_new(A->pool, *v++);
		A->max_set = p_list_append(A->max_set, S);
		A->current_set = p_list_append(A->current_set, S);
		assert(A->current_set);
	}

	g_strfreev(h);

	A->dirty = TRUE;
	return A;
}
コード例 #2
0
ファイル: dm_capa.c プロジェクト: Alexander-KI/dbmail
void Capa_add(T A, const char *c)
{
	List_T element = capa_search(A->max_set, c);
	if (element) {
		A->current_set = p_list_append(A->current_set, 
				p_list_data(element));
		assert(A->current_set);
		A->dirty = TRUE;
	}
}
コード例 #3
0
ファイル: phashtable.c プロジェクト: saprykin/plibsys
P_LIB_API PList *
p_hash_table_values (const PHashTable *table)
{
	PList		*ret = NULL;
	PHashTableNode	*node;
	puint		i;

	if (P_UNLIKELY (table == NULL))
		return NULL;

	for (i = 0; i < table->size; ++i)
		for (node = table->table[i]; node != NULL; node = node->next)
			ret = p_list_append (ret, node->value);

	return ret;
}
コード例 #4
0
ファイル: phashtable.c プロジェクト: saprykin/plibsys
P_LIB_API PList *
p_hash_table_lookup_by_value (const PHashTable *table, pconstpointer val, PCompareFunc func)
{
	PList		*ret = NULL;
	PHashTableNode	*node;
	puint		i;
	pboolean	res;

	if (P_UNLIKELY (table == NULL))
		return NULL;

	for (i = 0; i < table->size; ++i)
		for (node = table->table[i]; node != NULL; node = node->next) {
			if (func == NULL)
				res = (node->value == val);
			else
				res = (func (node->value, val) == 0);

			if (res)
				ret = p_list_append (ret, node->key);
		}

	return ret;
}
コード例 #5
0
ファイル: timsieve.c プロジェクト: cDoru/dbmail
int tims_tokenizer(ClientSession_T *session, char *buffer)
{
	int command_type = 0;
	char *command, *value = NULL;

	if (! session->command_type) {

		command = buffer;

		strip_crlf(command);
		g_strstrip(command);
		if (! strlen(command)) return FALSE; /* ignore empty commands */

		value = strstr(command, " ");	/* look for the separator */

		if (value != NULL) {
			*value++ = '\0';	/* set a \0 on the command end and skip space */
			if (strlen(value) == 0)
				value = NULL;	/* no value specified */
		}

		for (command_type = TIMS_LOUT; command_type < TIMS_END; command_type++)
			if (strcasecmp(command, commands[command_type]) == 0)
				break;

		/* commands that are allowed to have no arguments */
		if ((value == NULL) && !(command_type <= TIMS_LIST) && (command_type < TIMS_END))
			return tims_error(session, "NO \"This command requires an argument.\"\r\n");

		TRACE (TRACE_DEBUG, "command [%s] value [%s]\n", command, value);
		session->command_type = command_type;
	}

	if (session->ci->rbuff_size) {
		size_t l = strlen(buffer);
		size_t n = min(session->ci->rbuff_size, l);
		p_string_append_len(session->rbuff, buffer, n);
		session->ci->rbuff_size -= n;
		if (! session->ci->rbuff_size) {
			String_T s = p_string_new(session->pool, p_string_str(session->rbuff));
			session->args = p_list_append(session->args, s);
			p_string_printf(session->rbuff, "%s", "");
			session->parser_state = TRUE;
		}
		TRACE(TRACE_DEBUG, "state [%d], size [%" PRIu64 "]", session->parser_state, session->ci->rbuff_size);
		return session->parser_state;
	}

	if (value) {
		char *s = value;
		int i = 0;
		char p = 0, c = 0;
		gboolean inquote = FALSE;
		String_T t = p_string_new(session->pool, "");
		while ((c = s[i++])) {
			if (inquote) {
				if (c == '"' && p != '\\') {
					session->args = p_list_append(session->args, t);
					t = p_string_new(session->pool, "");
					inquote = FALSE;
				} else {
					p_string_append_len(t, &c, 1);
				}
				p = c;
				continue;
			}
			if (c == '"' && p != '\\') {
				inquote = TRUE;
				p = c;
				continue;
			}
			if (c == ' ' && p != '\\') {
				p = c;
				continue;
			}
			if (c == '{') { // a literal...
				session->ci->rbuff_size = strtoull(s+i, NULL, 10);
				return FALSE;
			}
			p_string_append_len(t, &c, 1);
			p = c;
		}
		if (p_string_len(t)) {
			session->args = p_list_append(session->args, t);
		} else {
			p_string_free(t, TRUE);
		}
	} 
	session->parser_state = TRUE;
	
	session->args = p_list_first(session->args);
	while (session->args) {
		String_T s = p_list_data(session->args);
		if (! s)
			break;
		TRACE(TRACE_DEBUG,"arg: [%s]", (char *)p_string_str(s));			
		if (! p_list_next(session->args))
			break;
		session->args = p_list_next(session->args);
	}
	TRACE(TRACE_DEBUG, "[%p] cmd [%d], state [%d] [%s]", session, session->command_type, session->parser_state, buffer);

	return session->parser_state;
}
コード例 #6
0
ファイル: pop3.c プロジェクト: skeyby/dbmail
static int db_createsession(uint64_t user_idnr, ClientSession_T * session)
{
    Connection_T c;
    ResultSet_T r;
    volatile int t = DM_SUCCESS;
    struct message *tmpmessage;
    int message_counter = 0;
    const char *query_result;
    uint64_t mailbox_idnr;
    INIT_QUERY;

    if (db_find_create_mailbox("INBOX", BOX_DEFAULT, user_idnr, &mailbox_idnr) < 0) {
        TRACE(TRACE_NOTICE, "find_create INBOX for user [%" PRIu64 "] failed, exiting..", user_idnr);
        return DM_EQUERY;
    }

    g_return_val_if_fail(mailbox_idnr > 0, DM_EQUERY);

    /* query is < MESSAGE_STATUS_DELETE  because we don't want deleted
     * messages
     */
    snprintf(query, DEF_QUERYSIZE-1,
             "SELECT pm.messagesize, msg.message_idnr, msg.status, "
             "msg.unique_id FROM %smessages msg, %sphysmessage pm "
             "WHERE msg.mailbox_idnr = %" PRIu64 " "
             "AND msg.status < %d "
             "AND msg.physmessage_id = pm.id "
             "ORDER BY msg.message_idnr ASC",DBPFX,DBPFX,
             mailbox_idnr, MESSAGE_STATUS_DELETE);

    c = db_con_get();
    TRY
    r = db_query(c, query);

    session->totalmessages = 0;
    session->totalsize = 0;

    /* messagecounter is total message, +1 tot end at message 1 */
    message_counter = 1;

    /* filling the list */
    TRACE(TRACE_DEBUG, "adding items to list");
    while (db_result_next(r)) {
        tmpmessage = mempool_pop(session->pool, sizeof(struct message));
        /* message size */
        tmpmessage->msize = db_result_get_u64(r,0);
        /* real message id */
        tmpmessage->realmessageid = db_result_get_u64(r,1);
        /* message status */
        tmpmessage->messagestatus = db_result_get_u64(r,2);
        /* virtual message status */
        tmpmessage->virtual_messagestatus = tmpmessage->messagestatus;
        /* unique id */
        query_result = db_result_get(r,3);
        if (query_result)
            strncpy(tmpmessage->uidl, query_result, UID_SIZE-1);

        session->totalmessages++;
        session->totalsize += tmpmessage->msize;
        tmpmessage->messageid = (uint64_t) message_counter;

        session->messagelst = p_list_append(session->messagelst, tmpmessage);

        message_counter++;
    }
    CATCH(SQLException)
    LOG_SQLERROR;
    t = DM_EQUERY;
    FINALLY
    db_con_close(c);
    END_TRY;

    if (t == DM_EQUERY) return t;
    if (message_counter == 1) {
        /* there are no messages for this user */
        return DM_EGENERAL;
    }

    TRACE(TRACE_DEBUG, "adding succesful");

    /* setting all virtual values */
    session->virtual_totalmessages = session->totalmessages;
    session->virtual_totalsize = session->totalsize;

    return DM_EGENERAL;
}