mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-30 23:26:21 +00:00
Add XEP-0377: Spam Reporting
Report and block: `/blocked add someone@domain.org report-abuse This is not nice` `/blocked add someone@domain.org report-spam This is not nice` Regular block: `/blocked add someone@domain.org` Implement https://github.com/profanity-im/profanity/issues/1434
This commit is contained in:
@@ -420,7 +420,7 @@ static struct cmd_t command_defs[] = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
{ "/blocked",
|
{ "/blocked",
|
||||||
parse_args, 0, 2, NULL,
|
parse_args_with_freetext, 0, 4, NULL,
|
||||||
CMD_NOSUBFUNCS
|
CMD_NOSUBFUNCS
|
||||||
CMD_MAINFUNC(cmd_blocked)
|
CMD_MAINFUNC(cmd_blocked)
|
||||||
CMD_TAGS(
|
CMD_TAGS(
|
||||||
@@ -428,7 +428,7 @@ static struct cmd_t command_defs[] = {
|
|||||||
CMD_TAG_CHAT)
|
CMD_TAG_CHAT)
|
||||||
CMD_SYN(
|
CMD_SYN(
|
||||||
"/blocked",
|
"/blocked",
|
||||||
"/blocked add [<jid>]",
|
"/blocked add [<jid>] [report-abuse|report-spam [<message>]",
|
||||||
"/blocked remove <jid>")
|
"/blocked remove <jid>")
|
||||||
CMD_DESC(
|
CMD_DESC(
|
||||||
"Manage blocked users (XEP-0191), calling with no arguments shows the current list of blocked users. "
|
"Manage blocked users (XEP-0191), calling with no arguments shows the current list of blocked users. "
|
||||||
@@ -438,6 +438,7 @@ static struct cmd_t command_defs[] = {
|
|||||||
{ "remove <jid>", "Remove the specified Jabber ID from the blocked list." })
|
{ "remove <jid>", "Remove the specified Jabber ID from the blocked list." })
|
||||||
CMD_EXAMPLES(
|
CMD_EXAMPLES(
|
||||||
"/blocked add hel@helheim.edda",
|
"/blocked add hel@helheim.edda",
|
||||||
|
"/blocked add hel@helheim.edda report-spam",
|
||||||
"/blocked add profanity@rooms.dismail.de/spammy-user")
|
"/blocked add profanity@rooms.dismail.de/spammy-user")
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -3014,17 +3014,41 @@ cmd_blocked(ProfWin* window, const char* const command, gchar** args)
|
|||||||
|
|
||||||
if (g_strcmp0(args[0], "add") == 0) {
|
if (g_strcmp0(args[0], "add") == 0) {
|
||||||
char* jid = args[1];
|
char* jid = args[1];
|
||||||
if (jid == NULL && (window->type == WIN_CHAT)) {
|
char* msg = NULL;
|
||||||
ProfChatWin* chatwin = (ProfChatWin*)window;
|
blocked_report br = BLOCKED_NO_REPORT;
|
||||||
jid = chatwin->barejid;
|
|
||||||
|
// /blocked add jid or /blocked add (in window)
|
||||||
|
if (g_strv_length(args) < 3) {
|
||||||
|
if (jid == NULL && (window->type == WIN_CHAT)) {
|
||||||
|
ProfChatWin* chatwin = (ProfChatWin*)window;
|
||||||
|
jid = chatwin->barejid;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jid == NULL) {
|
||||||
|
cons_bad_cmd_usage(command);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (args[2] && g_strcmp0(args[2], "report-abuse") == 0) {
|
||||||
|
br = BLOCKED_REPORT_ABUSE;
|
||||||
|
} else if (args[2] && g_strcmp0(args[2], "report-abuse") == 0) {
|
||||||
|
br = BLOCKED_REPORT_SPAM;
|
||||||
|
} else {
|
||||||
|
cons_bad_cmd_usage(command);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!connection_supports(XMPP_FEATURE_SPAM_REPORTING)) {
|
||||||
|
cons_show("Spam reporting not supported by server.");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = args[3];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jid == NULL) {
|
// args[3] is optional message
|
||||||
cons_bad_cmd_usage(command);
|
gboolean res = blocked_add(jid, br, msg);
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean res = blocked_add(jid);
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
cons_show("User %s already blocked.", jid);
|
cons_show("User %s already blocked.", jid);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ blocked_ac_reset(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
blocked_add(char* jid)
|
blocked_add(char* jid, blocked_report reportkind, const char* const message)
|
||||||
{
|
{
|
||||||
GList* found = g_list_find_custom(blocked, jid, (GCompareFunc)g_strcmp0);
|
GList* found = g_list_find_custom(blocked, jid, (GCompareFunc)g_strcmp0);
|
||||||
if (found) {
|
if (found) {
|
||||||
@@ -129,6 +129,31 @@ blocked_add(char* jid)
|
|||||||
xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
|
xmpp_stanza_set_name(item, STANZA_NAME_ITEM);
|
||||||
xmpp_stanza_set_attribute(item, STANZA_ATTR_JID, jid);
|
xmpp_stanza_set_attribute(item, STANZA_ATTR_JID, jid);
|
||||||
|
|
||||||
|
if (reportkind != BLOCKED_NO_REPORT) {
|
||||||
|
xmpp_stanza_t* report = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(report, STANZA_NAME_REPORT);
|
||||||
|
if (reportkind == BLOCKED_REPORT_ABUSE) {
|
||||||
|
xmpp_stanza_set_attribute(report, STANZA_ATTR_REASON, STANZA_REPORTING_ABUSE);
|
||||||
|
} else {
|
||||||
|
xmpp_stanza_set_attribute(report, STANZA_ATTR_REASON, STANZA_REPORTING_SPAM);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message) {
|
||||||
|
xmpp_stanza_t* text = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_name(text, STANZA_NAME_TEXT);
|
||||||
|
|
||||||
|
xmpp_stanza_t* txt = xmpp_stanza_new(ctx);
|
||||||
|
xmpp_stanza_set_text(txt, message);
|
||||||
|
|
||||||
|
xmpp_stanza_add_child(text, txt);
|
||||||
|
xmpp_stanza_add_child(report, text);
|
||||||
|
xmpp_stanza_release(txt);
|
||||||
|
}
|
||||||
|
|
||||||
|
xmpp_stanza_add_child(item, report);
|
||||||
|
xmpp_stanza_release(report);
|
||||||
|
}
|
||||||
|
|
||||||
xmpp_stanza_add_child(block, item);
|
xmpp_stanza_add_child(block, item);
|
||||||
xmpp_stanza_release(item);
|
xmpp_stanza_release(item);
|
||||||
|
|
||||||
|
|||||||
@@ -122,6 +122,7 @@
|
|||||||
#define STANZA_NAME_AFTER "after"
|
#define STANZA_NAME_AFTER "after"
|
||||||
#define STANZA_NAME_USERNAME "username"
|
#define STANZA_NAME_USERNAME "username"
|
||||||
#define STANZA_NAME_PROPOSE "propose"
|
#define STANZA_NAME_PROPOSE "propose"
|
||||||
|
#define STANZA_NAME_REPORT "report"
|
||||||
|
|
||||||
// error conditions
|
// error conditions
|
||||||
#define STANZA_NAME_BAD_REQUEST "bad-request"
|
#define STANZA_NAME_BAD_REQUEST "bad-request"
|
||||||
@@ -245,6 +246,9 @@
|
|||||||
|
|
||||||
#define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
|
#define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
|
||||||
|
|
||||||
|
#define STANZA_REPORTING_ABUSE "urn:xmpp:reporting:abuse"
|
||||||
|
#define STANZA_REPORTING_SPAM "urn:xmpp:reporting:spam"
|
||||||
|
|
||||||
typedef struct caps_stanza_t
|
typedef struct caps_stanza_t
|
||||||
{
|
{
|
||||||
char* hash;
|
char* hash;
|
||||||
|
|||||||
@@ -70,6 +70,7 @@
|
|||||||
#define XMPP_FEATURE_USER_AVATAR_METADATA_NOTIFY "urn:xmpp:avatar:metadata+notify"
|
#define XMPP_FEATURE_USER_AVATAR_METADATA_NOTIFY "urn:xmpp:avatar:metadata+notify"
|
||||||
#define XMPP_FEATURE_LAST_MESSAGE_CORRECTION "urn:xmpp:message-correct:0"
|
#define XMPP_FEATURE_LAST_MESSAGE_CORRECTION "urn:xmpp:message-correct:0"
|
||||||
#define XMPP_FEATURE_MAM2 "urn:xmpp:mam:2"
|
#define XMPP_FEATURE_MAM2 "urn:xmpp:mam:2"
|
||||||
|
#define XMPP_FEATURE_SPAM_REPORTING "urn:xmpp:reporting:1"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
JABBER_CONNECTING,
|
JABBER_CONNECTING,
|
||||||
@@ -89,6 +90,12 @@ typedef enum {
|
|||||||
INVITE_MEDIATED
|
INVITE_MEDIATED
|
||||||
} jabber_invite_t;
|
} jabber_invite_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BLOCKED_NO_REPORT,
|
||||||
|
BLOCKED_REPORT_ABUSE,
|
||||||
|
BLOCKED_REPORT_SPAM
|
||||||
|
} blocked_report;
|
||||||
|
|
||||||
typedef struct bookmark_t
|
typedef struct bookmark_t
|
||||||
{
|
{
|
||||||
char* barejid;
|
char* barejid;
|
||||||
@@ -286,7 +293,7 @@ void roster_send_add_new(const char* const barejid, const char* const name);
|
|||||||
void roster_send_remove(const char* const barejid);
|
void roster_send_remove(const char* const barejid);
|
||||||
|
|
||||||
GList* blocked_list(void);
|
GList* blocked_list(void);
|
||||||
gboolean blocked_add(char* jid);
|
gboolean blocked_add(char* jid, blocked_report reportkind, const char* const message);
|
||||||
gboolean blocked_remove(char* jid);
|
gboolean blocked_remove(char* jid);
|
||||||
char* blocked_ac_find(const char* const search_str, gboolean previous, void* context);
|
char* blocked_ac_find(const char* const search_str, gboolean previous, void* context);
|
||||||
void blocked_ac_reset(void);
|
void blocked_ac_reset(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user