int32_t sec_recv_real; /* time received, seconds, realtime */
int32_t nsec_recv_real; /* time received, nanoseconds, realtime*/
int32_t tag_len;
- char msg[]; /* the entry's payload */
+ char msg[]; /* the entry's payload. Contains tag and message separated by \0 ie: "tag\0message\0". Has variable length, which is contained in 'len' field of this struct*/
} dlogutil_entry_s;
struct dlogutil_entry_with_msg {
int parse_syslog_datagram(const char * buffer, int buffer_size, dlogutil_entry_s * le);
void parse_androidlogger_message(struct android_logger_entry *ale, dlogutil_entry_s *le, size_t dgram_size);
void parse_pipe_message(struct pipe_logger_entry *ple, dlogutil_entry_s *le, size_t msg_size);
+void deep_copy_dlogutil_entry_s(dlogutil_entry_s *dest, const dlogutil_entry_s *source);
#ifdef __cplusplus
}
}
/**
+ * @brief This function makes a deep copy of dlogutil_entry_s.
+ * @details In order to work properly dest, has to have sufficient allocated memory and source has to have a correct len field.
+ * @param[out] dest Struct to which data is copied
+ * @param[in] source Struct from which data is copied
+ */
+void deep_copy_dlogutil_entry_s(dlogutil_entry_s *dest, const dlogutil_entry_s *source)
+{
+ assert(dest);
+ assert(source);
+ memcpy(dest, source, sizeof(dlogutil_entry_s)+source->len);
+}
+/**
* @}
*/
#include <queued_entry.h>
#include <queued_entry_timestamp.h>
+
+/**
+ * @brief This function tests deep_copy_dlogutil_entry_s function
+ */
+void check_deep_copy(void)
+{
+ char test_data[] = "tag\0important message";
+ dlogutil_entry_s *source = calloc(1, sizeof(*source) + sizeof test_data);
+ assert(source);
+
+ //setting up struct
+ source->len = sizeof test_data;
+ source->priority = DLOG_DEBUG;
+ source->padding = 16;
+ source->pid = 17;
+ source->tid = 18;
+ source->sec_sent_mono = 12;
+ source->nsec_sent_mono = 1212;
+ source->sec_sent_real = 13;
+ source->nsec_sent_real = 1313;
+ source->sec_recv_mono = 14;
+ source->nsec_recv_mono = 1414;
+ source->sec_recv_real = 15;
+ source->nsec_recv_real = 1515;
+ source->tag_len = strlen(test_data);
+ memcpy(source->msg, test_data, source->len);
+
+ //creating new struct
+ dlogutil_entry_s *dest = calloc(1, sizeof(*dest) + sizeof test_data);
+
+ //copying
+ deep_copy_dlogutil_entry_s(dest, source);
+
+ //check if pointer isn't just copied
+ assert(source != dest);
+
+ //check if internal fields match
+ assert(dest->len == source->len);
+ assert(dest->priority == source->priority);
+ assert(dest->padding == source->padding);
+ assert(dest->pid == source->pid);
+ assert(dest->tid == source->tid);
+ assert(dest->sec_sent_mono == source->sec_sent_mono);
+ assert(dest->nsec_sent_mono == source->nsec_sent_mono);
+ assert(dest->sec_sent_real == source->sec_sent_real);
+ assert(dest->nsec_sent_real == source->nsec_sent_real);
+ assert(dest->sec_recv_mono == source->sec_recv_mono);
+ assert(dest->nsec_recv_mono == source->nsec_recv_mono);
+ assert(dest->sec_recv_real == source->sec_recv_real);
+ assert(dest->nsec_recv_real == source->nsec_recv_real);
+ assert(dest->tag_len == source->tag_len);
+
+ //check if payload pinter isn't just copied
+ assert(dest->msg != source->msg);
+ assert(!memcmp(dest->msg,source->msg,source->len));
+
+ free(source);
+ free(dest);
+}
+
int main(void)
{
+ check_deep_copy();
assert(get_proper_clock(DLOGUTIL_SORT_SENT_MONO) == CLOCK_MONOTONIC);
assert(get_proper_clock(DLOGUTIL_SORT_SENT_REAL) == CLOCK_REALTIME);
assert(get_proper_clock(DLOGUTIL_SORT_RECV_MONO) == CLOCK_MONOTONIC);