Ejemplo n.º 1
0
JsonNode*   cometd_ping_ls(cometd* h, char *target)
{
  JsonObject	*adviceObject = json_object_new();
  JsonNode	*adviceNode = json_node_new(JSON_NODE_OBJECT);
  JsonNode	*adviceRoot = json_node_init_object(adviceNode, adviceObject);

  adviceObject = json_node_get_object(adviceRoot);

  json_object_set_string_member(adviceObject, "folder", "/");

  
  JsonNode*	root = json_node_new(JSON_NODE_OBJECT);
  JsonObject*	obj  = json_object_new();
  gint64	seed = ++(h->conn->msg_id_seed);

  char*  connection_type = cometd_current_transport(h)->name;
  
  json_object_set_int_member   (obj, COMETD_MSG_ID_FIELD,      seed);
  json_object_set_string_member(obj, COMETD_MSG_CHANNEL_FIELD, target);
  json_object_set_string_member(obj, "connectionType",         connection_type);
  json_object_set_member(obj, "data", adviceRoot);
  json_object_set_string_member(obj, "clientId",               cometd_conn_client_id(h->conn));
 
  json_node_take_object(root, obj);

  return(root);
}
Ejemplo n.º 2
0
static JsonNode *
snra_json_value_to_node (const GValue *value)
{
  JsonNode *n = NULL;

  if (GST_VALUE_HOLDS_STRUCTURE (value)) {
    const GstStructure *s = gst_value_get_structure (value);
    n = snra_json_from_gst_structure (s);
  }
  else if (GST_VALUE_HOLDS_ARRAY (value)) {
    guint count = gst_value_array_get_size (value);
    guint i;
    JsonArray *arr = json_array_sized_new (count);
    for (i = 0; i < count; i++) {
      const GValue *sub_val = gst_value_array_get_value (value, i);
      JsonNode *tmp = snra_json_value_to_node (sub_val);
      if (tmp)
        json_array_add_element (arr, tmp);
    }
    n = json_node_new (JSON_NODE_ARRAY);
    json_node_take_array (n, arr);
  } else {
    n = json_node_new (JSON_NODE_VALUE);
    json_node_set_value (n, value);
  }

  return n;
}
Ejemplo n.º 3
0
// Create a gchar** into a json array
JsonNode *glib_jsonrpc_json_strv_to_json_array(gchar **strv)
{
  JsonArray *array = json_array_new();
  gchar **p = strv;
  while(*p)
    {
      JsonNode *node = json_node_new(JSON_NODE_VALUE);
      json_node_set_string(node, *p);
      json_array_add_element(array,node);
      p++;
    }
  JsonNode *node = json_node_new(JSON_NODE_ARRAY);
  json_node_take_array(node, array);
  return node;
}
Ejemplo n.º 4
0
Archivo: ui.c Proyecto: automata/imgflo
static void
send_response(SoupWebsocketConnection *ws,
            const gchar *protocol, const gchar *command, JsonObject *payload)
{
    g_return_if_fail(ws);

    JsonObject *response = json_object_new();
    g_assert(response);

    json_object_set_string_member(response, "protocol", protocol);
    json_object_set_string_member(response, "command", command);
    json_object_set_object_member(response, "payload", payload);

    JsonGenerator *generator = json_generator_new();
    JsonNode *node = json_node_new(JSON_NODE_OBJECT);
    json_node_take_object(node, response);
    json_generator_set_root(generator, node);

    gsize len = 0;
    gchar *data = json_generator_to_data(generator, &len);
    GBytes *resp = g_bytes_new_take(data, len);
    g_print ("SEND: %.*s\n", (int)len, data);
    soup_websocket_connection_send(ws, SOUP_WEBSOCKET_DATA_TEXT, resp);

    g_object_unref(generator);
}
Ejemplo n.º 5
0
static char *
file_list_to_json (GList *files)
{
    JsonNode *root;
    JsonArray *array;
    GList *ptr;
    char *file;
    JsonGenerator *gen;
    char *json_data;
    gsize len;

    root = json_node_new (JSON_NODE_ARRAY);
    array = json_array_new ();

    for (ptr = files; ptr; ptr = ptr->next) {
        file = ptr->data;
        json_array_add_string_element (array, file);
    }
    json_node_set_array (root, array);

    gen = json_generator_new ();
    json_generator_set_root (gen, root);
    json_data = json_generator_to_data (gen, &len);
    json_node_free (root);
    g_object_unref (gen);

    return json_data;
}
Ejemplo n.º 6
0
JsonNode*
cometd_new_handshake_message(const cometd* h)
{
  gint64 seed = ++(h->conn->msg_id_seed);

  JsonNode*   root = json_node_new(JSON_NODE_OBJECT);
  JsonObject* obj  = json_object_new();

  json_object_set_int_member   (obj, COMETD_MSG_ID_FIELD,          seed);
  json_object_set_string_member(obj, COMETD_MSG_CHANNEL_FIELD,     COMETD_CHANNEL_META_HANDSHAKE);
  json_object_set_string_member(obj, COMETD_MSG_VERSION_FIELD,     COMETD_VERSION);
  json_object_set_string_member(obj, COMETD_MSG_MIN_VERSION_FIELD, COMETD_MIN_VERSION);

  // construct advice - TODO: these values should not be hardcoded
  JsonObject* advice = json_object_new();
  json_object_set_int_member(advice, "timeout",  60000);
  json_object_set_int_member(advice, "interval", 0);
  json_object_set_object_member(obj, COMETD_MSG_ADVICE_FIELD, advice);

  // construct supported transports
  JsonArray* json_transports = json_array_new();

  GList* entry = h->config->transports;
  while (entry){
    cometd_transport* t = entry->data;
    json_array_add_string_element(json_transports, t->name);
    entry = g_list_next(entry);
  }
  json_object_set_array_member(obj, "supportedConnectionTypes", json_transports);

  // call extensions with message - TODO: implement extensions first
  json_node_take_object(root, obj);

  return root;
}
Ejemplo n.º 7
0
static JsonNode *
melo_jsonrpc_build_error_nodev (MeloJSONRPCError error_code,
                                const char *error_format, va_list args)
{
  gchar *error_message;
  JsonObject *obj;
  JsonNode *node;

  /* Create a new JSON builder */
  obj = json_object_new ();
  if (!obj)
    return NULL;

  /* Generate error message */
  error_message = g_strdup_vprintf (error_format, args);

  /* Begin a new object */
  json_object_set_int_member (obj, "code", error_code);
  json_object_set_string_member (obj, "message", error_message);

  /* Free message */
  g_free (error_message);

  /* Create node */
  node = json_node_new (JSON_NODE_OBJECT);
  json_node_take_object (node, obj);

  return node;
}
Ejemplo n.º 8
0
JsonNode*
cometd_new_publish_message(const cometd* h,
                           const char* channel,
                           JsonNode* data)
{
  gint64 seed = ++(h->conn->msg_id_seed);

  JsonNode*   root = json_node_new(JSON_NODE_OBJECT);
  JsonObject* obj  = json_object_new();

  json_object_set_int_member(obj, COMETD_MSG_ID_FIELD, seed);

  json_object_set_string_member(obj,
                                COMETD_MSG_CHANNEL_FIELD,
                                channel);

  json_object_set_string_member(obj,
                                COMETD_MSG_CLIENT_ID_FIELD,
                                cometd_conn_client_id(h->conn));

  json_object_set_member(obj,
                         COMETD_MSG_DATA_FIELD,
                         json_node_copy(data));

  json_node_take_object(root, obj);

  return root;
}
Ejemplo n.º 9
0
int main(void)
{
  cometd			*cometd = cometd_new();
  JsonNode			*connect = json_node_new(JSON_NODE_OBJECT);
  
  /*After the new you can enable or disable the Websocket simply do this, disabled by defautl*/
  cometd->config->webSockState = true;
  
  
  if (cometd->config->webSockState)
    return(webSocketTest());
  
  cometd_configure(cometd, COMETDOPT_URL, "http://m.zpush.ovh:8080/str/strd");
  cometd_configure(cometd, COMETDOPT_MAX_BACKOFF, 5000);
  struct _cometd_ext* logger = cometd_ext_logger_new();
  cometd_ext_add(&cometd->exts, logger);
  cometd_connect(cometd);
  connect = cometd_msg_connect_new(cometd);
  cometd_transport_send(cometd, connect);


  //cometd_subscribe(cometd, "/service/GmY-HuzW/6sd0/echo", handler);
  cometd_transport_send(cometd, cometd_ping_ls(cometd, "/service/GmY-HuzW/6sd0/echo"));
  //cometd_subscribe(cometd, "/service/GmY-HuzW/6sd0/ls", handler);
  //cometd_subscribe(cometd, "service/GmY-HuzW/6sd0/updateMeta", handler);
  //cometd_subscribe(cometd, "/service/GmY-HuzW/6sd0/ls", handler);
  //cometd_subscribe(cometd, "/service/GmY-HuzW/6sd0/newFile", handler);

  
  cometd_listen(cometd);
  return 0;
}
Ejemplo n.º 10
0
static JSValueRef
js_emit (JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject,
	 size_t argumentCount, const JSValueRef arguments[],
	 JSValueRef * exception)
{
  JsonObject *obj;
  JsonNode *node;
  gchar *buffer;
  if (argumentCount != 1)
    {
      *exception = JSValueMakeNumber (ctx, 1);
      return NULL;
    }
  if (JSValueIsObject (ctx, arguments[0]) == false)
    {
      *exception = JSValueMakeNumber (ctx, 1);
      return NULL;
    }

  obj = json_object_new();

  js_value (ctx, (JSObjectRef) arguments[0], &node);
  json_object_set_member (obj, "emit", node);

  JsonNode *node1 = json_node_new (JSON_NODE_OBJECT);

  if (node1 == NULL)
    {
      json_object_unref (obj);
      return NULL;
    }

  json_node_set_object (node1, obj);

  JsonGenerator *gen = json_generator_new();

  if (gen == NULL)
    {
      json_node_free (node1);
      return NULL;
    }

  json_generator_set_root (gen, node1 );
  buffer = json_generator_to_data (gen,NULL);

  if (buffer == NULL)
    {
      json_node_free (node1);
      g_object_unref (gen);
      return NULL;
    }

  json_node_free (node1);
  g_object_unref (gen);

  puts (buffer);
  g_free (buffer);

  return NULL; /* shouldn't be an object ? */
}
Ejemplo n.º 11
0
JsonNode*
cometd_new_unsubscribe_message(const cometd* h, const char* channel)
{
  
  gint64 seed = ++(h->conn->msg_id_seed);

  JsonNode*   root = json_node_new(JSON_NODE_OBJECT);
  JsonObject* obj  = json_object_new();

  json_object_set_int_member(obj, COMETD_MSG_ID_FIELD, seed);

  json_object_set_string_member(obj,
                                COMETD_MSG_CHANNEL_FIELD,
                                COMETD_CHANNEL_META_UNSUBSCRIBE);

  json_object_set_string_member(obj,
                                COMETD_MSG_CLIENT_ID_FIELD,
                                cometd_conn_client_id(h->conn));

  json_object_set_string_member(obj,
                                COMETD_MSG_SUBSCRIPTION_FIELD,
                                channel);

  json_node_take_object(root, obj);

  return root;
}
Ejemplo n.º 12
0
static JsonGenerator *
_model_to_generator (MexQueueModel *model)
{
  gint i;
  JsonArray *json_array;
  JsonNode *root;
  JsonGenerator *generator;

  json_array = json_array_sized_new (mex_model_get_length (MEX_MODEL (model)));

  for (i = 0; i < mex_model_get_length (MEX_MODEL (model)); i++)
    {
      MexContent *content;
      JsonNode *content_node;

      content = mex_model_get_content (MEX_MODEL (model), i);

      content_node = json_gobject_serialize (G_OBJECT (content));
      json_array_add_element (json_array, content_node);
    }

  generator = json_generator_new ();
  root = json_node_new (JSON_NODE_ARRAY);
  json_node_set_array (root, json_array);

  json_generator_set_root (generator, root);

  json_array_unref (json_array);
  json_node_free (root);

  return generator;
}
Ejemplo n.º 13
0
/**
 * json_gvariant_serialize:
 * @variant: A #GVariant to convert
 *
 * Converts @variant to a JSON tree.
 *
 * Return value: (transfer full): A #JsonNode representing the root of the
 *   JSON data structure obtained from @variant
 *
 * Since: 0.14
 */
