static void afstomp_create_connect_frame(STOMPDestDriver *self, stomp_frame* frame) { stomp_frame_init(frame, "CONNECT", sizeof("CONNECT")); stomp_frame_add_header(frame, "login", self->user); stomp_frame_add_header(frame, "passcode", self->password); };
Test(stomp_proto, test_generate_gstring_from_frame) { stomp_frame frame; GString *actual; stomp_frame_init(&frame, "SEND", sizeof("SEND")); stomp_frame_add_header(&frame, "header_name", "header_value"); stomp_frame_set_body(&frame, "body", sizeof("body")); actual = create_gstring_from_frame(&frame); cr_assert_str_eq(actual->str, "SEND\nheader_name:header_value\n\nbody", "Generated stomp frame does not match"); stomp_frame_deinit(&frame); };
static int stomp_parse_command(char *buffer, int buflen, stomp_frame *frame, char **out_pos) { char *pos; pos = g_strstr_len(buffer, buflen, "\n"); if (pos == NULL) return STOMP_PARSE_ERROR; stomp_frame_init(frame, buffer, pos - buffer); *out_pos = pos + 1; return STOMP_PARSE_HEADER; }
static gboolean afstomp_worker_publish(STOMPDestDriver *self, LogMessage *msg) { gboolean success = TRUE; SBGString *body = NULL; stomp_frame frame; stomp_frame recv_frame; gchar seq_num[16]; if (!self->conn) { msg_error("STOMP server is not connected, not sending message!", NULL); return FALSE; } body = sb_gstring_acquire(); stomp_frame_init(&frame, "SEND", sizeof("SEND")); if (self->persistent) stomp_frame_add_header(&frame, "persistent", "true"); stomp_frame_add_header(&frame, "destination", self->destination); if (self->ack_needed) { g_snprintf(seq_num, sizeof(seq_num), "%i", self->super.seq_num); stomp_frame_add_header(&frame, "receipt", seq_num); }; value_pairs_foreach(self->vp, afstomp_vp_foreach, msg, self->super.seq_num, LTZ_SEND, &self->template_options, &frame); afstomp_set_frame_body(self, body, &frame, msg); if (!afstomp_send_frame(self, &frame)) { msg_error("Error while inserting into STOMP server", NULL); success = FALSE; } if (success && self->ack_needed) success = stomp_receive_frame(self->conn, &recv_frame); sb_gstring_release(body); return success; }