mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-05 16:33:12 +02:00
4cd520d327
This is the 1st RPC API call that actually works :D
74 lines
1.3 KiB
C
74 lines
1.3 KiB
C
/* user.* RPC calls
|
|
* (C) Copyright 2022-.. Bram Matthys (Syzop) and the UnrealIRCd team
|
|
* License: GPLv2 or later
|
|
*/
|
|
|
|
#include "unrealircd.h"
|
|
|
|
ModuleHeader MOD_HEADER
|
|
= {
|
|
"rpc/user",
|
|
"1.0.0",
|
|
"user.* RPC calls",
|
|
"UnrealIRCd Team",
|
|
"unrealircd-6",
|
|
};
|
|
|
|
/* Forward declarations */
|
|
void rpc_user_list(Client *client, json_t *request, json_t *params);
|
|
|
|
MOD_INIT()
|
|
{
|
|
RPCHandlerInfo r;
|
|
|
|
MARK_AS_OFFICIAL_MODULE(modinfo);
|
|
|
|
memset(&r, 0, sizeof(r));
|
|
r.method = "user.list";
|
|
r.call = rpc_user_list;
|
|
if (!RPCHandlerAdd(modinfo->handle, &r))
|
|
{
|
|
config_error("[rpc/user] Could not register RPC handler");
|
|
return MOD_FAILED;
|
|
}
|
|
|
|
return MOD_SUCCESS;
|
|
}
|
|
|
|
MOD_LOAD()
|
|
{
|
|
return MOD_SUCCESS;
|
|
}
|
|
|
|
MOD_UNLOAD()
|
|
{
|
|
return MOD_SUCCESS;
|
|
}
|
|
|
|
#define RPC_USER_LIST_EXPAND_NONE 0
|
|
#define RPC_USER_LIST_EXPAND_SELECT 1
|
|
#define RPC_USER_LIST_EXPAND_ALL 2
|
|
|
|
void rpc_user_list(Client *client, json_t *request, json_t *params)
|
|
{
|
|
json_t *result, *list, *item;
|
|
Client *acptr;
|
|
|
|
result = json_object();
|
|
list = json_array();
|
|
json_object_set_new(result, "list", list);
|
|
|
|
list_for_each_entry(acptr, &client_list, client_node)
|
|
{
|
|
if (!IsUser(acptr))
|
|
continue;
|
|
|
|
item = json_object();
|
|
json_expand_client(item, NULL, acptr, 1);
|
|
json_array_append_new(list, item);
|
|
}
|
|
|
|
rpc_response(client, request, result);
|
|
json_decref(result);
|
|
}
|