| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| •18 |
#include "module.h" |
| •19 |
#include "channels.h" |
| 20 |
#include "signals.h" |
| 21 |
#include "settings.h" |
| 22 |
|
| 23 |
#include "xmpp-servers.h" |
| 24 |
#include "rosters-tools.h" |
| 25 |
#include "tools.h" |
| •26 |
#include "xep/disco.h" |
| 27 |
|
| •28 |
char *pgp_passwd = NULL; |
| 29 |
|
| 30 |
static void |
| 31 |
sig_set_presence(XMPP_SERVER_REC *server, const int show, const char *status, |
| 32 |
const int priority) |
| 33 |
{ |
| 34 |
LmMessage *lmsg; |
| 35 |
char *str; |
| 36 |
const char *pgp_keyid; |
| 37 |
|
| 38 |
g_return_if_fail(IS_XMPP_SERVER(server)); |
| 39 |
if (!xmpp_presence_changed(show, server->show, status, |
| •40 |
server->away_reason, priority, server->priority)) { |
| 41 |
signal_stop(); |
| 42 |
return; |
| 43 |
} |
| 44 |
|
| 45 |
lmsg = lm_message_new(NULL, LM_MESSAGE_TYPE_PRESENCE); |
| 46 |
server->show = show; |
| 47 |
|
| 48 |
if (!xmpp_priority_out_of_bound(priority)) |
| 49 |
server->priority = priority; |
| 50 |
|
| 51 |
if (show != XMPP_PRESENCE_AVAILABLE) |
| 52 |
lm_message_node_add_child(lmsg->node, "show", |
| 53 |
xmpp_presence_show[server->show]); |
| 54 |
|
| 55 |
if(server->away_reason) g_free(server->away_reason); |
| 56 |
server->away_reason = NULL; |
| 57 |
|
| 58 |
if(!status) status = ""; |
| 59 |
server->away_reason = g_strdup(status); |
| 60 |
str = xmpp_recode_out(server->away_reason); |
| •61 |
lm_message_node_add_child(lmsg->node, "status", str); |
| 62 |
if(!str) str = g_strdup(""); |
| 63 |
|
| •64 |
if((pgp_keyid = settings_get_str("xmpp_pgp"))) { |
| 65 |
LmMessageNode *x; |
| •66 |
char *signature = call_gpg("-ab", str, NULL, 0, 1); |
| •67 |
disco_add_feature("jabber:x:signed"); |
| •68 |
disco_add_feature("jabber:x:encrypted"); |
| 69 |
|
| 70 |
if(signature) { |
| •71 |
x = lm_message_node_add_child(lmsg->node, "x", signature); |
| 72 |
lm_message_node_set_attribute(x, "xmlns", "jabber:x:signed"); |
| 73 |
|
| •74 |
free(signature); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
g_free(str); |
| 79 |
|
| 80 |
str = g_strdup_printf("%d", server->priority); |
| 81 |
lm_message_node_add_child(lmsg->node, "priority", str); |
| 82 |
g_free(str); |
| 83 |
|
| 84 |
signal_emit("xmpp send presence", 2, server, lmsg); |
| 85 |
lm_message_unref(lmsg); |
| 86 |
if (show != XMPP_PRESENCE_AVAILABLE) |
| 87 |
signal_emit("event 306", 2, server, server->jid); |
| 88 |
else if (server->usermode_away) |
| 89 |
signal_emit("event 305", 2, server, server->jid); |
| 90 |
} |
| 91 |
|
| 92 |
static void |
| 93 |
sig_recv_message(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type, |
| 94 |
const char *id, const char *from, const char *to) |
| 95 |
{ |
| •96 |
LmMessageNode *node, *encrypted; |
| 97 |
char *str, *subject; |
| •98 |
const char *from_stripped; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
str = xmpp_strip_resource(from); |
| 106 |
from_stripped = |
| 107 |
((settings_get_bool("xmpp_strip_resource")) && |
| 108 |
(channel_find(SERVER(server), str)) == NULL) ? |
| 109 |
g_strdup(str) : g_strdup(from); |
| 110 |
g_free(str); |
| 111 |
|
| 112 |
if ((type != LM_MESSAGE_SUB_TYPE_NOT_SET |
| 113 |
&& type != LM_MESSAGE_SUB_TYPE_HEADLINE |
| 114 |
&& type != LM_MESSAGE_SUB_TYPE_NORMAL |
| 115 |
&& type != LM_MESSAGE_SUB_TYPE_CHAT) |
| 116 |
|| server->ischannel(SERVER(server), from)) |
| 117 |
return; |
| 118 |
node = lm_message_node_get_child(lmsg->node, "subject"); |
| •119 |
if (node != NULL && node->value != NULL && *node->value != '\0') { |
| 120 |
str = xmpp_recode_in(node->value); |
| 121 |
subject = g_strconcat("Subject: ", str, (void *)NULL); |
| 122 |
g_free(str); |
| •123 |
signal_emit("message private", 4, server, subject, from_stripped, from); |
| 124 |
g_free(subject); |
| •125 |
} |
| •126 |
|
| 127 |
str = NULL; |
| 128 |
encrypted = lm_find_node(lmsg->node, "x", "xmlns", "jabber:x:encrypted"); |
| 129 |
if(encrypted && encrypted->value) { |
| 130 |
|
| 131 |
|
| 132 |
char *send_to_gpg = malloc(sizeof( \ |
| 133 |
"-----BEGIN PGP MESSAGE-----\n\n" \ |
| 134 |
"-----END PGP MESSAGE-----\n")+ \ |
| 135 |
strlen(encrypted->value)+1 \ |
| 136 |
); |
| 137 |
char *from_gpg; |
| 138 |
|
| 139 |
send_to_gpg[0] = '\0'; |
| 140 |
strcat(send_to_gpg, "-----BEGIN PGP MESSAGE-----\n\n"); |
| 141 |
strcat(send_to_gpg, encrypted->value); |
| 142 |
strcat(send_to_gpg, "-----END PGP MESSAGE-----\n"); |
| 143 |
|
| 144 |
from_gpg = call_gpg("-d", send_to_gpg, NULL, 0, 0); |
| 145 |
if(from_gpg) { |
| 146 |
str = xmpp_recode_in(from_gpg); |
| 147 |
free(from_gpg); |
| 148 |
} |
| 149 |
|
| 150 |
free(send_to_gpg); |
| 151 |
} else { |
| 152 |
node = lm_message_node_get_child(lmsg->node, "body"); |
| 153 |
if (node != NULL && node->value != NULL && *node->value != '\0') { |
| 154 |
str = xmpp_recode_in(node->value); |
| 155 |
} |
| 156 |
} |
| 157 |
if(str) { |
| 158 |
if (g_ascii_strncasecmp(str, "/me ", 4) == 0) |
| 159 |
signal_emit("message xmpp action", 5, |
| •160 |
server, str+4, from_stripped, from, |
| 161 |
GINT_TO_POINTER(SEND_TARGET_NICK)); |
| 162 |
else |
| 163 |
signal_emit("message private", 4, server, |
| •164 |
str, from_stripped, from); |
| 165 |
g_free(str); |
| 166 |
} |
| 167 |
} |
| 168 |
|
| 169 |
void |
| 170 |
protocol_init(void) |
| 171 |
{ |
| 172 |
signal_add_first("xmpp set presence", sig_set_presence); |
| 173 |
signal_add("xmpp recv message", sig_recv_message); |
| 174 |
} |
| 175 |
|
| 176 |
void |
| 177 |
protocol_deinit(void) |
| 178 |
{ |
| 179 |
signal_remove("xmpp set presence", sig_set_presence); |
| 180 |
signal_remove("xmpp recv message", sig_recv_message); |
| 181 |
} |