in eventmesh-sdks/eventmesh-sdk-c/src/rmb_msg.c [823:939]
int set_extfields_2_rmb_msg (StRmbMsg * pStMsg, const char *command, int iSeq)
{
char born_time[32];
char store_time[32];
char leave_time[32];
char arrive_time[32];
memset (born_time, 0x00, sizeof (born_time));
memset (store_time, 0x00, sizeof (store_time));
memset (leave_time, 0x00, sizeof (leave_time));
memset (arrive_time, 0x00, sizeof (arrive_time));
WEMQJSON *jsonDecoder = NULL;
WEMQJSON *jsonExtField = NULL;
WEMQJSON *property = json_tokener_parse (pStMsg->sysHeader.cProperty);
if (NULL != property)
{
if (json_object_object_get_ex
(property, MSG_BODY_PROPERTY_BORN_TIME_STR, &jsonDecoder))
{
const char *tmpTime = json_object_get_string (jsonDecoder);
snprintf (born_time, sizeof (born_time), "%s", tmpTime);
}
else
{
LOGRMB (RMB_LOG_ERROR, "In property, %s is null!",
MSG_BODY_PROPERTY_BORN_TIME_STR);
}
if (json_object_object_get_ex
(property, MSG_BODY_PROPERTY_STORE_TIME_STR, &jsonDecoder))
{
const char *tmpTime = json_object_get_string (jsonDecoder);
snprintf (store_time, sizeof (store_time), "%s", tmpTime);
}
else
{
LOGRMB (RMB_LOG_ERROR, "In property, %s is null!",
MSG_BODY_PROPERTY_STORE_TIME_STR);
}
if (json_object_object_get_ex
(property, MSG_BODY_PROPERTY_LEAVE_TIME_STR, &jsonDecoder))
{
const char *tmpTime = json_object_get_string (jsonDecoder);
snprintf (leave_time, sizeof (leave_time), "%s", tmpTime);
}
else
{
LOGRMB (RMB_LOG_ERROR, "In property, %s is null!",
MSG_BODY_PROPERTY_LEAVE_TIME_STR);
}
if (json_object_object_get_ex
(property, MSG_BODY_PROPERTY_ARRIVE_TIME_STR, &jsonDecoder))
{
const char *tmpTime = json_object_get_string (jsonDecoder);
snprintf (arrive_time, sizeof (arrive_time), "%s", tmpTime);
}
else
{
LOGRMB (RMB_LOG_ERROR, "In property, %s is null!",
MSG_BODY_PROPERTY_ARRIVE_TIME_STR);
}
}
jsonExtField = json_tokener_parse (pStMsg->sysHeader.cExtFields);
if (jsonExtField == NULL)
{
jsonExtField = json_object_new_object ();
}
if (strcmp (command, REQUEST_TO_CLIENT) == 0
|| strcmp (command, ASYNC_MESSAGE_TO_CLIENT) == 0
|| strcmp (command, BROADCAST_MESSAGE_TO_CLIENT) == 0)
{
json_object_object_add (jsonExtField, REQ_BORN_TIMESTAMP,
json_object_new_string (born_time));
json_object_object_add (jsonExtField, REQ_STORE_TIMESTAMP,
json_object_new_string (store_time));
json_object_object_add (jsonExtField, REQ_LEAVE_TIMESTAMP,
json_object_new_string (leave_time));
json_object_object_add (jsonExtField, REQ_ARRIVE_TIMESTAMP,
json_object_new_string (arrive_time));
json_object_object_add (jsonExtField, MSG_BODY_SYSTEM_ACK_SEQ,
json_object_new_int (iSeq));
}
else if (strcmp (command, RESPONSE_TO_CLIENT) == 0)
{
json_object_object_add (jsonExtField, RSP_BORN_TIMESTAMP,
json_object_new_string (born_time));
json_object_object_add (jsonExtField, RSP_STORE_TIMESTAMP,
json_object_new_string (store_time));
json_object_object_add (jsonExtField, RSP_LEAVE_TIMESTAMP,
json_object_new_string (leave_time));
json_object_object_add (jsonExtField, RSP_ARRIVE_TIMESTAMP,
json_object_new_string (arrive_time));
}
const char *extFields = json_object_get_string (jsonExtField);
if (extFields != NULL)
{
int len = (int) strlen (extFields);
if (len >= RMB_SYSTEMHEADER_EXTFIELDS_MAX_LEN)
{
LOGRMB (RMB_LOG_ERROR, "systemHeader len=%d too large!max_limit=%d: %s",
len, RMB_SYSTEMHEADER_EXTFIELDS_MAX_LEN, extFields);
}
else
{
snprintf (pStMsg->sysHeader.cExtFields,
sizeof (pStMsg->sysHeader.cExtFields), "%s", extFields);
}
}
json_object_put (property);
json_object_put (jsonExtField);
return 0;
}