Esempio n. 1
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;
}
Esempio n. 2
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;
}
Esempio n. 3
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);
}
END_TEST

START_TEST (test_cometd_process_handshake_success)
{
    cometd_conn* conn = g_instance->conn;
    JsonNode* n = json_from_fixture("handshake_resp_lp");

    fail_unless(cometd_conn_is_state(conn, COMETD_UNINITIALIZED));
    fail_unless(cometd_current_transport(g_instance) == NULL);
    fail_unless(cometd_conn_client_id(conn) == NULL);

    int code = cometd_process_handshake(g_instance, n);

    fail_unless(code == COMETD_SUCCESS);
    fail_unless(cometd_conn_is_state(conn, COMETD_HANDSHAKE_SUCCESS));
    fail_if(cometd_current_transport(g_instance) == NULL);
    fail_if(cometd_conn_client_id(conn) == NULL);

    json_node_free(n);
}
END_TEST

START_TEST (test_cometd_process_handshake_no_transport)
{
    cometd_conn* conn = g_instance->conn;
    JsonNode* n = json_from_fixture("handshake_resp_unsupported_transports");

    fail_unless(cometd_conn_is_state(conn, COMETD_UNINITIALIZED));
    fail_unless(cometd_current_transport(g_instance) == NULL);
    fail_unless(cometd_conn_client_id(conn) == NULL);

    int code = cometd_process_handshake(g_instance, n);

    fail_unless(code == ECOMETD_NO_TRANSPORT);
    fail_unless(cometd_conn_is_state(conn, COMETD_UNINITIALIZED));
    fail_unless(cometd_current_transport(g_instance) == NULL);
    fail_unless(cometd_conn_client_id(conn) == NULL);
    fail_if(cometd_conn_advice(conn) == NULL);

    json_node_free(n);
}
Esempio n. 6
0
JsonNode*
cometd_msg_connect_new(const cometd* h) {
    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, COMETD_CHANNEL_META_CONNECT);
    json_object_set_string_member(obj, "connectionType",         connection_type);
    json_object_set_string_member(obj, "clientId",               cometd_conn_client_id(h->conn));

    json_node_take_object(root, obj);

    return root;
}