aboutsummaryrefslogtreecommitdiffstats
path: root/perl/Rspamd/InternetAddress.xs
blob: 834117bbe19d5937cfdd3cce341c186727b1f549 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
MODULE = Mail::Rspamd PACKAGE = Mail::Rspamd::InternetAddress PREFIX = rspamd_internet_address_

Mail::Rspamd::InternetAddress
rspamd_internet_address_new (Class, name, address)
	CASE: items <= 1
		char *		Class
	CODE:
		RETVAL = internet_address_new ();
		plist = g_list_prepend (plist, RETVAL);
	OUTPUT:
		RETVAL
	CASE: items == 2
		char *		Class
		char *		name
	CODE:
		RETVAL = internet_address_new_group (name);
		plist = g_list_prepend (plist, RETVAL);
	OUTPUT:
		RETVAL
	CASE: items == 3
		char *		Class
		char *		name
		char *		address
	CODE:
		RETVAL = internet_address_new_name (name, address);
		plist = g_list_prepend (plist, RETVAL);
	OUTPUT:
		RETVAL

void
DESTROY(ia)
		Mail::Rspamd::InternetAddress	ia
	CODE:
		if (g_list_find (plist,ia)) {
			internet_address_unref (ia);
			plist = g_list_remove (plist, ia);
		}

AV *
rspamd_internet_address_parse_string (str)
		const char *		str
	PREINIT:
		InternetAddressList *		addrlist;
		AV * 		retav;
	CODE:
		addrlist = internet_address_parse_string (str);
		retav = newAV ();
		while (addrlist) {
		  SV * address = newSViv (0);
		  sv_setref_pv (address, "Mail::Rspamd::InternetAddress", (Mail__Rspamd__InternetAddress)(addrlist->address));
		  av_push (retav, address);
		  addrlist = addrlist->next;
		}
		RETVAL = retav;
	OUTPUT:
		RETVAL

void
interface_ia_set (ia, value)
		Mail::Rspamd::InternetAddress	ia
	char *				value
	INTERFACE_MACRO:
	XSINTERFACE_FUNC
	XSINTERFACE_FUNC_RSPAMD_IA_SET
	INTERFACE:
	set_name
	set_addr

SV *
rspamd_internet_address_to_string (ia, encode = TRUE)
		Mail::Rspamd::InternetAddress	ia
		gboolean		encode
	PREINIT:
		char *		textdata;
	CODE:
		textdata = internet_address_to_string (ia, encode);
		if (textdata == NULL) {
			XSRETURN_UNDEF;
		}
		RETVAL = newSVpv (textdata, 0);
	OUTPUT:
		RETVAL

void
rspamd_internet_address_set_group (ia, ...)
		Mail::Rspamd::InternetAddress	ia
	PREINIT:
		Mail__Rspamd__InternetAddress	addr;
		InternetAddressList *		addrlist = NULL;
		int			i;
	CODE:
		if (items < 2) {
	  		XSRETURN_UNDEF;
		}
		for (i = items - 1; i > 0; --i) {
			/* retrieve each address from the perl array */
			if (sv_derived_from (ST (items - i), "Mail::Rspamd::InternetAddress")) {
				IV tmp = SvIV ((SV*)SvRV (ST (items - i)));
				addr = INT2PTR (Mail__Rspamd__InternetAddress, tmp);
			}
			if (addr) {
				internet_address_list_append (addrlist, addr);
			}
		}
		if (addrlist) {
			internet_address_set_group (ia, addrlist);
		}

void
rspamd_internet_address_add_member (ia, member)
		Mail::Rspamd::InternetAddress	ia
		Mail::Rspamd::InternetAddress	member
	CODE:
		internet_address_add_memeber (ia, member);

Mail::Rspamd::InternetAddressType
rspamd_internet_address_type (ia)
		Mail::Rspamd::InternetAddress	ia
	CODE:
		RETVAL = ia->type;
	OUTPUT:
		RETVAL