2019-02-25 20:28:31 +00:00
|
|
|
#include "wsfs/message.h"
|
2019-02-09 02:08:02 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <libwebsockets.h>
|
|
|
|
|
2019-03-03 11:48:58 +00:00
|
|
|
extern struct wsfs_message * wsfs_message_create(json_t const * value)
|
2019-02-09 02:08:02 +00:00
|
|
|
{
|
2019-03-03 11:48:58 +00:00
|
|
|
#if 0
|
|
|
|
char * msg = json_dumps(value, JSON_COMPACT);
|
|
|
|
puts(msg);
|
|
|
|
free(msg);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct wsfs_message * message = NULL;
|
|
|
|
size_t const length = json_dumpb(value, NULL, 0, JSON_COMPACT);
|
|
|
|
|
|
|
|
if (0 < length)
|
2019-02-09 02:08:02 +00:00
|
|
|
{
|
2019-03-03 11:48:58 +00:00
|
|
|
char * data = malloc(sizeof(struct wsfs_message) + LWS_PRE + length);
|
|
|
|
message = (struct wsfs_message *) data;
|
|
|
|
if (NULL != message)
|
|
|
|
{
|
|
|
|
message->data = &data[sizeof(struct wsfs_message) + LWS_PRE];
|
|
|
|
message->length = length;
|
|
|
|
message->next = NULL;
|
|
|
|
|
|
|
|
json_dumpb(value, message->data, length, JSON_COMPACT);
|
|
|
|
}
|
2019-02-09 02:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wsfs_message_dispose(
|
|
|
|
struct wsfs_message * message)
|
|
|
|
{
|
|
|
|
free(message);
|
|
|
|
}
|