const char *ESLevent::serialize(const char *format) { this_check(""); esl_safe_free(serialized_string); if (!event) { return ""; } if (esl_event_serialize(event, &serialized_string, ESL_TRUE) == ESL_SUCCESS) { return serialized_string; } return ""; }
static void *msg_thread_run(esl_thread_t *me, void *obj) { esl_handle_t *handle = (esl_handle_t *) obj; thread_running = 1; while(thread_running && handle->connected) { esl_status_t status = esl_recv_event_timed(handle, 10, 1, NULL); if (status == ESL_FAIL) { esl_log(ESL_LOG_WARNING, "Disconnected.\n"); running = thread_running = 0; } else if (status == ESL_SUCCESS) { if (handle->last_event) { const char *type = esl_event_get_header(handle->last_event, "content-type"); int known = 0; if (!esl_strlen_zero(type)) { if (!strcasecmp(type, "log/data")) { const char *userdata = esl_event_get_header(handle->last_event, "user-data"); if (esl_strlen_zero(userdata) || esl_strlen_zero(filter_uuid) || !strcasecmp(filter_uuid, userdata)) { int level = 0; const char *lname = esl_event_get_header(handle->last_event, "log-level"); #ifdef WIN32 DWORD len = (DWORD) strlen(handle->last_event->body); DWORD outbytes = 0; #endif if (lname) { level = atoi(lname); } #ifdef WIN32 SetConsoleTextAttribute(hStdout, COLORS[level]); WriteFile(hStdout, handle->last_event->body, len, &outbytes, NULL); SetConsoleTextAttribute(hStdout, wOldColorAttrs); #else printf("%s%s%s", COLORS[level], handle->last_event->body, ESL_SEQ_DEFAULT_COLOR); #endif } known++; } else if (!strcasecmp(type, "text/disconnect-notice")) { running = thread_running = 0; known++; } else if (!strcasecmp(type, "text/event-plain")) { char *foo; esl_event_serialize(handle->last_ievent, &foo, ESL_FALSE); printf("RECV EVENT\n%s\n", foo); free(foo); known++; } } if (!known) { char *foo; printf("INCOMING DATA [%s]\n%s\n", type, handle->last_event->body ? handle->last_event->body : ""); esl_event_serialize(handle->last_event, &foo, ESL_FALSE); printf("RECV EVENT\n%s\n", foo); free(foo); } } } usleep(1000); } thread_running = 0; esl_log(ESL_LOG_DEBUG, "Thread Done\n"); return NULL; }
static void *msg_thread_run(esl_thread_t *me, void *obj) { esl_handle_t *handle = (esl_handle_t *) obj; thread_running = 1; while(thread_running && handle->connected) { int aok = 1; esl_status_t status = esl_recv_event_timed(handle, 10, 1, NULL); if (status == ESL_FAIL) { esl_log(ESL_LOG_WARNING, "Disconnected.\n"); running = -1; thread_running = 0; } else if (status == ESL_SUCCESS) { aok = stdout_writable(); if (handle->last_event) { int known = 1; const char *type = esl_event_get_header(handle->last_event, "content-type"); if (!esl_strlen_zero(type)) { if (!strcasecmp(type, "log/data")) { const char *userdata = esl_event_get_header(handle->last_event, "user-data"); if (esl_strlen_zero(userdata) || esl_strlen_zero(filter_uuid) || !strcasecmp(filter_uuid, userdata)) { int level = 0; const char *lname = esl_event_get_header(handle->last_event, "log-level"); #ifdef WIN32 DWORD len = (DWORD) strlen(handle->last_event->body); DWORD outbytes = 0; #endif if (logfilter) { if (!strstr(handle->last_event->body, logfilter)) { continue; } } if (lname) { level = atoi(lname); } #ifndef WIN32 if (aok) { if (feature_level) clear_line(); if(!(global_profile->batch_mode)) { printf("%s", colors[level]); } if (global_profile->log_uuid && !esl_strlen_zero(userdata)) { printf("%s ", userdata); } printf("%s", handle->last_event->body); if(!(global_profile->batch_mode)) { if (!feature_level) printf("%s", ESL_SEQ_DEFAULT_COLOR); } if (feature_level) redisplay(); } #else if (aok) { if(!(global_profile->batch_mode)) { SetConsoleTextAttribute(hStdout, colors[level]); } if (global_profile->log_uuid && !esl_strlen_zero(userdata)) { WriteFile(hStdout, userdata, (DWORD)strlen(userdata), &outbytes, NULL); WriteFile(hStdout, " ", (DWORD)strlen(" "), &outbytes, NULL); } WriteFile(hStdout, handle->last_event->body, len, &outbytes, NULL); if(!(global_profile->batch_mode)) { SetConsoleTextAttribute(hStdout, wOldColorAttrs); } } #endif } } else if (!strcasecmp(type, "text/disconnect-notice")) { running = -1; thread_running = 0; } else if (!strcasecmp(type, "text/event-plain")) { char *s; esl_event_serialize(handle->last_ievent, &s, ESL_FALSE); if (aok) { clear_line(); output_printf("RECV EVENT\n%s\n", s); redisplay(); } free(s); } else { known = 0; } } if (aok && !known) { char *s; output_printf("INCOMING DATA [%s]\n%s\n", type, handle->last_event->body ? handle->last_event->body : ""); esl_event_serialize(handle->last_event, &s, ESL_FALSE); output_printf("RECV EVENT\n%s\n", s); redisplay(); free(s); } } } if (warn_stop) { if (aok) { clear_line(); output_printf("Type control-D or /exit or /quit or /bye to exit.\n\n"); redisplay(); } warn_stop = 0; } sleep_ms(1); } thread_running = 0; esl_log(ESL_LOG_DEBUG, "Thread Done\n"); return NULL; }