diff --git a/cmdline/cmdline.c b/cmdline/cmdline.c index 389d1477..844ca110 100644 --- a/cmdline/cmdline.c +++ b/cmdline/cmdline.c @@ -580,20 +580,24 @@ char* mrmailbox_cmdline(mrmailbox_t* mailbox, const char* cmdline) if( mrchat_get_archived(chat) ) { statestr = " [Archived]"; } - else switch( poortext->m_state ) { + else switch( mrlot_get_state(poortext) ) { case MR_STATE_OUT_PENDING: statestr = " o"; break; case MR_STATE_OUT_DELIVERED: statestr = " √"; break; case MR_STATE_OUT_MDN_RCVD: statestr = " √√"; break; case MR_STATE_OUT_ERROR: statestr = " ERR"; break; } - char* timestr = mr_timestamp_to_str(poortext->m_timestamp); + char* timestr = mr_timestamp_to_str(mrlot_get_timestamp(poortext)); + char* text1 = mrlot_get_text1(poortext); + char* text2 = mrlot_get_text2(poortext); mrmailbox_log_info(mailbox, 0, "%s%s%s%s [%s]", - poortext->m_text1? poortext->m_text1 : "", - poortext->m_text1? ": " : "", - poortext->m_text2? poortext->m_text2 : NULL, + text1? text1 : "", + text1? ": " : "", + text2? text2 : "", statestr, timestr ); + free(text1); + free(text2); free(timestr); mrpoortext_unref(poortext); diff --git a/src/mrchatlist.h b/src/mrchatlist.h index 9ba114b6..1d61d144 100644 --- a/src/mrchatlist.h +++ b/src/mrchatlist.h @@ -28,7 +28,7 @@ extern "C" { typedef struct mrmailbox_t mrmailbox_t; -typedef struct mrlot_t mrlot_t; +typedef struct _mrlot mrlot_t; typedef struct _mrchat mrchat_t; typedef struct mrarray_t mrarray_t; diff --git a/src/mrlot-internal.h b/src/mrlot-internal.h new file mode 100644 index 00000000..65a0ecf9 --- /dev/null +++ b/src/mrlot-internal.h @@ -0,0 +1,46 @@ +/******************************************************************************* + * + * Delta Chat Core + * Copyright (C) 2017 Björn Petersen + * Contact: r10s@b44t.com, http://b44t.com + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see http://www.gnu.org/licenses/ . + * + ******************************************************************************/ + + +#ifndef __MRLOT_INTERNAL_H__ +#define __MRLOT_INTERNAL_H__ +#ifdef __cplusplus +extern "C" { +#endif + + +struct _mrlot +{ + /** @privatesection */ + uint32_t m_magic; /**< The magic is used to avoid passing structures of different types. */ + int m_text1_meaning; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ + char* m_text1; /**< The meaning of this string is defined by the creator of the object. The string is freed with mrlot_unref(). NULL if not applicable. */ + char* m_text2; /**< The meaning of this string is defined by the creator of the object. The string is freed with mrlot_unref(). NULL if not applicable. */ + time_t m_timestamp; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ + int m_state; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ +}; + + + +#ifdef __cplusplus +} /* /extern "C" */ +#endif +#endif /* __MRLOT_INTERNAL_H__ */ diff --git a/src/mrlot.c b/src/mrlot.c index 980a7957..a25adc04 100644 --- a/src/mrlot.c +++ b/src/mrlot.c @@ -81,6 +81,88 @@ void mrlot_empty(mrlot_t* ths) } +/** + * Get first string. The meaning of the string is defined by the creator or the object any may be roughly described by mrlot_get_text1_meaning(). + * + * @param lot The lot object. + * + * @return A string, the string may be empty and the returned value must be free()'d. NULL if there is no such string. + */ +char* mrlot_get_text1(mrlot_t* lot) +{ + if( lot == NULL || lot->m_magic != MR_LOT_MAGIC ) { + return NULL; + } + return strdup_keep_null(lot->m_text1); +} + + +/** + * Get second string. The meaning of the string is defined by the creator or the object. + * + * @param lot The lot object. + * + * @return A string, the string may be empty and the returned value must be free()'d . NULL if there is no such string. + */ +char* mrlot_get_text2(mrlot_t* lot) +{ + if( lot == NULL || lot->m_magic != MR_LOT_MAGIC ) { + return NULL; + } + return strdup_keep_null(lot->m_text2); +} + + +/** + * Get the meaning of the first string. Posssible meanings of the string are defined by the creator or the object and may be returned eg. + * as MR_TEXT1_DRAFT, MR_TEXT1_USERNAME or MR_TEXT1_SELF. + * + * @param lot The lot object. + * + * @return Returns the meaning of the first string, possible meanings are defined by the creator of the object. + * 0 if there is no concrete meaning or on errors. + */ +int mrlot_get_text1_meaning(mrlot_t* lot) +{ + if( lot == NULL || lot->m_magic != MR_LOT_MAGIC ) { + return 0; + } + return lot->m_text1_meaning; +} + + +/** + * Get the associated state. The meaning of the state is defined by the creator or the object. + * + * @param lot The lot object. + * + * @return The state as defined by the creator of the object. 0 if there is not state or on errors. + */ +int mrlot_get_state(mrlot_t* lot) +{ + if( lot == NULL || lot->m_magic != MR_LOT_MAGIC ) { + return 0; + } + return lot->m_state; +} + + +/** + * Get the associated timestamp. The meaning of the timestamp is defined by the creator or the object. + * + * @param lot The lot object. + * + * @return The timestamp as defined by the creator of the object. 0 if there is not timestamp or on errors. + */ +time_t mrlot_get_timestamp(mrlot_t* lot) +{ + if( lot == NULL || lot->m_magic != MR_LOT_MAGIC ) { + return 0; + } + return lot->m_timestamp; +} + + void mrlot_fill(mrlot_t* ths, const mrmsg_t* msg, const mrchat_t* chat, const mrcontact_t* contact) { if( ths == NULL || ths->m_magic != MR_LOT_MAGIC || msg == NULL ) { diff --git a/src/mrlot.h b/src/mrlot.h index d5150e7d..5866e32f 100644 --- a/src/mrlot.h +++ b/src/mrlot.h @@ -28,20 +28,14 @@ extern "C" { /** + * @class mrlot_t + * * An object containing a set of values. The meaning of the values is defined by the function returning the set object. * Set objects are created eg. by mrchatlist_get_summary(), mrmsg_get_summary() or by mrmsg_get_mediainfo(). * * NB: _Lot_ is used in the meaning _heap_ here. */ -typedef struct mrlot_t -{ - uint32_t m_magic; /**< @private */ - int m_text1_meaning; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ - char* m_text1; /**< The meaning of this string is defined by the creator of the object. The string is freed with mrlot_unref(). NULL if not applicable. */ - char* m_text2; /**< The meaning of this string is defined by the creator of the object. The string is freed with mrlot_unref(). NULL if not applicable. */ - time_t m_timestamp; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ - int m_state; /**< The meaning of this value is defined by the creator of the object. 0 if not applicable. */ -} mrlot_t; +typedef struct _mrlot mrlot_t; #define MR_TEXT1_DRAFT 1 @@ -49,9 +43,14 @@ typedef struct mrlot_t #define MR_TEXT1_SELF 3 -mrlot_t* mrlot_new (); -void mrlot_empty (mrlot_t*); -void mrlot_unref (mrlot_t*); +mrlot_t* mrlot_new (); +void mrlot_empty (mrlot_t*); +void mrlot_unref (mrlot_t*); +char* mrlot_get_text1 (mrlot_t*); +char* mrlot_get_text2 (mrlot_t*); +int mrlot_get_text1_meaning (mrlot_t*); +int mrlot_get_state (mrlot_t*); +time_t mrlot_get_timestamp (mrlot_t*); /* library-internal */ diff --git a/src/mrmailbox_internal.h b/src/mrmailbox_internal.h index 18afa264..29103b57 100644 --- a/src/mrmailbox_internal.h +++ b/src/mrmailbox_internal.h @@ -35,6 +35,7 @@ extern "C" { #include "mrtools.h" #include "mrstock.h" #include "mrchat-internal.h" +#include "mrlot-internal.h" #ifdef __cplusplus