]> jfr.im git - solanum.git/blobdiff - tests/client_util.c
modules/m_challenge.c: log correct mechanism
[solanum.git] / tests / client_util.c
index e9e8a093525a71f86357177096bb35944d1ec6f8..322f3c56725b626734ee6eecfb982cae8639b1fe 100644 (file)
 
 #include "hash.h"
 #include "s_newconf.h"
+#include "parse.h"
+#include "listener.h"
 
 #define MSG "%s:%d (%s)", __FILE__, __LINE__, __FUNCTION__
 
+static struct Listener fake_listener = {
+       .name = "fake",
+       .F = NULL,
+       .ref_count = 0,
+       .active = 1,
+       .ssl = 1,
+       .defer_accept = 0,
+       .sctp = false,
+       .wsock = 0,
+       .addr = {
+               { .ss_family = AF_INET6 },
+               { .ss_family = AF_INET6 },
+       },
+       .vhost = { "fake" },
+};
+
+struct Client *make_local_unknown(void)
+{
+       struct Client *client;
+
+       client = make_client(NULL);
+       rb_dlinkMoveNode(&client->localClient->tnode, &unknown_list, &lclient_list);
+       client->servptr = &me;
+       rb_dlinkAdd(client, &client->lnode, &client->servptr->serv->users);
+       client->localClient->listener = &fake_listener;
+       client->preClient->auth.accepted = true;
+       client->localClient->localflags |= LFLAGS_FAKE;
+
+       return client;
+}
+
 struct Client *make_local_person(void)
 {
        return make_local_person_nick(TEST_NICK);
@@ -44,14 +77,11 @@ struct Client *make_local_person_full(const char *nick, const char *username, co
 {
        struct Client *client;
 
-       client = make_client(NULL);
-       rb_dlinkMoveNode(&client->localClient->tnode, &unknown_list, &lclient_list);
-       client->servptr = &me;
-       rb_dlinkAdd(client, &client->lnode, &client->servptr->serv->users);
+       client = make_local_unknown();
        make_user(client);
        SetClient(client);
 
-       rb_inet_pton_sock(ip, (struct sockaddr *)&client->localClient->ip);
+       rb_inet_pton_sock(ip, &client->localClient->ip);
        rb_strlcpy(client->name, nick, sizeof(client->name));
        rb_strlcpy(client->username, username, sizeof(client->username));
        rb_strlcpy(client->host, hostname, sizeof(client->host));
@@ -68,6 +98,8 @@ void make_local_person_oper(struct Client *client)
        rb_dlinkAddAlloc(client, &local_oper_list);
        rb_dlinkAddAlloc(client, &oper_list);
        SetOper(client);
+       struct PrivilegeSet *p = privilegeset_set_new("test", "test:test", 0);
+       client->user->privset = privilegeset_ref(p);
 }
 
 void remove_local_person(struct Client *client)
@@ -91,6 +123,7 @@ struct Client *make_remote_server_full(struct Client *uplink, const char *name,
 
        client = make_client(NULL);
        client->servptr = uplink;
+       client->localClient->localflags |= LFLAGS_FAKE;
 
        attach_server_conf(client, find_server_conf(name));
 
@@ -105,6 +138,8 @@ struct Client *make_remote_server_full(struct Client *uplink, const char *name,
        SetServer(client);
 
        add_to_client_hash(client->name, client);
+       if (strlen(id))
+               add_to_id_hash(client->id, client);
 
        return client;
 }
@@ -122,7 +157,7 @@ struct Client *make_remote_person_nick(struct Client *server, const char *nick)
 struct Client *make_remote_person_full(struct Client *server, const char *nick, const char *username, const char *hostname, const char *ip, const char *realname)
 {
        struct Client *client;
-       struct sockaddr addr;
+       struct sockaddr_storage addr;
 
        client = make_client(server);
        make_user(client);
@@ -135,7 +170,7 @@ struct Client *make_remote_person_full(struct Client *server, const char *nick,
        rb_strlcpy(client->name, nick, sizeof(client->name));
        rb_strlcpy(client->username, username, sizeof(client->username));
        rb_strlcpy(client->host, hostname, sizeof(client->host));
-       rb_inet_ntop_sock(&addr, client->sockhost, sizeof(client->sockhost));
+       rb_inet_ntop_sock((struct sockaddr *)&addr, client->sockhost, sizeof(client->sockhost));
        rb_strlcpy(client->info, realname, sizeof(client->info));
 
        add_to_client_hash(nick, client);
@@ -160,6 +195,10 @@ void remove_remote_server(struct Client *server)
        exit_client(server, server, server->servptr, "Test server removed");
 }
 
+struct Channel *make_channel(void)
+{
+       return allocate_channel(TEST_CHANNEL);
+}
 
 char *get_client_sendq(const struct Client *client)
 {
@@ -171,7 +210,7 @@ char *get_client_sendq(const struct Client *client)
                memset(buf, 0, sizeof(buf));
                ret = rb_linebuf_get(&client->localClient->buf_sendq, buf, sizeof(buf), 0, 1);
 
-               if (is_bool(ret > 0, true, MSG)) {
+               if (ok(ret > 0, MSG)) {
                        return buf;
                } else {
                        return "<get_client_sendq error>";
@@ -181,6 +220,15 @@ char *get_client_sendq(const struct Client *client)
        return "";
 }
 
+void client_util_parse(struct Client *client, const char *message)
+{
+       char *copy = rb_strdup(message);
+
+       parse(client, copy, copy+strlen(copy));
+
+       rb_free(copy);
+}
+
 void client_util_init(void)
 {
 }