aboutsummaryrefslogtreecommitdiffstats
path: root/set.h
blob: 48bc8145e41d669467981d3b8e2cd8250c571ee9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  /********************************************************************\
  * BitlBee -- An IRC to other IM-networks gateway                     *
  *                                                                    *
  * Copyright 2002-2006 Wilmer van der Gaast and others                *
  \********************************************************************/

/* Some stuff to register, handle and save user preferences             */

/*
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License with
  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
  Suite 330, Boston, MA  02111-1307  USA
*/

typedef struct set
{
	void *data;
	
	char *key;
	char *value;
	char *def;	/* Default */
	
	int flags;
	
	/* Eval: Returns NULL if the value is incorrect or exactly the
	   passed value variable. When returning a corrected value,
	   set_setstr() should be able to free() the returned string! */
	char *(*eval) ( struct set *set, char *value );
	struct set *next;
} set_t;

set_t *set_add( set_t **head, char *key, char *def, void *eval, void *data );
set_t *set_find( set_t **head, char *key );
G_MODULE_EXPORT char *set_getstr( set_t **head, char *key );
G_MODULE_EXPORT int set_getint( set_t **head, char *key );
G_MODULE_EXPORT int set_getbool( set_t **head, char *key );
int set_setstr( set_t **head, char *key, char *value );
int set_setint( set_t **head, char *key, int value );
void set_del( set_t **head, char *key );

char *set_eval_int( set_t *set, char *value );
char *set_eval_bool( set_t *set, char *value );

char *set_eval_to_char( set_t *set, char *value );
char *set_eval_ops( set_t *set, char *value );
char *set_eval_charset( set_t *set, char *value );
pan> }; for (i = 0; get[i]; i++) { char copy[20], *ret; strcpy(copy, get[i]); ret = strip_newlines(copy); fail_unless (strcmp(copy, expected[i]) == 0, "(%d) strip_newlines broken: %s -> %s (expected: %s)", i, get[i], copy, expected[i]); fail_unless (copy == ret, "Original string not returned"); } } END_TEST START_TEST(test_set_url_http) url_t url; fail_if (0 == url_set(&url, "http://host/")); fail_unless (!strcmp(url.host, "host")); fail_unless (!strcmp(url.file, "/")); fail_unless (!strcmp(url.user, "")); fail_unless (!strcmp(url.pass, "")); fail_unless (url.proto == PROTO_HTTP); fail_unless (url.port == 80); END_TEST START_TEST(test_set_url_https) url_t url; fail_if (0 == url_set(&url, "https://ahost/AimeeMann")); fail_unless (!strcmp(url.host, "ahost")); fail_unless (!strcmp(url.file, "/AimeeMann")); fail_unless (!strcmp(url.user, "")); fail_unless (!strcmp(url.pass, "")); fail_unless (url.proto == PROTO_HTTPS); fail_unless (url.port == 443); END_TEST START_TEST(test_set_url_port) url_t url; fail_if (0 == url_set(&url, "https://ahost:200/Lost/In/Space")); fail_unless (!strcmp(url.host, "ahost")); fail_unless (!strcmp(url.file, "/Lost/In/Space")); fail_unless (!strcmp(url.user, "")); fail_unless (!strcmp(url.pass, "")); fail_unless (url.proto == PROTO_HTTPS); fail_unless (url.port == 200); END_TEST START_TEST(test_set_url_username) url_t url; fail_if (0 == url_set(&url, "socks4://user@ahost/Space")); fail_unless (!strcmp(url.host, "ahost")); fail_unless (!strcmp(url.file, "/Space")); fail_unless (!strcmp(url.user, "user")); fail_unless (!strcmp(url.pass, "")); fail_unless (url.proto == PROTO_SOCKS4); fail_unless (url.port == 1080); END_TEST START_TEST(test_set_url_username_pwd) url_t url; fail_if (0 == url_set(&url, "socks5://user:pass@ahost/")); fail_unless (!strcmp(url.host, "ahost")); fail_unless (!strcmp(url.file, "/")); fail_unless (!strcmp(url.user, "user")); fail_unless (!strcmp(url.pass, "pass")); fail_unless (url.proto == PROTO_SOCKS5); fail_unless (url.port == 1080); END_TEST struct { char *orig; int line_len; char *wrapped; } word_wrap_tests[] = { { "Line-wrapping is not as easy as it seems?", 16, "Line-wrapping is\nnot as easy as\nit seems?" }, { "Line-wrapping is not as easy as it seems?", 8, "Line-\nwrapping\nis not\nas easy\nas it\nseems?" }, { "Line-wrapping is\nnot as easy as it seems?", 8, "Line-\nwrapping\nis\nnot as\neasy as\nit\nseems?" }, { "a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa", 5, "a aa\naaa\naaaa\naaaaa\naaaaa\na\naaaaa\naa\naaaaa\naaa", }, { "aaaaaaaa aaaaaaa aaaaaa aaaaa aaaa aaa aa a", 5, "aaaaa\naaa\naaaaa\naa\naaaaa\na\naaaaa\naaaa\naaa\naa a", }, { "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 5, "aaaaa\naaaaa\naaaaa\naaaaa\naaaaa\naaaaa\naaaaa\na", }, { NULL } }; START_TEST(test_word_wrap) int i; for( i = 0; word_wrap_tests[i].orig && *word_wrap_tests[i].orig; i ++ ) { char *wrapped = word_wrap( word_wrap_tests[i].orig, word_wrap_tests[i].line_len ); fail_unless( strcmp( word_wrap_tests[i].wrapped, wrapped ) == 0, "%s (line_len = %d) should wrap to `%s', not to `%s'", word_wrap_tests[i].orig, word_wrap_tests[i].line_len, word_wrap_tests[i].wrapped, wrapped ); g_free( wrapped ); } END_TEST START_TEST(test_http_encode) char s[80]; strcpy( s, "ee\xc3""\xab""ee!!..." ); http_encode( s ); fail_unless( strcmp( s, "ee%C3%ABee%21%21..." ) == 0 ); END_TEST Suite *util_suite (void) { Suite *s = suite_create("Util"); TCase *tc_core = tcase_create("Core"); suite_add_tcase (s, tc_core); tcase_add_test (tc_core, test_strip_linefeed); tcase_add_test (tc_core, test_strip_newlines); tcase_add_test (tc_core, test_set_url_http); tcase_add_test (tc_core, test_set_url_https); tcase_add_test (tc_core, test_set_url_port); tcase_add_test (tc_core, test_set_url_username); tcase_add_test (tc_core, test_set_url_username_pwd); tcase_add_test (tc_core, test_word_wrap); tcase_add_test (tc_core, test_http_encode); return s; }