Esempio n. 1
0
File: config.c Progetto: CingHu/code
bool
update_password_config()
{
    bool ok;
    header_list_t *list;

    log_info("Update password configuration, updating password is done");

    if (file_exist(Config.config_file)) {
        list = hl_load_config(Config.config_file);

        if (list == NULL) {
            log_error("Could not load configuration");
            return false;
        }

    } else {
        list = header_list_new();
    }

    hl_set(list, "update_password", "no", rel_none);

    ok = hl_write_config(Config.config_file, list);

    if (!ok) {
        log_error("Could not write configuration");
        return false;
    }

    header_list_free(list);

    return true;
}
Esempio n. 2
0
static void
test_remove_at (void)
{
	const char *name, *value;
	GMimeHeaderList *list;
	GMimeHeader *header;
	int count;
	
	list = header_list_new ();
	
	testsuite_check ("remove first header");
	try {
		/* remove the first header */
		g_mime_header_list_remove_at (list, 0);
		
		/* make sure the first header is now the same as the second original header */
		header = g_mime_header_list_get_header_at (list, 0);
		name = g_mime_header_get_name (header);
		value = g_mime_header_get_value (header);
		
		if (strcmp (initial[1].name, name) != 0 ||
		    strcmp (initial[1].value, value) != 0)
			throw (exception_new ("expected second Received header"));
		
		/* make sure that the internal hash table was properly updated */
		if (!(header = g_mime_header_list_get_header (list, "Received")))
			throw (exception_new ("lookup of Received header failed"));
		
		if (!(value = g_mime_header_get_value (header)))
			throw (exception_new ("getting Received header value failed"));
		
		if (strcmp (initial[1].value, value) != 0)
			throw (exception_new ("expected second Received header value"));
		
		testsuite_check_passed ();
	} catch (ex) {
		testsuite_check_failed ("remove first header: %s", ex->message);
	} finally;
	
	testsuite_check ("remove last header");
	try {
		/* remove the last header */
		count = g_mime_header_list_get_count (list);
		g_mime_header_list_remove_at (list, count - 1);
		
		if ((header = g_mime_header_list_get_header (list, "Message-Id")) != NULL)
			throw (exception_new ("lookup of Message-Id should have failed"));
		
		testsuite_check_passed ();
	} catch (ex) {
		testsuite_check_failed ("remove last header: %s", ex->message);
	} finally;
	
	g_object_unref (list);
}
Esempio n. 3
0
static void
test_indexing (void)
{
	const char *name, *value, *raw_value;
	GMimeHeaderList *list;
	GMimeHeader *header;
	int index;
	size_t len;
	
	list = header_list_new ();
	
	/* make sure indexing works as expected */
	for (index = 0; index < G_N_ELEMENTS (initial); index++) {
		testsuite_check ("headers[%d]", index);
		try {
			if (!(header = g_mime_header_list_get_header_at (list, index)))
				throw (exception_new ("failed to get header at index"));
			
			name = g_mime_header_get_name (header);
			value = g_mime_header_get_value (header);
			
			if (strcmp (initial[index].name, name) != 0 ||
			    strcmp (initial[index].value, value) != 0)
				throw (exception_new ("resulted in unexpected value"));
			
			if (!(raw_value = g_mime_header_get_raw_value (header)))
				throw (exception_new ("null raw value"));
			
			len = strlen (raw_value);
			if (raw_value[len - 1] != '\n')
				throw (exception_new ("raw value does not end with a \\n"));
			
			testsuite_check_passed ();
		} catch (ex) {
			testsuite_check_failed ("next iter[%d]: %s", index, ex->message);
		} finally;
	}
	
	/* make sure trying to advance past the last header fails */
	testsuite_check ("indexing past end of headers");
	try {
		if (g_mime_header_list_get_header_at (list, index) != NULL)
			throw (exception_new ("should not have worked"));
		testsuite_check_passed ();
	} catch (ex) {
		testsuite_check_failed ("indexing past end of headers: %s", ex->message);
	} finally;
	
	g_object_unref (list);
}