mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-04-01 02:00:19 +00:00
Compare commits
4 Commits
0eb4d08daa
...
ec18c95d32
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ec18c95d32 | ||
| d9557c7da1 | |||
| fc90fd41be | |||
| ec5e38d1f9 |
@@ -1796,6 +1796,36 @@ inbound_cap_ack (server *serv, char *nick, char *extensions,
|
||||
inbound_toggle_caps (serv, extensions, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
inbound_cap_new (server *serv, char *nick, char *extensions,
|
||||
const message_tags_data *tags_data)
|
||||
{
|
||||
if (extensions)
|
||||
{
|
||||
char **tokens = g_strsplit (extensions, " ", 0);
|
||||
int i;
|
||||
|
||||
for (i = 0; tokens[i]; i++)
|
||||
{
|
||||
char **parts = g_strsplit (tokens[i], "=", 2);
|
||||
|
||||
if (!g_strcmp0 (parts[0], "sts") && parts[1] && parts[1][0])
|
||||
{
|
||||
sts_handle_capability (serv, parts[1]);
|
||||
}
|
||||
|
||||
g_strfreev (parts);
|
||||
}
|
||||
|
||||
g_strfreev (tokens);
|
||||
}
|
||||
|
||||
EMIT_SIGNAL_TIMESTAMP (XP_TE_CAPACK, serv->server_session, nick, extensions,
|
||||
NULL, NULL, 0, tags_data->timestamp);
|
||||
|
||||
inbound_toggle_caps (serv, extensions, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
inbound_cap_del (server *serv, char *nick, char *extensions,
|
||||
const message_tags_data *tags_data)
|
||||
|
||||
@@ -95,6 +95,8 @@ void inbound_cap_ls (server *serv, char *nick, char *extensions,
|
||||
void inbound_cap_nak (server *serv, char *extensions, const message_tags_data *tags_data);
|
||||
void inbound_cap_list (server *serv, char *nick, char *extensions,
|
||||
const message_tags_data *tags_data);
|
||||
void inbound_cap_new (server *serv, char *nick, char *extensions,
|
||||
const message_tags_data *tags_data);
|
||||
void inbound_cap_del (server *serv, char *nick, char *extensions,
|
||||
const message_tags_data *tags_data);
|
||||
void inbound_sasl_authenticate (server *serv, char *data);
|
||||
|
||||
@@ -1359,12 +1359,18 @@ process_named_msg (session *sess, char *type, char *word[], char *word_eol[],
|
||||
word[5][0] == ':' ? word_eol[5] + 1 : word_eol[5],
|
||||
tags_data);
|
||||
}
|
||||
else if (g_ascii_strncasecmp(word[4], "LS", 2) == 0 || g_ascii_strncasecmp(word[4], "NEW", 3) == 0)
|
||||
else if (g_ascii_strncasecmp(word[4], "LS", 2) == 0)
|
||||
{
|
||||
inbound_cap_ls (serv, word[1],
|
||||
word[5][0] == ':' ? word_eol[5] + 1 : word_eol[5],
|
||||
tags_data);
|
||||
}
|
||||
else if (g_ascii_strncasecmp(word[4], "NEW", 3) == 0)
|
||||
{
|
||||
inbound_cap_new (serv, word[1],
|
||||
word[5][0] == ':' ? word_eol[5] + 1 : word_eol[5],
|
||||
tags_data);
|
||||
}
|
||||
else if (g_ascii_strncasecmp(word[4], "NAK", 3) == 0)
|
||||
{
|
||||
inbound_cap_nak (serv, word[5][0] == ':' ? word_eol[5] + 1 : word_eol[5], tags_data);
|
||||
|
||||
@@ -305,6 +305,7 @@ sts_parse_value (const char *value, guint16 *port, guint64 *duration, gboolean *
|
||||
{
|
||||
char **tokens;
|
||||
gsize i;
|
||||
char *end;
|
||||
|
||||
if (!value || !*value)
|
||||
{
|
||||
@@ -349,8 +350,9 @@ sts_parse_value (const char *value, guint16 *port, guint64 *duration, gboolean *
|
||||
continue;
|
||||
}
|
||||
|
||||
port_value = g_ascii_strtoll (val, NULL, 10);
|
||||
if (port_value > 0 && port_value <= G_MAXUINT16)
|
||||
end = NULL;
|
||||
port_value = g_ascii_strtoll (val, &end, 10);
|
||||
if (end && *end == '\0' && port_value > 0 && port_value <= G_MAXUINT16)
|
||||
{
|
||||
*port = (guint16) port_value;
|
||||
*has_port = TRUE;
|
||||
@@ -371,7 +373,12 @@ sts_parse_value (const char *value, guint16 *port, guint64 *duration, gboolean *
|
||||
continue;
|
||||
}
|
||||
|
||||
duration_value = g_ascii_strtoull (val, NULL, 10);
|
||||
end = NULL;
|
||||
duration_value = g_ascii_strtoull (val, &end, 10);
|
||||
if (!end || *end != '\0')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
*duration = duration_value;
|
||||
*has_duration = TRUE;
|
||||
}
|
||||
@@ -612,7 +619,7 @@ sts_handle_capability (struct server *serv, const char *value)
|
||||
{
|
||||
time_t now = time (NULL);
|
||||
time_t expires_at = now + (time_t) duration;
|
||||
guint16 effective_port = 0;
|
||||
guint16 effective_port = (guint16) serv->port;
|
||||
sts_profile *existing_profile;
|
||||
sts_profile *profile;
|
||||
|
||||
|
||||
@@ -109,7 +109,6 @@ url_add (char *urltext, int len)
|
||||
{
|
||||
char *data;
|
||||
int size;
|
||||
GUri *parsed;
|
||||
|
||||
if (!prefs.hex_url_grabber && !prefs.hex_url_logging)
|
||||
{
|
||||
@@ -133,16 +132,6 @@ url_add (char *urltext, int len)
|
||||
data[len - 1] = 0;
|
||||
}
|
||||
|
||||
parsed = g_uri_parse (data, G_URI_FLAGS_NONE, NULL);
|
||||
if (parsed == NULL || g_uri_get_host (parsed) == NULL || *g_uri_get_host (parsed) == '\0')
|
||||
{
|
||||
if (parsed)
|
||||
g_uri_unref (parsed);
|
||||
g_free (data);
|
||||
return;
|
||||
}
|
||||
g_uri_unref (parsed);
|
||||
|
||||
if (prefs.hex_url_logging)
|
||||
{
|
||||
url_save_node (data);
|
||||
|
||||
@@ -1888,6 +1888,20 @@ key_action_put_history (GtkWidget * wid, GdkEventKey * ent, char *d1,
|
||||
return 2;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
replace_set_pos_idle (gpointer data)
|
||||
{
|
||||
GtkWidget *t = GTK_WIDGET (data);
|
||||
gpointer pos_data = g_object_get_data (G_OBJECT (t), "zoitechat-replace-pos");
|
||||
|
||||
if (pos_data)
|
||||
SPELL_ENTRY_SET_POS (t, GPOINTER_TO_INT (pos_data));
|
||||
|
||||
g_object_set_data (G_OBJECT (t), "zoitechat-replace-pos", NULL);
|
||||
g_object_unref (t);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
static void
|
||||
replace_handle (GtkWidget *t)
|
||||
{
|
||||
@@ -1903,11 +1917,12 @@ replace_handle (GtkWidget *t)
|
||||
size_t match_len;
|
||||
ptrdiff_t cursor_byte_offset;
|
||||
ptrdiff_t match_start_offset;
|
||||
ptrdiff_t match_end_offset;
|
||||
ptrdiff_t new_cursor_offset;
|
||||
const char *best_match;
|
||||
size_t best_len;
|
||||
struct popup *best_pop;
|
||||
int best_rank;
|
||||
ptrdiff_t best_distance;
|
||||
|
||||
text = SPELL_ENTRY_GET_TEXT (t);
|
||||
|
||||
@@ -1922,20 +1937,51 @@ replace_handle (GtkWidget *t)
|
||||
best_match = NULL;
|
||||
best_len = 0;
|
||||
best_pop = NULL;
|
||||
best_rank = 3;
|
||||
best_distance = 0;
|
||||
cursor_byte_offset = cursor_ptr - text;
|
||||
while (list)
|
||||
{
|
||||
pop = (struct popup *) list->data;
|
||||
if (pop->name[0] != '\0')
|
||||
{
|
||||
size_t pop_len = strlen (pop->name);
|
||||
const char *found = strstr (text, pop->name);
|
||||
const char *found = text;
|
||||
|
||||
if (found && (!best_match || found < best_match))
|
||||
while ((found = strstr (found, pop->name)) != NULL)
|
||||
{
|
||||
ptrdiff_t found_offset = found - text;
|
||||
ptrdiff_t found_end_offset = found_offset + (ptrdiff_t) pop_len;
|
||||
int rank;
|
||||
ptrdiff_t distance;
|
||||
|
||||
if (cursor_byte_offset >= found_offset && cursor_byte_offset <= found_end_offset)
|
||||
{
|
||||
rank = 0;
|
||||
distance = found_end_offset - cursor_byte_offset;
|
||||
}
|
||||
else if (found_end_offset <= cursor_byte_offset)
|
||||
{
|
||||
rank = 1;
|
||||
distance = cursor_byte_offset - found_end_offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
rank = 2;
|
||||
distance = found_offset - cursor_byte_offset;
|
||||
}
|
||||
|
||||
if (rank < best_rank || (rank == best_rank && distance < best_distance))
|
||||
{
|
||||
best_rank = rank;
|
||||
best_distance = distance;
|
||||
best_match = found;
|
||||
best_len = pop_len;
|
||||
best_pop = pop;
|
||||
}
|
||||
|
||||
found++;
|
||||
}
|
||||
}
|
||||
list = list->next;
|
||||
}
|
||||
@@ -1952,21 +1998,17 @@ replace_handle (GtkWidget *t)
|
||||
return;
|
||||
|
||||
replacement_len = strlen (pop->cmd);
|
||||
cursor_byte_offset = cursor_ptr - text;
|
||||
match_start_offset = match_start - text;
|
||||
match_end_offset = match_start_offset + (ptrdiff_t) match_len;
|
||||
if (cursor_byte_offset <= match_start_offset)
|
||||
new_cursor_offset = cursor_byte_offset;
|
||||
else if (cursor_byte_offset >= match_end_offset)
|
||||
new_cursor_offset = cursor_byte_offset + ((ptrdiff_t) replacement_len - (ptrdiff_t) match_len);
|
||||
else
|
||||
new_cursor_offset = match_start_offset + (ptrdiff_t) replacement_len;
|
||||
buf = g_string_sized_new (strlen (text) + 32);
|
||||
g_string_append_len (buf, text, match_start - text);
|
||||
g_string_append (buf, pop->cmd);
|
||||
g_string_append (buf, match_start + match_len);
|
||||
SPELL_ENTRY_SET_TEXT (t, buf->str);
|
||||
SPELL_ENTRY_SET_POS (t, len_to_offset (buf->str, new_cursor_offset));
|
||||
new_cursor_offset = len_to_offset (buf->str, new_cursor_offset);
|
||||
SPELL_ENTRY_SET_POS (t, new_cursor_offset);
|
||||
g_object_set_data (G_OBJECT (t), "zoitechat-replace-pos", GINT_TO_POINTER ((gint) new_cursor_offset));
|
||||
g_idle_add (replace_set_pos_idle, g_object_ref (t));
|
||||
g_string_free (buf, TRUE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user