0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-16 06:51:08 +01:00

cap: allow modules to return client-specific responses for capability inquiries

This commit is contained in:
William Pitcock 2016-03-05 18:56:36 -06:00
parent 1aee992256
commit 38ffccf8c3
3 changed files with 9 additions and 9 deletions

View file

@ -56,8 +56,8 @@ extern struct CapabilityIndex *cli_capindex;
#define CLICAP_FLAGS_REQACK 0x002 #define CLICAP_FLAGS_REQACK 0x002
struct ClientCapability { struct ClientCapability {
int (*visible)(void); /* whether or not to display the capability. set to NULL or true return value = displayed */ int (*visible)(struct Client *); /* whether or not to display the capability. set to NULL or true return value = displayed */
const char *(*data)(void); /* any custom data for the capability. set to NULL or return NULL = no data */ const char *(*data)(struct Client *); /* any custom data for the capability. set to NULL or return NULL = no data */
unsigned int flags; unsigned int flags;
}; };

View file

@ -60,7 +60,7 @@ DECLARE_MODULE_AV1(cap, NULL, NULL, cap_clist, NULL, NULL, "$Revision: 676 $");
#define HasCapabilityFlag(c, f) (c->ownerdata != NULL && (((struct ClientCapability *)c->ownerdata)->flags & (f)) == f) #define HasCapabilityFlag(c, f) (c->ownerdata != NULL && (((struct ClientCapability *)c->ownerdata)->flags & (f)) == f)
static inline int static inline int
clicap_visible(const struct CapabilityEntry *cap) clicap_visible(struct Client *client_p, const struct CapabilityEntry *cap)
{ {
struct ClientCapability *clicap; struct ClientCapability *clicap;
@ -75,7 +75,7 @@ clicap_visible(const struct CapabilityEntry *cap)
if (clicap->visible == NULL) if (clicap->visible == NULL)
return 1; return 1;
return clicap->visible(); return clicap->visible(client_p);
} }
/* clicap_find() /* clicap_find()
@ -188,12 +188,12 @@ clicap_generate(struct Client *source_p, const char *subcmd, int flags, int clea
continue; continue;
} }
if (!clicap_visible(entry)) if (!clicap_visible(source_p, entry))
continue; continue;
caplen = strlen(entry->cap); caplen = strlen(entry->cap);
if (!flags && (source_p->flags & FLAGS_CLICAP_DATA) && clicap != NULL && clicap->data != NULL) if (!flags && (source_p->flags & FLAGS_CLICAP_DATA) && clicap != NULL && clicap->data != NULL)
data = clicap->data(); data = clicap->data(source_p);
if (data != NULL) if (data != NULL)
caplen += strlen(data) + 1; caplen += strlen(data) + 1;
@ -374,7 +374,7 @@ cap_req(struct Client *source_p, const char *arg)
} }
else else
{ {
if (!clicap_visible(cap)) if (!clicap_visible(source_p, cap))
{ {
finished = 0; finished = 0;
break; break;

View file

@ -81,7 +81,7 @@ mapi_hfn_list_av1 sasl_hfnlist[] = {
}; };
static int static int
sasl_visible(void) sasl_visible(struct Client *client_p)
{ {
struct Client *agent_p = NULL; struct Client *agent_p = NULL;
@ -92,7 +92,7 @@ sasl_visible(void)
} }
static const char * static const char *
sasl_data(void) sasl_data(struct Client *client_p)
{ {
return *mechlist_buf != 0 ? mechlist_buf : NULL; return *mechlist_buf != 0 ? mechlist_buf : NULL;
} }