]>
Commit | Line | Data |
---|---|---|
d2b5f411 SA |
1 | /* |
2 | * client_util.c: Utility functions for making test clients | |
3 | * Copyright 2017 Simon Arlott | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 | |
18 | * USA | |
19 | */ | |
20 | #include <stdio.h> | |
21 | #include <string.h> | |
22 | #include <stdlib.h> | |
23 | #include <unistd.h> | |
24 | #include "tap/basic.h" | |
25 | ||
26 | #include "stdinc.h" | |
27 | #include "ircd_defs.h" | |
28 | #include "client_util.h" | |
29 | ||
30 | #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__ | |
31 | ||
32 | struct Client *make_local_person(void) | |
33 | { | |
34 | return make_local_person_nick(TEST_NICK); | |
35 | } | |
36 | ||
37 | struct Client *make_local_person_nick(const char *nick) | |
38 | { | |
39 | return make_local_person_full(nick, TEST_USERNAME, TEST_HOSTNAME, TEST_IP, TEST_REALNAME); | |
40 | } | |
41 | ||
42 | struct Client *make_local_person_full(const char *nick, const char *username, const char *hostname, const char *ip, const char *realname) | |
43 | { | |
44 | struct Client *client; | |
45 | ||
46 | client = make_client(NULL); | |
47 | rb_dlinkMoveNode(&client->localClient->tnode, &unknown_list, &lclient_list); | |
48 | client->servptr = &me; | |
49 | rb_dlinkAdd(client, &client->lnode, &client->servptr->serv->users); | |
50 | SetClient(client); | |
51 | make_user(client); | |
52 | ||
53 | rb_inet_pton_sock(ip, (struct sockaddr *)&client->localClient->ip); | |
54 | rb_strlcpy(client->name, nick, sizeof(client->name)); | |
55 | rb_strlcpy(client->username, username, sizeof(client->username)); | |
56 | rb_strlcpy(client->host, hostname, sizeof(client->host)); | |
57 | rb_inet_ntop_sock((struct sockaddr *)&client->localClient->ip, client->sockhost, sizeof(client->sockhost)); | |
58 | rb_strlcpy(client->info, realname, sizeof(client->info)); | |
59 | ||
60 | return client; | |
61 | } | |
62 | ||
6af47466 SA |
63 | void make_local_person_oper(struct Client *client) |
64 | { | |
65 | rb_dlinkAddAlloc(client, &local_oper_list); | |
66 | rb_dlinkAddAlloc(client, &oper_list); | |
67 | SetOper(client); | |
68 | } | |
69 | ||
d2b5f411 SA |
70 | void remove_local_person(struct Client *client) |
71 | { | |
72 | exit_client(NULL, client, &me, "Test client removed"); | |
73 | } | |
74 | ||
75 | char *get_client_sendq(const struct Client *client) | |
76 | { | |
77 | static char buf[EXT_BUFSIZE + sizeof(CRLF)]; | |
78 | ||
79 | if (rb_linebuf_len(&client->localClient->buf_sendq)) { | |
80 | int ret; | |
81 | ||
82 | memset(buf, 0, sizeof(buf)); | |
83 | ret = rb_linebuf_get(&client->localClient->buf_sendq, buf, sizeof(buf), 0, 1); | |
84 | ||
85 | if (is_bool(ret > 0, true, MSG)) { | |
86 | return buf; | |
87 | } else { | |
88 | return "<get_client_sendq error>"; | |
89 | } | |
90 | } | |
91 | ||
92 | return ""; | |
93 | } | |
94 | ||
95 | void client_util_init(void) | |
96 | { | |
97 | } | |
98 | ||
99 | void client_util_free(void) | |
100 | { | |
101 | } |