summaryrefslogtreecommitdiff
path: root/src/perl/irc/Server.xs
blob: 33417bf5487377f6d95dc1dfc3c804c29297402a (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#define PERL_NO_GET_CONTEXT
#include "module.h"

static GSList *register_hash2list(HV *hv)
{
	HE *he;
	GSList *list;

	if (hv == NULL)
		return NULL;

	list = NULL;
	hv_iterinit(hv);
	while ((he = hv_iternext(hv)) != NULL) {
		I32 len;
		char *key = hv_iterkey(he, &len);
		int value = (int)SvIV(HeVAL(he));

		list = g_slist_append(list, g_strdup(key));
		list = g_slist_append(list, GINT_TO_POINTER(value));
	}
	return list;
}

static GSList *event_hash2list(HV *hv)
{
	HE *he;
	GSList *list;

	if (hv == NULL)
		return NULL;

	list = NULL;
	hv_iterinit(hv);
	while ((he = hv_iternext(hv)) != NULL) {
		I32 len;
		char *key = hv_iterkey(he, &len);
		char *value = SvPV_nolen(HeVAL(he));

		list = g_slist_append(list, g_strdup(key));
		list = g_slist_append(list, g_strdup(value));
	}
	return list;
}

MODULE = Irssi::Irc::Server	PACKAGE = Irssi::Irc::Server  PREFIX = irc_server_
PROTOTYPES: ENABLE

void
irc_server_get_channels(server)
	Irssi::Irc::Server server
PREINIT:
	char *ret;
PPCODE:
	ret = irc_server_get_channels(server);
	XPUSHs(sv_2mortal(new_pv(ret)));
	g_free(ret);

void
send_raw(server, cmd)
	Irssi::Irc::Server server
	char *cmd
CODE:
	irc_send_cmd(server, cmd);

void
send_raw_now(server, cmd)
	Irssi::Irc::Server server
	char *cmd
CODE:
	irc_send_cmd_now(server, cmd);

void
send_raw_first(server, cmd)
	Irssi::Irc::Server server
	char *cmd
CODE:
	irc_send_cmd_first(server, cmd);

void
send_raw_split(server, cmd, nickarg, max_nicks)
	Irssi::Irc::Server server
	char *cmd
	int nickarg
	int max_nicks
CODE:
	irc_send_cmd_split(server, cmd, nickarg, max_nicks);

MODULE = Irssi::Irc::Server	PACKAGE = Irssi::Irc::Server  PREFIX = server_

void
server_redirect_register(command, remote, timeout, start, stop, opt)
	char *command
	int remote
	int timeout
	SV *start
	SV *stop
	SV *opt
CODE:
	server_redirect_register_list(command, remote, timeout, 
				      register_hash2list(hvref(start)),
				      register_hash2list(hvref(stop)),
				      register_hash2list(hvref(opt)));

void
server_redirect_event(server, command, count, arg, remote, failure_signal, signals)
	Irssi::Irc::Server server
	char *command
	int count
	char *arg
	int remote
	char *failure_signal
	SV *signals
CODE:
	server_redirect_event_list(server, command, count, *arg == '\0' ? NULL : arg, remote,
				   *failure_signal == '\0' ? NULL : failure_signal,
				   event_hash2list(hvref(signals)));

char *
server_redirect_get_signal(server, prefix, event, args)
	Irssi::Irc::Server server
	char *prefix
	char *event
	char *args
CODE:
	RETVAL = (char *) server_redirect_get_signal(server, prefix, event, args);
OUTPUT:
	RETVAL

char *
server_redirect_peek_signal(server, prefix, event, args)
	Irssi::Irc::Server server
	char *prefix
	char *event
	char *args
PREINIT:
	int redirection;
CODE:
	RETVAL = (char *) server_redirect_peek_signal(server, prefix, event, args, &redirection);
OUTPUT:
	RETVAL

char *
server_isupport(server, name)
	Irssi::Irc::Server server
	char *name
CODE:
	RETVAL = (char *) g_hash_table_lookup(server->isupport, name);
OUTPUT:
	RETVAL

int
irc_server_cap_toggle(server, cap, enable)
	Irssi::Irc::Server server
	char *cap
	int enable
CODE:
	RETVAL = cap_toggle(server, cap, enable);
OUTPUT:
	RETVAL