Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 1de71ce

Browse files
committed
Pass length of newline delimited JSON to parser.
1 parent 5629edd commit 1de71ce

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

src/comms.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ signald_read_cb(gpointer data, gint source, PurpleInputCondition cond)
2525
if(sa->input_buffer_position[-1] == '\n') {
2626
*sa->input_buffer_position = 0;
2727
purple_debug_info(SIGNALD_PLUGIN_ID, "got newline delimited message: %s", sa->input_buffer);
28-
signald_parse_input(sa, sa->input_buffer);
29-
// reset buffer
30-
*sa->input_buffer = 0;
28+
signald_parse_input(sa, sa->input_buffer, sa->input_buffer_position - sa->input_buffer - 1);
29+
// reset buffer write pointer
3130
sa->input_buffer_position = sa->input_buffer;
3231
}
3332
if (sa->input_buffer_position - sa->input_buffer + 1 == SIGNALD_INPUT_BUFSIZE) {
34-
purple_debug_error(SIGNALD_PLUGIN_ID, "message exceeded buffer size: %s\n", sa->input_buffer);
33+
purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_NETWORK_ERROR, "message exceeded buffer size");
34+
// reset buffer write pointer
35+
// should not have any effect since the connection will be destroyed, but better safe than sorry
3536
sa->input_buffer_position = sa->input_buffer;
36-
// NOTE: incomplete message may be passed to handler during next call
3737
return;
3838
}
3939
read = recv(sa->fd, sa->input_buffer_position, 1, MSG_DONTWAIT);

src/input.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ signald_handle_input(SignaldAccount *sa, JsonNode *root)
164164
}
165165

166166
void
167-
signald_parse_input(SignaldAccount *sa, const char * json)
167+
signald_parse_input(SignaldAccount *sa, const char * json, gssize length)
168168
{
169169
JsonParser *parser = json_parser_new();
170-
if (!json_parser_load_from_data(parser, json, -1, NULL)) {
170+
if (!json_parser_load_from_data(parser, json, length, NULL)) {
171171
purple_connection_error(sa->pc, PURPLE_CONNECTION_ERROR_OTHER_ERROR, "Error parsing input.");
172172
return;
173173
} else {

src/input.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
#include "structs.h"
44

5-
void signald_parse_input(SignaldAccount *sa, const char * json);
5+
void signald_parse_input(SignaldAccount *sa, const char * json, gssize length);

src/login.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ try_connect(SignaldAccount *sa, gchar *socket_path) {
146146
* Tries multiple possible default socket location at once in background.
147147
* In case the user has explicitly defined a socket location, only that one is considered.
148148
*/
149+
// TODO: find out how purple does connections in the gevent loop. use that instead of explicit sockets and threads.
149150
void
150151
signald_connect_socket(SignaldAccount *sa) {
151152
purple_connection_set_state(sa->pc, PURPLE_CONNECTION_CONNECTING);

0 commit comments

Comments
 (0)