int oscar_send_im PurpleConnection gc const char name const char messa

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
int
oscar_send_im(PurpleConnection *gc, const char *name, const char *message, PurpleMessageFlags imflags)
{
OscarData *od;
PurpleAccount *account;
PeerConnection *conn;
int ret;
char *tmp1, *tmp2;
gboolean is_sms, is_html;
od = purple_connection_get_protocol_data(gc);
account = purple_connection_get_account(gc);
ret = 0;
is_sms = oscar_util_valid_name_sms(name);
if (od->icq && is_sms) {
/*
* We're sending to a phone number and this is ICQ,
* so send the message as an SMS using aim_icq_sendsms()
*/
int ret;
purple_debug_info("oscar", "Sending SMS to %s.\n", name);
ret = aim_icq_sendsms(od, name, message, purple_account_get_username(account));
return (ret >= 0 ? 1 : ret);
}
if (imflags & PURPLE_MESSAGE_AUTO_RESP)
tmp1 = oscar_util_format_string(message, name);
else
tmp1 = g_strdup(message);
// ====== Костыль для jasmine icq ==========
unsigned int i, msg_len = strlen(tmp1);
for (i = 0; i < msg_len; ++i) {
if (strncmp(&tmp1[i], "<br>", 4) == 0) {
i += 4;
tmp1 = (char *) realloc(tmp1, msg_len + 2);
memmove(tmp1 + i + 1, tmp1 + i, msg_len - i);
tmp1[i] = '\n';
i += 1; msg_len += 1;
}
}
tmp1[msg_len] = 0;
// =========================================
conn = peer_connection_find_by_type(od, name, OSCAR_CAPABILITY_DIRECTIM);
if ((conn != NULL) && (conn->ready))
{
/* If we're directly connected, send a direct IM */
purple_debug_info("oscar", "Sending direct IM with flags %i\n", imflags);
purple_odc_send_im(conn, tmp1, imflags);
} else {
struct buddyinfo *bi;
struct aim_sendimext_args args;
PurpleConversation *conv;
PurpleStoredImage *img;
PurpleBuddy *buddy;
conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, name, account);
if (strstr(tmp1, "<IMG "))
purple_conversation_write(conv, "",
_("Your IM Image was not sent. "
"You must be Direct Connected to send IM Images."),
PURPLE_MESSAGE_ERROR, time(NULL));
buddy = purple_find_buddy(account, name);
bi = g_hash_table_lookup(od->buddyinfo, purple_normalize(account, name));
if (!bi) {
bi = g_new0(struct buddyinfo, 1);
g_hash_table_insert(od->buddyinfo, g_strdup(purple_normalize(account, name)), bi);
}
args.flags = 0;
if (!is_sms && (!buddy || !PURPLE_BUDDY_IS_ONLINE(buddy)))
args.flags |= AIM_IMFLAGS_OFFLINE;
if (od->icq) {
args.features = features_icq;
args.featureslen = sizeof(features_icq);
} else {
args.features = features_aim;
args.featureslen = sizeof(features_aim);
if (imflags & PURPLE_MESSAGE_AUTO_RESP)
args.flags |= AIM_IMFLAGS_AWAY;
}
if (bi->ico_need) {
purple_debug_info("oscar",
"Sending buddy icon request with message\n");
args.flags |= AIM_IMFLAGS_BUDDYREQ;
bi->ico_need = FALSE;
}
img = purple_buddy_icons_find_account_icon(account);
if (img) {
gconstpointer data = purple_imgstore_get_data(img);
args.iconlen = purple_imgstore_get_size(img);
args.iconsum = aimutil_iconsum(data, args.iconlen);
args.iconstamp = purple_buddy_icons_get_account_icon_timestamp(account);
if ((args.iconlen != bi->ico_me_len) || (args.iconsum != bi->ico_me_csum) || (args.iconstamp != bi->ico_me_time)) {
bi->ico_informed = FALSE;
bi->ico_sent = FALSE;
}
/*
* TODO:
* For some reason sending our icon to people only works
* when we're the ones who initiated the conversation. If
* the other person sends the first IM then they never get
* the icon. We should fix that.
*/
if (!bi->ico_informed) {
purple_debug_info("oscar",
"Claiming to have a buddy icon\n");
args.flags |= AIM_IMFLAGS_HASICON;
bi->ico_me_len = args.iconlen;
bi->ico_me_csum = args.iconsum;
bi->ico_me_time = args.iconstamp;
bi->ico_informed = TRUE;
}
purple_imgstore_unref(img);
}
args.destbn = name;
if (oscar_util_valid_name_sms(name)) {
/* Messaging an SMS (mobile) user--strip HTML */
tmp2 = purple_markup_strip_html(tmp1);
is_html = FALSE;
} else {
/* ICQ 6 wants its HTML wrapped in these tags. Oblige it. */
tmp2 = g_strdup_printf("<HTML><BODY>%s</BODY></HTML>", tmp1);
is_html = TRUE;
}
g_free(tmp1);
tmp1 = tmp2;
args.msg = oscar_encode_im(tmp1, &args.msglen, &args.charset, NULL);
if (is_html && (args.msglen > MAXMSGLEN)) {
/* If the length was too long, try stripping the HTML and then running it back through
* purple_strdup_withhtml() and the encoding process. The result may be shorter. */
g_free((char *)args.msg);
tmp2 = purple_markup_strip_html(tmp1);
g_free(tmp1);
/* re-escape the entities */
tmp1 = g_markup_escape_text(tmp2, -1);
g_free(tmp2);
tmp2 = purple_strdup_withhtml(tmp1);
g_free(tmp1);
tmp1 = tmp2;
args.msg = oscar_encode_im(tmp1, &args.msglen, &args.charset, NULL);
purple_debug_info("oscar", "Sending %s as %s because the original was too long.\n",
message, (char *)args.msg);
}
purple_debug_info("oscar", "Sending IM, charset=0x%04hx, length=%" G_GSIZE_FORMAT "\n", args.charset, args.msglen);
ret = aim_im_sendch1_ext(od, &args);
g_free((char *)args.msg);
}
g_free(tmp1);
if (ret >= 0)
return 1;
return ret;
}