Add new line ending after mod_event_socket JSON event
Hi FS Community, I'm trying to add a '\n' new line after the JSON event sent from FS on the mod_event_socket when the event type is JSON, I need to do so as I'm writing a JAVA event parser and it would make the code much simpler if I can add this new line after the event. I'm not able to know where to edit exactly in the mod_event_scoket file (I have no experience in C lang at all) but I think it is somewhere around line 1274. If someone could help with this, I would really appreciate it. (the java socket lib am writing uses Netty DelimiterBasedFrameDecoder on '\n' nut it breaks as after the JSON event there is no new line and Content-Length: is directly written after the JSON event) Mahmood Alkhalil.
Hi, So I figured it out static switch_status_t read_packet(listener_t *listener, switch_event_t **event, uint32_t timeout) { switch_size_t mlen, bytes = 0; char *mbuf = NULL; char newLine[2] = "\n"; //added this new line str char buf[1024] = ""; switch_size_t len; switch_status_t status = SWITCH_STATUS_SUCCESS; . . . . . if (switch_test_flag(listener, LFLAG_EVENTS)) { while (switch_queue_trypop(listener->event_queue, &pop) == SWITCH_STATUS_SUCCESS) { char hbuf[512]; switch_event_t *pevent = (switch_event_t *) pop; char *etype; do_sleep = 0; if (listener->format == EVENT_FORMAT_PLAIN) { etype = "plain"; switch_event_serialize(pevent, &listener->ebuf, SWITCH_TRUE); } else if (listener->format == EVENT_FORMAT_JSON) { etype = "json"; switch_event_serialize_json(pevent, &listener->ebuf); strcat(listener->ebuf, newLine); //concatenate new line str to the event } else { switch_xml_t xml; etype = "xml"; if ((xml = switch_event_xmlize(pevent, SWITCH_VA_NONE))) { listener->ebuf = switch_xml_toxml(xml, SWITCH_FALSE); switch_xml_free(xml); } else { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(listener->sessio> goto endloop; } } Mahmood Alkhalil. ________________________________ From: FreeSWITCH-users <freeswitch-users-bounces@lists.freeswitch.org> on behalf of Mahmood Alkhalil <mahmood.alkhalil@outlook.com> Sent: Thursday, January 20, 2022 10:49 AM To: freeswitch-users@lists.freeswitch.org <freeswitch-users@lists.freeswitch.org> Subject: [Freeswitch-users] Add new line ending after mod_event_socket JSON event Hi FS Community, I'm trying to add a '\n' new line after the JSON event sent from FS on the mod_event_socket when the event type is JSON, I need to do so as I'm writing a JAVA event parser and it would make the code much simpler if I can add this new line after the event. I'm not able to know where to edit exactly in the mod_event_scoket file (I have no experience in C lang at all) but I think it is somewhere around line 1274. If someone could help with this, I would really appreciate it. (the java socket lib am writing uses Netty DelimiterBasedFrameDecoder on '\n' nut it breaks as after the JSON event there is no new line and Content-Length: is directly written after the JSON event) Mahmood Alkhalil.
participants (1)
-
Mahmood Alkhalil