Module: kamailio
Branch: master
Commit: 04bb88f988d4e99625efef3f3b575b5a2dc652c1
URL:
https://github.com/kamailio/kamailio/commit/04bb88f988d4e99625efef3f3b575b5…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2023-07-13T17:41:16+02:00
imc: added function to check if a user is member of a chat room
---
Modified: src/modules/imc/imc.c
---
Diff:
https://github.com/kamailio/kamailio/commit/04bb88f988d4e99625efef3f3b575b5…
Patch:
https://github.com/kamailio/kamailio/commit/04bb88f988d4e99625efef3f3b575b5…
---
diff --git a/src/modules/imc/imc.c b/src/modules/imc/imc.c
index c5b65cb95d7..14b36c62300 100644
--- a/src/modules/imc/imc.c
+++ b/src/modules/imc/imc.c
@@ -91,6 +91,7 @@ static int child_init(int);
static int w_imc_manager(struct sip_msg *, char *, char *);
static int w_imc_room_active(sip_msg_t *, char *, char *);
+static int w_imc_room_member(sip_msg_t *, char *, char *);
static int imc_rpc_init(void);
@@ -107,6 +108,8 @@ static cmd_export_t cmds[] = {
{"imc_manager", (cmd_function)w_imc_manager, 0, 0, 0, REQUEST_ROUTE},
{"imc_room_active", (cmd_function)w_imc_room_active, 1,
fixup_spve_null, fixup_free_spve_null, ANY_ROUTE},
+ {"imc_room_member", (cmd_function)w_imc_room_member, 2,
+ fixup_spve_spve, fixup_free_spve_spve, ANY_ROUTE},
{0, 0, 0, 0, 0, 0}
};
@@ -471,7 +474,7 @@ static int w_imc_room_active(sip_msg_t *msg, char *proom, char *str2)
{
str room = STR_NULL;
- if(fixup_get_svalue(msg, (gparam_t*)proom, &room) != 0) {
+ if(fixup_get_svalue(msg, (gparam_t *)proom, &room) != 0) {
LM_ERR("invalid room parameter");
return -1;
}
@@ -479,6 +482,57 @@ static int w_imc_room_active(sip_msg_t *msg, char *proom, char
*str2)
return ki_imc_room_active(msg, &room);
}
+/**
+ *
+ */
+static int ki_imc_room_member(sip_msg_t *msg, str *room, str *member)
+{
+ sip_uri_t puri;
+ imc_room_t *rm;
+ imc_member_t *mb;
+
+ if(parse_uri(room->s, room->len, &puri) != 0) {
+ LM_ERR("failed to parse room uri [%.*s]\n", room->len, room->s);
+ return -1;
+ }
+
+ rm = imc_get_room(&puri.user, &puri.host);
+
+ if(rm == NULL) {
+ return -1;
+ }
+
+ if(parse_uri(member->s, member->len, &puri) != 0) {
+ imc_release_room(rm);
+ LM_ERR("failed to parse member uri [%.*s]\n", member->len, member->s);
+ return -1;
+ }
+ mb = imc_get_member(rm, &puri.user, &puri.host);
+ imc_release_room(rm);
+
+ return (mb != NULL) ? 1 : -1;
+}
+
+/**
+ *
+ */
+static int w_imc_room_member(sip_msg_t *msg, char *proom, char *pmember)
+{
+ str room = STR_NULL;
+ str member = STR_NULL;
+
+ if(fixup_get_svalue(msg, (gparam_t *)proom, &room) != 0) {
+ LM_ERR("invalid room parameter");
+ return -1;
+ }
+ if(fixup_get_svalue(msg, (gparam_t *)pmember, &member) != 0) {
+ LM_ERR("invalid member parameter");
+ return -1;
+ }
+
+ return ki_imc_room_member(msg, &room, &member);
+}
+
/**
* destroy module
*/