1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-09 06:03:13 +02:00
Files
unrealircd/src/modules/rpc/user.c
T
Bram Matthys 5a32333360 JSON-RPC: show +vhoaq in "channels" in user.* and in "members" in channel.*
as requested in https://bugs.unrealircd.org/view.php?id=6206
And also for channel.get, in "members", include the UID in "id".

This breaks the current format but we don't have many users yet anyway.
Something tells me that will happen more ;)

This also bumps the user and channel RPC modules from 1.0.0 to 1.0.1

In user.get (and currently user.list too) this shows as:

"channels": [
  {
    "name": "#test",
    "level": "o"
  }
]

And in channel.get (not .list) this shows as:
"members": [
  {
    "name": "abc",
    "id": "00129BP02",
    "level": "o"
  },
  {
    "name": "def",
    "id": "001LFMB05"
  }
]
2023-01-05 17:48:08 +01:00

111 lines
2.1 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.1",
"user.* RPC calls",
"UnrealIRCd Team",
"unrealircd-6",
};
/* Forward declarations */
RPC_CALL_FUNC(rpc_user_list);
RPC_CALL_FUNC(rpc_user_get);
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;
}
memset(&r, 0, sizeof(r));
r.method = "user.get";
r.call = rpc_user_get;
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
// TODO: right now returns everything for everyone,
// give the option to return a list of names only or
// certain options (hence the placeholder #define's above)
RPC_CALL_FUNC(rpc_user_list)
{
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);
}
RPC_CALL_FUNC(rpc_user_get)
{
json_t *result, *list, *item;
const char *nick;
Client *acptr;
nick = json_object_get_string(params, "nick");
if (!nick)
{
rpc_error(client, request, JSON_RPC_ERROR_INVALID_PARAMS, "Missing parameter: 'nick'");
return;
}
if (!(acptr = find_user(nick, NULL)))
{
rpc_error(client, request, JSON_RPC_ERROR_NOT_FOUND, "Nickname not found");
return;
}
result = json_object();
json_expand_client(result, "client", acptr, 1);
rpc_response(client, request, result);
json_decref(result);
}