JsonNode *
json_gvariant_serialize (GVariant *variant)
{
  JsonNode *json_node = NULL;
  GVariantClass class;

  g_return_val_if_fail (variant != NULL, NULL);

  class = g_variant_classify (variant);

  if (! g_variant_is_container (variant))
    {
      json_node = json_node_new (JSON_NODE_VALUE);

      switch (class)
        {
        case G_VARIANT_CLASS_BOOLEAN:
          json_node_set_boolean (json_node, g_variant_get_boolean (variant));
          break;

        case G_VARIANT_CLASS_BYTE:
          json_node_set_int (json_node, g_variant_get_byte (variant));
          break;
        case G_VARIANT_CLASS_INT16:
          json_node_set_int (json_node, g_variant_get_int16 (variant));
          break;
        case G_VARIANT_CLASS_UINT16:
          json_node_set_int (json_node, g_variant_get_uint16 (variant));
          break;
        case G_VARIANT_CLASS_INT32:
          json_node_set_int (json_node, g_variant_get_int32 (variant));
          break;
        case G_VARIANT_CLASS_UINT32:
          json_node_set_int (json_node, g_variant_get_uint32 (variant));
          break;
        case G_VARIANT_CLASS_INT64:
          json_node_set_int (json_node, g_variant_get_int64 (variant));
          break;
        case G_VARIANT_CLASS_UINT64:
          json_node_set_int (json_node, g_variant_get_uint64 (variant));
          break;
        case G_VARIANT_CLASS_HANDLE:
          json_node_set_int (json_node, g_variant_get_handle (variant));
          break;

        case G_VARIANT_CLASS_DOUBLE:
          json_node_set_double (json_node, g_variant_get_double (variant));
          break;

        case G_VARIANT_CLASS_STRING:
        case G_VARIANT_CLASS_OBJECT_PATH:
        case G_VARIANT_CLASS_SIGNATURE:
          json_node_set_string (json_node, g_variant_get_string (variant, NULL));
          break;

        default:
          break;
        }
    }
Ejemplo n.º 14
0
static void
glide_document_json_obj_set_name (GlideDocument *document, JsonObject *obj)
{
  JsonNode *node = json_node_new (JSON_NODE_VALUE);
  json_node_set_string (node, document->priv->name);
  
  json_object_set_member (obj, "name", node);
}
Ejemplo n.º 15
0
static JsonNode* create_fault_msg_response(int error_num, const char *message, int id)
{
  JsonNode *msg_node = json_node_new(JSON_NODE_VALUE);
  json_node_set_string(msg_node, message);
  JsonNode *node = create_fault_value_response(error_num, msg_node, id);
  json_node_free(msg_node);
  return node;
}
Ejemplo n.º 16
0
JsonNode*
cometd_msg_wrap(JsonNode* msg)
{
    JsonNode* payload = json_node_new(JSON_NODE_ARRAY);
    JsonArray* arr = json_array_new();
    json_array_add_element(arr, msg);
    json_node_take_array(payload, arr);
    return payload;
}
Ejemplo n.º 17
0
/**
 * json_array_add_string_element:
 * @array: a #JsonArray
 * @value: a string value
 *
 * Conveniently adds a string @value into @array
 *
 * See also: json_array_add_element(), json_node_set_string()
 *
 * Since: 0.8
 */
void
json_array_add_string_element (JsonArray   *array,
                               const gchar *value)
{
  JsonNode *node;

  g_return_if_fail (array != NULL);
  g_return_if_fail (value != NULL);

  if (value != NULL)
    {
      node = json_node_new (JSON_NODE_VALUE);
      json_node_set_string (node, value);
    }
  else
    node = json_node_new (JSON_NODE_NULL);

  g_ptr_array_add (array->elements, node);
}
Ejemplo n.º 18
0
/**
 * json_array_add_object_element:
 * @array: a #JsonArray
 * @value: (transfer full): a #JsonObject
 *
 * Conveniently adds an object into @array. The @array takes ownership
 * of the newly added #JsonObject
 *
 * See also: json_array_add_element(), json_node_take_object()
 *
 * Since: 0.8
 */
void
json_array_add_object_element (JsonArray  *array,
                               JsonObject *value)
{
  JsonNode *node;

  g_return_if_fail (array != NULL);
  g_return_if_fail (value != NULL);

  if (value != NULL)
    {
      node = json_node_new (JSON_NODE_OBJECT);
      json_node_take_object (node, value);
    }
  else
    node = json_node_new (JSON_NODE_NULL);

  g_ptr_array_add (array->elements, node);
}
Ejemplo n.º 19
0
static JsonNode *
clutter_paint_node_serialize (ClutterPaintNode *node)
{
  ClutterPaintNodeClass *klass = CLUTTER_PAINT_NODE_GET_CLASS (node);

  if (klass->serialize != NULL)
    return klass->serialize (node);

  return json_node_new (JSON_NODE_NULL);
}
Ejemplo n.º 20
0
/**
 * json_object_set_object_member:
 * @object: a #JsonObject
 * @member_name: the name of the member
 * @value: (transfer full): the value of the member
 *
 * Convenience function for setting an object @value of
 * @member_name inside @object.
 *
 * The @object will take ownership of the passed #JsonObject
 *
 * See also: json_object_set_member()
 *
 * Since: 0.8
 */
void
json_object_set_object_member (JsonObject  *object,
                               const gchar *member_name,
                               JsonObject  *value)
{
  JsonNode *node;

  g_return_if_fail (object != NULL);
  g_return_if_fail (member_name != NULL);

  if (value != NULL)
    {
      node = json_node_new (JSON_NODE_OBJECT);
      json_node_take_object (node, value);
    }
  else
    node = json_node_new (JSON_NODE_NULL);

  object_set_member_internal (object, member_name, node);
}
Ejemplo n.º 21
0
/**
 * json_array_add_null_element:
 * @array: a #JsonArray
 *
 * Conveniently adds a null element into @array
 *
 * See also: json_array_add_element(), %JSON_NODE_NULL
 *
 * Since: 0.8
 */
void
json_array_add_null_element (JsonArray *array)
{
  JsonNode *node;

  g_return_if_fail (array != NULL);

  node = json_node_new (JSON_NODE_NULL);

  g_ptr_array_add (array->elements, node);
}
Ejemplo n.º 22
0
static JsonNode*
to_json_string (const gchar *str)
{
  gchar *escaped = json_strescape (str);
  JsonNode *node = json_node_new (JSON_NODE_VALUE);
  
  json_node_set_string (node, escaped);

  g_free (escaped);
  
  return node;
}
Ejemplo n.º 23
0
static void
glide_json_object_add_image_properties (JsonObject *obj, GlideImage *image)
{
  JsonNode *n = json_node_new (JSON_NODE_OBJECT);
  JsonObject *img_obj = json_object_new ();
  
  json_node_set_object (n, img_obj);
  
  glide_json_object_set_string (img_obj, "filename", image->priv->filename);
  
  json_object_set_member (obj, "image-properties", n);
}
Ejemplo n.º 24
0
static JsonNode *base_request(gchar * method)
{
    JsonNode *root = json_node_new(JSON_NODE_OBJECT);
    JsonObject *object = json_object_new();
    JsonObject *args = json_object_new();

    json_object_set_string_member(object, PARAM_METHOD, method);
    json_object_set_object_member(object, PARAM_ARGUMENTS, args);
    json_node_take_object(root, object);

    return root;
}
Ejemplo n.º 25
0
/**
 * json_gobject_serialize:
 * @gobject: a #GObject
 *
 * Creates a #JsonNode representing the passed #GObject
 * instance. Each member of the returned JSON object will
 * map to a property of the #GObject
 *
 * Return value: (transfer full): the newly created #JsonNode
 *   of type %JSON_NODE_OBJECT. Use json_node_free() to free
 *   the resources allocated by this function
 *
 * Since: 0.10
 */
JsonNode *
json_gobject_serialize (GObject *gobject)
{
  JsonNode *retval;

  g_return_val_if_fail (G_IS_OBJECT (gobject), NULL);

  retval = json_node_new (JSON_NODE_OBJECT);
  json_node_take_object (retval, json_gobject_dump (gobject));

  return retval;
}
Ejemplo n.º 26
0
/**
 * json_object_set_null_member:
 * @object: a #JsonObject
 * @member_name: the name of the member
 *
 * Convenience function for setting a null @value of
 * @member_name inside @object.
 *
 * See also: json_object_set_member()
 *
 * Since: 0.8
 */
void
json_object_set_null_member (JsonObject  *object,
                             const gchar *member_name)
{
  JsonNode *node;

  g_return_if_fail (object != NULL);
  g_return_if_fail (member_name != NULL);

  node = json_node_new (JSON_NODE_NULL);
  object_set_member_internal (object, member_name, node);
}
Ejemplo n.º 27
0
JsonNode *
snra_json_from_gst_structure (const GstStructure * s)
{
  JsonNode *root = json_node_new (JSON_NODE_OBJECT);

  json_node_take_object (root, json_object_new ());

  gst_structure_foreach (s,
      (GstStructureForeachFunc) snra_add_struct_object,
      json_node_get_object (root));

  return root;
}
Ejemplo n.º 28
0
/**
 * json_array_add_boolean_element:
 * @array: a #JsonArray
 * @value: a boolean value
 *
 * Conveniently adds a boolean @value into @array
 *
 * See also: json_array_add_element(), json_node_set_boolean()
 *
 * Since: 0.8
 */
void
json_array_add_boolean_element (JsonArray *array,
                                gboolean   value)
{
  JsonNode *node;

  g_return_if_fail (array != NULL);

  node = json_node_new (JSON_NODE_VALUE);
  json_node_set_boolean (node, value);

  g_ptr_array_add (array->elements, node);
}
Ejemplo n.º 29
0
/**
 * json_object_set_array_member:
 * @object: a #JsonObject
 * @member_name: the name of the member
 * @value: the value of the member
 *
 * Convenience function for setting an array @value of
 * @member_name inside @object.
 *
 * The @object will take ownership of the passed #JsonArray
 *
 * See also: json_object_set_member()
 *
 * Since: 0.8
 */
void
json_object_set_array_member (JsonObject  *object,
                              const gchar *member_name,
                              JsonArray   *value)
{
  JsonNode *node;

  g_return_if_fail (object != NULL);
  g_return_if_fail (member_name != NULL);

  node = json_node_new (JSON_NODE_ARRAY);
  json_node_take_array (node, value);
  object_set_member_internal (object, member_name, node);
}
Ejemplo n.º 30
0
/**
 * json_object_set_string_member:
 * @object: a #JsonObject
 * @member_name: the name of the member
 * @value: the value of the member
 *
 * Convenience function for setting a string @value of
 * @member_name inside @object.
 *
 * See also: json_object_set_member()
 *
 * Since: 0.8
 */
void
json_object_set_string_member (JsonObject  *object,
                               const gchar *member_name,
                               const gchar *value)
{
  JsonNode *node;

  g_return_if_fail (object != NULL);
  g_return_if_fail (member_name != NULL);

  node = json_node_new (JSON_NODE_VALUE);
  json_node_set_string (node, value);
  object_set_member_internal (object, member_name, node);
}