Beispiel #1
0
void ZnpActorPublishDeviceLqi(WORD nAddress, BYTE nLqi)
{
	PDEVICEINFO pDevice;
	if (pZnpActor == NULL) return;
	pDevice = DeviceFind(nAddress);
	if (pDevice == NULL) return;
	json_t* eventJson = json_object();
	json_t* paramsJson = json_object();
	char* macIdString = IeeeToString(pDevice->IeeeAddr);
	json_t* macIdJson = json_string(macIdString);
	json_t* lqiJson = NULL;
	free(macIdString);
	json_t* protocolJson = json_string("zigbee");
	if (nLqi > LQI_LIMIT)
		lqiJson = json_integer(1);
	else
		lqiJson = json_integer(0);
	json_object_set(paramsJson, "macId", macIdJson);
	json_object_set(paramsJson, "protocol", protocolJson);
	json_object_set(paramsJson, "signal_strength", lqiJson);
	json_object_set(eventJson, "params", paramsJson);
	char* eventMessage = json_dumps(eventJson, JSON_INDENT(4) | JSON_REAL_PRECISION(4));
	//char* topicName = ActorMakeTopicName(pZnpActor->guid, "/:event/device_signal");
	char* topicName = ActorMakeTopicName("event/", pZnpActor->guid, "/device_signal");
	ActorSend(pZnpActor, topicName, eventMessage, NULL, FALSE, topicName);
	json_decref(lqiJson);
	json_decref(protocolJson);
	json_decref(macIdJson);
	json_decref(paramsJson);
	json_decref(eventJson);
	free(topicName);
	free(eventMessage);
}
Beispiel #2
0
void ZnpActorPublishEndpointAddedEvent(IEEEADDRESS macId, BYTE endpoint, WORD deviceId, WORD deviceType)
{
	if (pZnpActor == NULL) return;
	json_t* eventJson = json_object();
	json_t* paramsJson = json_object();
	char* eventMessage;
	char* topicName;
	char* macIdString = IeeeToString(macId);
	json_t* macJson = json_string(macIdString);
	free(macIdString);
	json_object_set(paramsJson, "macId", macJson);
	json_decref(macJson);
	char* endpointString = malloc(20);
	sprintf(endpointString, "%d", endpoint);
	json_t* endpointJson = json_string(endpointString);
	free(endpointString);
	json_object_set(paramsJson, "endpoint", endpointJson);
	json_decref(endpointJson);
	json_t* deviceClassJson;
	deviceClassJson = DevDesMakeDeviceClassJson(deviceId, deviceType);
	json_object_set(paramsJson, "class", deviceClassJson);
	json_decref(deviceClassJson);
	json_t* protocolJson = json_string("zigbee");
	json_object_set(paramsJson, "protocol", protocolJson);
	json_decref(protocolJson);
	json_object_set(eventJson, "params", paramsJson);
	json_decref(paramsJson);
	eventMessage = json_dumps(eventJson, JSON_INDENT(4) | JSON_REAL_PRECISION(4));
	json_decref(eventJson);
	//topicName = ActorMakeTopicName(pZnpActor->guid, "/:event/endpoint_added");
	topicName = ActorMakeTopicName("event/", pZnpActor->guid, "/endpoint_added");
	ActorSend(pZnpActor, topicName, eventMessage, NULL, FALSE, topicName);
	free(eventMessage);
	free(topicName);
}
Beispiel #3
0
void ZnpActorPublishDeviceErrorEvent(IEEEADDRESS macId, WORD error)
{
	if (pZnpActor == NULL) return;
	json_t* eventJson = json_object();
	json_t* paramsJson = json_object();
	char* macIdString = IeeeToString(macId);
	json_t* macIdJson = json_string(macIdString);
	free(macIdString);
	json_t* protocolJson = json_string("zigbee");
	char* errorMessage = malloc(50);
	sprintf(errorMessage, "%s%d","error.actor.", error);
	json_t* errorJson = json_string(errorMessage);
	free(errorMessage);
	json_object_set(paramsJson, "macId", macIdJson);
	json_object_set(paramsJson, "protocol", protocolJson);
	json_object_set(paramsJson, "error", errorJson);
	json_object_set(eventJson, "params", paramsJson);
	char* eventMessage = json_dumps(eventJson, JSON_INDENT(4) | JSON_REAL_PRECISION(4));
	//char* topicName = ActorMakeTopicName(pZnpActor->guid, "/:event/device_error");
	char* topicName = ActorMakeTopicName("event/", pZnpActor->guid, "/device_error");
	ActorSend(pZnpActor, topicName, eventMessage, NULL, FALSE, topicName);
	json_decref(errorJson);
	json_decref(protocolJson);
	json_decref(macIdJson);
	json_decref(paramsJson);
	json_decref(eventJson);
	free(topicName);
	free(eventMessage);
}
Beispiel #4
0
int janus_websockets_send_message(void *transport, void *request_id, gboolean admin, json_t *message) {
	if(message == NULL)
		return -1;
	if(transport == NULL) {
		g_free(message);
		return -1;
	}
	/* Make sure this is not related to a closed /freed WebSocket session */
	janus_mutex_lock(&old_wss_mutex);
	janus_websockets_client *client = (janus_websockets_client *)transport;
	if(g_list_find(old_wss, client) != NULL) {
		g_free(message);
		message = NULL;
		transport = NULL;
	} else if(!client->context || !client->wsi) {
		g_free(message);
		message = NULL;
	}
	if(message == NULL) {
		janus_mutex_unlock(&old_wss_mutex);
		return -1;
	}
	janus_mutex_lock(&client->mutex);
	/* Convert to string and enqueue */
	char *payload = json_dumps(message, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
	g_async_queue_push(client->messages, payload);
	libwebsocket_callback_on_writable(client->context, client->wsi);
	janus_mutex_unlock(&client->mutex);
	janus_mutex_unlock(&old_wss_mutex);
	json_decref(message);
	return 0;
}
Beispiel #5
0
/* encode_json : encode the exnode in the JSON format n dump it in string
 * dir : directory name
 * parent_id : parent directory id
 * return : JSON dump of exnode
 *
 */
char *encode_json(const char *dir, const char *parent_id){
	
	if(dir == NULL){
		fprintf(stderr, "Invalid directory name \n");
		return NULL;
	}
	
	// create json object
	json_t *json_exnode = json_object();
	json_object_set(json_exnode, "name", json_string(dir));
	json_object_set(json_exnode, "created", json_integer(time(NULL)));
	json_object_set(json_exnode, "modified", json_integer(time(NULL)));
	json_object_set(json_exnode, "mode", json_string("directory"));
	json_object_set(json_exnode, "size", json_integer(0));

	if (parent_id == NULL) {
	  json_object_set(json_exnode, "parent", json_null());
	}
	else {
	  json_t *pobj = json_object();
	  json_object_set(pobj, "href", json_string(parent_id));
	  json_object_set(pobj, "rel", json_string("full"));
	  json_object_set(json_exnode, "parent", pobj);
	}
	
	return json_dumps(json_exnode, JSON_INDENT(1));
}
Beispiel #6
0
bool w_state_save(void)
{
  json_t *state;
  w_jbuffer_t buffer;
  int fd = -1;
  char tmpname[WATCHMAN_NAME_MAX];
  bool result = false;

  if (dont_save_state) {
    return true;
  }

  pthread_mutex_lock(&state_lock);

  state = json_object();

  if (!w_json_buffer_init(&buffer)) {
    w_log(W_LOG_ERR, "save_state: failed to init json buffer\n");
    goto out;
  }

  snprintf(tmpname, sizeof(tmpname), "%sXXXXXX",
      watchman_state_file);
  fd = w_mkstemp(tmpname);
  if (fd == -1) {
    w_log(W_LOG_ERR, "save_state: unable to create temporary file: %s\n",
        strerror(errno));
    goto out;
  }

  json_object_set_new(state, "version", json_string(PACKAGE_VERSION));

  /* now ask the different subsystems to fill out the state */
  if (!w_root_save_state(state)) {
    goto out;
  }

  /* we've prepared what we're going to save, so write it out */
  w_json_buffer_write(&buffer, fd, state, JSON_INDENT(4));

  /* atomically replace the old contents */
  result = rename(tmpname, watchman_state_file) == 0;

out:
  if (state) {
    json_decref(state);
  }
  w_json_buffer_free(&buffer);
  if (fd != -1) {
    if (!result) {
      // If we didn't succeed, remove our temporary file
      unlink(tmpname);
    }
    close(fd);
  }

  pthread_mutex_unlock(&state_lock);

  return result;
}
Beispiel #7
0
void ZnpActorPublishDeviceDataEvent(IEEEADDRESS macId, BYTE endPoint, BYTE nDataCount, PZNPACTORDATA *pData)
{
	if (pZnpActor == NULL) return;
	json_t* eventJson = json_object();
	json_t* paramsJson = json_object();
	char* macIdString = IeeeToString(macId);
	json_t* macIdJson = json_string(macIdString);
	free(macIdString);
	char* endpointString = malloc(20);
	sprintf(endpointString, "%d", endPoint);
	json_t* endpointJson = json_string(endpointString);
	free(endpointString);
	json_t* protocolJson = json_string("zigbee");
	json_object_set(paramsJson, "macId", macIdJson);
	json_object_set(paramsJson, "endpoint", endpointJson);
	json_object_set(paramsJson, "protocol", protocolJson);
	json_decref(macIdJson);
	json_decref(endpointJson);
	json_decref(protocolJson);
	json_t* dataJson;
	json_t* valueJson;
	dataJson = json_object();
	BYTE nIndex = 0;
	while (nDataCount > 0)
	{
		switch (pData[nIndex]->nDataType)
		{
		case ZNP_DATA_TYPE_INTERGER:
			valueJson = json_integer((int)(*((int*)(pData[nIndex]->value))));
			break;
		case ZNP_DATA_TYPE_FLOAT:
			valueJson = json_real((double)(*((double*)(pData[nIndex]->value))));
			break;
		case ZNP_DATA_TYPE_STRING:
			valueJson = json_string(pData[nIndex]->value);
			break;
		default:
			json_decref(dataJson);
			json_decref(paramsJson);
			json_decref(eventJson);
			return;
			break;
		}
		json_object_set(dataJson, pData[nIndex]->dataName, valueJson);
		json_decref(valueJson);
		nDataCount--;
		nIndex++;
	}
	json_object_set(paramsJson, "data", dataJson);
	json_decref(dataJson);
	json_object_set(eventJson, "params", paramsJson);
	json_decref(paramsJson);
	char* eventMessage = json_dumps(eventJson, JSON_INDENT(4) | JSON_REAL_PRECISION(4));
	json_decref(eventJson);
	//char* topicName = ActorMakeTopicName(pZnpActor->guid, "/:event/device_data");
	char* topicName = ActorMakeTopicName("event/", pZnpActor->guid, "/device_data");
	ActorSend(pZnpActor, topicName, eventMessage, NULL, FALSE, topicName);
	free(topicName);
	free(eventMessage);
}
Beispiel #8
0
static struct MHD_Response *
send_metric(struct brubeck_server *server, const char *url)
{
    static const char *metric_types[] = {
        "gauge", "meter", "counter", "histogram", "timer", "internal"
    };
    static const char *expire_status[] = {
        "disabled", "inactive", "active"
    };

    struct brubeck_metric *metric = safe_lookup_metric(
                                        server, url + strlen("/metric/"));

    if (metric) {
        json_t *mj = json_pack("{s:s, s:s, s:i, s:s}",
                               "key", metric->key,
                               "type", metric_types[metric->type],
#if METRIC_SHARD_SPECIFIER
                               "shard", (int)metric->shard,
#else
                               "shard", 0,
#endif
                               "expire", expire_status[metric->expire]
                              );

        char *jsonr = json_dumps(mj, JSON_INDENT(4) | JSON_PRESERVE_ORDER);
        json_decref(mj);
        return MHD_create_response_from_data(
                   strlen(jsonr), jsonr, 1, 0);
    }

    return NULL;
}
void janus_echotest_hangup_media(janus_plugin_session *handle) {
	JANUS_LOG(LOG_INFO, "No WebRTC media anymore\n");
	if(stopping || !initialized)
		return;
	janus_echotest_session *session = (janus_echotest_session *)handle->plugin_handle;
	if(!session) {
		JANUS_LOG(LOG_ERR, "No session associated with this handle...\n");
		return;
	}
	if(session->destroyed)
		return;
	/* Send an event to the browser and tell it's over */
	json_t *event = json_object();
	json_object_set_new(event, "echotest", json_string("event"));
	json_object_set_new(event, "result", json_string("done"));
	char *event_text = json_dumps(event, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
	json_decref(event);
	JANUS_LOG(LOG_VERB, "Pushing event: %s\n", event_text);
	int ret = gateway->push_event(handle, &janus_echotest_plugin, NULL, event_text, NULL, NULL);
	JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
	g_free(event_text);
	/* Reset controls */
	session->audio_active = TRUE;
	session->video_active = TRUE;
	session->bitrate = 0;
}
void SubmitContext::submitBlock(blktemplate_t *blockTemplate,
                                const PrimecoinBlockHeader &header,
                                unsigned dataId)
{
  json_t *jsonBlock =
    blkmk_submit_jansson(blockTemplate,
                         (unsigned char*)&header,
                         dataId,
                         __builtin_bswap32(header.nonce),
                         header.multiplier,
                         header.multiplier[0]+1);
  char *request = json_dumps(jsonBlock, JSON_INDENT(2));
  json_delete(jsonBlock);
  
  _response.clear();
  logFormattedWrite(_log, "submit request: %s", request);
  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, request);
  if (curl_easy_perform(curl) != CURLE_OK) {
    logFormattedWrite(_log, "block send error!!!");
  } else {
    logFormattedWrite(_log, "response: %s");
  }
  
  free(request);
}
Beispiel #11
0
static
void
cd_JSONRequest (struct evhttp_request* request, CDServer* server)
{
    struct evbuffer* buffer = evhttp_request_get_input_buffer(request);
    char*            text   = CD_alloc(evbuffer_get_length(buffer) + 1);

    evbuffer_remove(buffer, text, evbuffer_get_length(buffer));

    json_error_t error;
    json_t*      input  = json_loads(text, 0, &error);
    json_t*      output = json_object();

    printf("%s\n", text);

    if (evhttp_request_get_command(request) != EVHTTP_REQ_POST) {
        goto error;
    }

    if (input == NULL) {
        SERR(server, "RPC.JSON: error on line %d: %s", error.line, error.text);

        goto error;
    }

    CD_EventDispatch(server, "RPC.JSON", input, output);

done: {
        char*            outString = json_dumps(output, JSON_INDENT(2));
        struct evbuffer* outBuffer = evbuffer_new();

        evbuffer_add_printf(outBuffer, "%s", outString);

        evhttp_send_reply(request, HTTP_OK, "OK", outBuffer);

        evbuffer_free(outBuffer);
        free(outString);
        json_delete(output);
        json_delete(input);
        CD_free(text);

        return;
    }

error: {
        evhttp_send_error(request, HTTP_INTERNAL, "Internal server error");

        CD_free(text);

        if (input) {
            json_delete(input);
        }

        if (output) {
            json_delete(output);
        }

        return;
    }
}
Beispiel #12
0
void on_list_update(struct DSLink *link, ref_t *req_ref, json_t *resp) {
    (void) link;
    RequestHolder *holder = req_ref->data;

    json_t *updates = json_object_get(resp, "updates");
    size_t index;
    json_t *value;

    const char* path = json_string_value(json_object_get(holder->req, "path"));

    printf("======= List %s =======\n", path);
    json_array_foreach(updates, index, value) {
        json_t *name = json_array_get(value, 0);
        json_t *val = json_array_get(value, 1);

        if (val->type == JSON_ARRAY || val->type == JSON_OBJECT) {
            char *data = json_dumps(val, JSON_INDENT(0));
            printf("%s = %s\n", json_string_value(name), data);
            dslink_free(data);
        } else if (val->type == JSON_STRING) {
            printf("%s = %s\n", json_string_value(name), json_string_value(val));
        } else if (val->type == JSON_INTEGER) {
            printf("%s = %lli\n", json_string_value(name), json_integer_value(val));
        } else if (val->type == JSON_REAL) {
            printf("%s = %f\n", json_string_value(name), json_real_value(val));
        } else if (val->type == JSON_NULL) {
            printf("%s = NULL\n", json_string_value(name));
        } else if (val->type == JSON_TRUE) {
            printf("%s = true\n", json_string_value(name));
        } else if (val->type == JSON_FALSE) {
            printf("%s = false\n", json_string_value(name));
        } else {
            printf("%s = (Unknown Type)\n", json_string_value(name));
        }
    }
Beispiel #13
0
void saveRevenueMovements(char * save_path)
{
    json_t * json_revenue = json_object();
    
    json_t * array = json_array();

    json_t * json_total = json_real(total);
    
    for (struct revenue * revenue = firstRevenueMovement; revenue!=0; revenue=revenue->next)
    {
        json_array_append(array, createRevenueArray(revenue));
    }
    
    int i  = json_object_set(json_revenue, "total", json_total);
    
    int j  = json_object_set(json_revenue, "revenue", array);
    
    if (i == -1 || j == -1)
    {
        printf("errore non è possibile scrivere il file");
    }
    
    json_dump_file(json_revenue, strcat(save_path, "/revenue.json"), JSON_INDENT(3));
    
}
Beispiel #14
0
static int send_metric(struct mg_connection *conn)
{
	static const char *metric_types[] = {
		"gauge", "meter", "counter", "histogram", "timer", "internal"
	};
	static const char *expire_status[] = {
		"disabled", "inactive", "active"
	};

	struct brubeck_server *server = conn->server_param;
	struct brubeck_metric *metric = safe_lookup_metric(
			server, conn->uri + strlen("/metric/"));

	if (metric) {
		json_t *mj = json_pack("{s:s, s:s, s:i, s:s}",
			"key", metric->key,
			"type", metric_types[metric->type],
#if METRIC_SHARD_SPECIFIER
			"shard", (int)metric->shard,
#else
			"shard", 0,
#endif
			"expire", expire_status[metric->expire]
		);

		send_headers(conn);
		json_dump_callback(mj, &dump_json, (void *)conn,
				JSON_INDENT(4) | JSON_PRESERVE_ORDER);
		json_decref(mj);
		return MG_TRUE;
	}

	return MG_FALSE;
}
Beispiel #15
0
char *janus_serial_query_session(janus_plugin_session *handle) {
	if(g_atomic_int_get(&stopping) || !g_atomic_int_get(&initialized)) {
		return NULL;
	}	
	janus_serial_session *session = (janus_serial_session *)handle->plugin_handle;
	if(!session) {
		JANUS_LOG(LOG_ERR, "No session associated with this handle...\n");
		return NULL;
	}
	/* In the echo test, every session is the same: we just provide some configure info */
	json_t *info = json_object();
	json_object_set_new(info, "audio_active", json_string(session->audio_active ? "true" : "false"));
	json_object_set_new(info, "video_active", json_string(session->video_active ? "true" : "false"));
	json_object_set_new(info, "bitrate", json_integer(session->bitrate));
	if(session->arc || session->vrc) {
		json_t *recording = json_object();
		if(session->arc && session->arc->filename)
			json_object_set_new(recording, "audio", json_string(session->arc->filename));
		if(session->vrc && session->vrc->filename)
			json_object_set_new(recording, "video", json_string(session->vrc->filename));
		json_object_set_new(info, "recording", recording);
	}
	json_object_set_new(info, "slowlink_count", json_integer(session->slowlink_count));
	json_object_set_new(info, "destroyed", json_integer(session->destroyed));
	char *info_text = json_dumps(info, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
	json_decref(info);
	return info_text;
}
void janus_streaming_setup_media(janus_plugin_session *handle) {
	JANUS_LOG(LOG_INFO, "WebRTC media is now available\n");
	if(stopping || !initialized)
		return;
	janus_streaming_session *session = (janus_streaming_session *)handle->plugin_handle;	
	if(!session) {
		JANUS_LOG(LOG_ERR, "No session associated with this handle...\n");
		return;
	}
	if(session->destroy)
		return;
	/* TODO Only start streaming when we get this event */
	session->started = TRUE;
	/* Prepare JSON event */
	json_t *event = json_object();
	json_object_set_new(event, "streaming", json_string("event"));
	json_t *result = json_object();
	json_object_set_new(result, "status", json_string("started"));
	json_object_set(event, "result", result);
	char *event_text = json_dumps(event, JSON_INDENT(3));
	json_decref(event);
	json_decref(result);
	JANUS_LOG(LOG_VERB, "Pushing event: %s\n", event_text);
	int ret = gateway->push_event(handle, &janus_streaming_plugin, NULL, event_text, NULL, NULL);
	JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
	g_free(event_text);
}
Beispiel #17
0
char *janus_videocall_query_session(janus_plugin_session *handle) {
	if(g_atomic_int_get(&stopping) || !g_atomic_int_get(&initialized)) {
		return NULL;
	}	
	janus_videocall_session *session = (janus_videocall_session *)handle->plugin_handle;
	if(!session) {
		JANUS_LOG(LOG_ERR, "No session associated with this handle...\n");
		return NULL;
	}
	/* Provide some generic info, e.g., if we're in a call and with whom */
	json_t *info = json_object();
	json_object_set_new(info, "state", json_string(session->peer ? "incall" : "idle"));
	json_object_set_new(info, "username", session->username ? json_string(session->username) : NULL);
	if(session->peer) {
		json_object_set_new(info, "peer", session->peer->username ? json_string(session->peer->username) : NULL);
		json_object_set_new(info, "audio_active", json_string(session->audio_active ? "true" : "false"));
		json_object_set_new(info, "video_active", json_string(session->video_active ? "true" : "false"));
		json_object_set_new(info, "bitrate", json_integer(session->bitrate));
		json_object_set_new(info, "slowlink_count", json_integer(session->slowlink_count));
	}
	json_object_set_new(info, "destroyed", json_integer(session->destroyed));
	char *info_text = json_dumps(info, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
	json_decref(info);
	return info_text;
}
Beispiel #18
0
bool print_config_schema_json(POOL_MEM &buffer)
{
   RES_TABLE *resources = my_config->m_resources;

   initialize_json();

   json_t *json = json_object();
   json_object_set_new(json, "format-version", json_integer(2));
   json_object_set_new(json, "component", json_string("bconsole"));
   json_object_set_new(json, "version", json_string(VERSION));

   /*
    * Resources
    */
   json_t *resource = json_object();
   json_object_set(json, "resource", resource);
   json_t *bconsole = json_object();
   json_object_set(resource, "bconsole", bconsole);

   for (int r = 0; resources[r].name; r++) {
      RES_TABLE resource = my_config->m_resources[r];
      json_object_set(bconsole, resource.name, json_items(resource.items));
   }

   pm_strcat(buffer, json_dumps(json, JSON_INDENT(2)));
   json_decref(json);

   return true;
}
Beispiel #19
0
void on_invoke_updates(struct DSLink *link, ref_t *req_ref, json_t *resp) {
    (void) link;
    (void) req_ref;
    char *data = json_dumps(resp, JSON_INDENT(2));
    printf("Got invoke %s\n", data);
    dslink_free(data);
}
void janus_videocall_hangup_media(janus_plugin_session *handle) {
	JANUS_LOG(LOG_INFO, "No WebRTC media anymore\n");
	if(stopping || !initialized)
		return;
	janus_videocall_session *session = (janus_videocall_session *)handle->plugin_handle;	
	if(!session) {
		JANUS_LOG(LOG_ERR, "No session associated with this handle...\n");
		return;
	}
	if(session->destroy)
		return;
	janus_mutex_lock(&sessions_mutex);
	if(session->peer) {
		/* Send event to our peer too */
		json_t *call = json_object();
		json_object_set_new(call, "videocall", json_string("event"));
		json_t *calling = json_object();
		json_object_set_new(calling, "event", json_string("hangup"));
		json_object_set_new(calling, "username", json_string(session->username));
		json_object_set_new(calling, "reason", json_string("Remote hangup"));
		json_object_set_new(call, "result", calling);
		char *call_text = json_dumps(call, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
		json_decref(call);
		JANUS_LOG(LOG_VERB, "Pushing event to peer: %s\n", call_text);
		int ret = gateway->push_event(session->peer->handle, &janus_videocall_plugin, NULL, call_text, NULL, NULL);
		JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
		g_free(call_text);
	}
	session->peer = NULL;
	/* Reset controls */
	session->audio_active = TRUE;
	session->video_active = TRUE;
	session->bitrate = 0;
	janus_mutex_unlock(&sessions_mutex);
}
Beispiel #21
0
// formats a json to string
int json_format_string(json_t *json, char **string)
{
  char *string_return = NULL;

  int exit_code = 0;

  check_not_null(json);
  check_not_null(string);

  string_return = json_dumps(json, JSON_INDENT(2) | JSON_PRESERVE_ORDER);
  check_not_null(string_return);

  *string = string_return;

  goto cleanup;

error:

  if (string_return != NULL) { free(string_return); }

  exit_code = -1;

cleanup:

  return exit_code;
}
void janus_source_send_id_error(janus_plugin_session *handle) {
	if (g_atomic_int_get(&stopping) || !g_atomic_int_get(&initialized))
		return;
	
	janus_source_session *session = (janus_source_session *)handle->plugin_handle;
	if (!session) {
		JANUS_LOG(LOG_ERR, "No session associated with this handle...\n");
		return;
	}
	
	if (session->destroyed)
		return;

	/* Send an event to the browser and tell it's over */
	char *error_cause = g_malloc0(512);
	g_snprintf(error_cause, 512, "JSON error: URL ID %s already exist in the system.",session->id);
	json_t *event = json_object();
	json_object_set_new(event, "source", json_string("event"));
	json_object_set_new(event, "error_code", json_integer(JANUS_SOURCE_ERROR_INVALID_URL_ID));
	json_object_set_new(event, "error", json_string(error_cause));
	char *event_text = json_dumps(event, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
	json_decref(event);
	JANUS_LOG(LOG_VERB, "Pushing event: %s\n", event_text);
	int ret = gateway->push_event(handle, &janus_source_plugin, NULL, event, NULL);
	JANUS_LOG(LOG_VERB, "  >> %d (%s)\n", ret, janus_get_api_error(ret));
	g_free(event_text);	
}
Beispiel #23
0
int main(void)
{
  json_t *json = json_object();

  int zbxVersion = json_object_set(json, "jsonrpc", json_string("2.0"));
  if (zbxVersion != 0)
    return -1;
  
  int zbxMethod = json_object_set(json, "method", json_string("user.login"));
  if (zbxMethod != 0)
    return -1;   

  json_t *uidParams = json_pack("{s:s, s:s}", "user", "jreed", "password", "Flight8152LA");
  int zbxParams = json_object_set(json, "params", uidParams);
  if (zbxParams != 0)
    return -1; 

  int zbxId = json_object_set(json, "id", json_integer((json_int_t)1));
  if (zbxId != 0)
    return -1;
  
  size_t jsonFLAGS = JSON_INDENT(4) | JSON_PRESERVE_ORDER ;
  puts(json_dumps(json,jsonFLAGS));
  
  return 0;
}
Beispiel #24
0
void CreateJSONMaxFeatureVector(double * MaxFeatureVector,const int bins,char * filename)
{
    json_t* corr = json_object();
    json_t* jsonFileName = json_string("MaxFeatureVector");
    json_t* featureVector = json_array();
    json_t* vectorVals;
    int i;

    // Build feature vector json array
    for (i=0; i<bins; i++)
    {
        vectorVals = json_real(MaxFeatureVector[i]);
        if (json_array_append_new(featureVector,vectorVals))
        {
            printf("Cannot append %f to json array",MaxFeatureVector[i]);
            puts(strerror(errno));
            exit(1);
        }
    }
    // add both feature vector and file name to json object
    json_object_set_new(corr,"FileName",jsonFileName);
    json_object_set_new(corr,"FeatureVector",featureVector);

    json_dump_file(corr,filename,JSON_INDENT(2));


    // need to call jansson specific free
    json_object_clear(corr);

}
Beispiel #25
0
int _rsIESClientHints(
    rsComm_t*    _comm,
    bytesBuf_t** _bbuf ) {
    if( ! _comm ) {
        return SYS_INVALID_INPUT_PARAM;
            
    }

    json_t* ies_hints = json_object();
    if ( !ies_hints ) {
        rodsLog(
            LOG_ERROR,
            "failed to allocate json_object" );
        return SYS_MALLOC_ERR;
    }

    std::string acls;
    irods::error ret = get_strict_acls(
                           _comm,
                           acls );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
    }

    json_object_set( 
        ies_hints, 
        "strict_acls", 
        json_string( acls.c_str() ) );

    json_t* query_arr = 0;
    ret = get_query_array( _comm, query_arr );
    if ( !ret.ok() ) {
        irods::log( PASS( ret ) );
    }
    json_object_set( 
        ies_hints, 
        "specific_queries", 
        query_arr );

    char* tmp_buf = json_dumps( ies_hints, JSON_INDENT( 4 ) );

    // *SHOULD* free All The Things...
    json_decref( ies_hints );

    ( *_bbuf ) = ( bytesBuf_t* ) malloc( sizeof( bytesBuf_t ) );
    if ( !( *_bbuf ) ) {
        rodsLog(
            LOG_ERROR,
            "_rsIESClientHints: failed to allocate _bbuf" );
        return SYS_MALLOC_ERR;

    }

    ( *_bbuf )->buf = tmp_buf;
    ( *_bbuf )->len = strlen( tmp_buf );

    return 0;

} // _rsIESClientHints
Beispiel #26
0
void event(void) {
    json_t* object;
    json_t* array_text_list;
    json_t* array_events;

    object = json_object();

    array_events = json_array();
    json_object_set(object, "events", array_events);
    json_decref(array_events);

    for (int f = 0; f < 58; f++) {
        const TableInfo* event_info;

        event_info = &table_info_event[f];

        std::string filename = "Extracted/" + std::string(event_info->filename);

        Event event(filename.c_str(), event_info->name, event_info->offset,
                    event_info->length);

        json_t* object_event;
        json_t* json_value;

        object_event = json_object();
        json_array_append(array_events, object_event);

        json_value = json_string(event_info->name);
        json_object_set(object_event, "name", json_value);
        json_decref(json_value);

        json_value = json_string(event_info->filename);
        json_object_set(object_event, "filename", json_value);
        json_decref(json_value);

        json_value = json_integer(event_info->offset);
        json_object_set(object_event, "offset", json_value);
        json_decref(json_value);

        json_value = json_integer(event_info->length);
        json_object_set(object_event, "length", json_value);
        json_decref(json_value);

        array_text_list = json_array();
        json_object_set(object_event, "text_list", array_text_list);
        json_decref(array_text_list);

        for (std::vector<Text*>::iterator tt = event.text_data()->begin();
             tt != event.text_data()->end(); tt++) {
            Text2JSON t2json(*(*tt), array_text_list);

            t2json.output();
        }
    }

    json_dump_file(object, "event.json", JSON_INDENT(0) | JSON_PRESERVE_ORDER);
    json_decref(object);
}
void janus_videocall_slow_link(janus_plugin_session *handle, int uplink, int video) {
	/* The core is informing us that our peer got or sent too many NACKs, are we pushing media too hard? */
	if(handle == NULL || handle->stopped || g_atomic_int_get(&stopping) || !g_atomic_int_get(&initialized))
		return;
	janus_videocall_session *session = (janus_videocall_session *)handle->plugin_handle;	
	if(!session) {
		JANUS_LOG(LOG_ERR, "No session associated with this handle...\n");
		return;
	}
	if(session->destroyed)
		return;
	session->slowlink_count++;
	if(uplink && !video && !session->audio_active) {
		/* We're not relaying audio and the peer is expecting it, so NACKs are normal */
		JANUS_LOG(LOG_VERB, "Getting a lot of NACKs (slow uplink) for audio, but that's expected, a configure disabled the audio forwarding\n");
	} else if(uplink && video && !session->video_active) {
		/* We're not relaying video and the peer is expecting it, so NACKs are normal */
		JANUS_LOG(LOG_VERB, "Getting a lot of NACKs (slow uplink) for video, but that's expected, a configure disabled the video forwarding\n");
	} else {
		/* Slow uplink or downlink, maybe we set the bitrate cap too high? */
		if(video) {
			/* Halve the bitrate, but don't go too low... */
			if(!uplink) {
				/* Downlink issue, user has trouble sending, halve this user's bitrate cap */
				session->bitrate = session->bitrate > 0 ? session->bitrate : 512*1024;
				session->bitrate = session->bitrate/2;
				if(session->bitrate < 64*1024)
					session->bitrate = 64*1024;
			} else {
				/* Uplink issue, user has trouble receiving, halve this user's peer's bitrate cap */
				if(session->peer == NULL || session->peer->handle == NULL)
					return;	/* Nothing to do */
				session->peer->bitrate = session->peer->bitrate > 0 ? session->peer->bitrate : 512*1024;
				session->peer->bitrate = session->peer->bitrate/2;
				if(session->peer->bitrate < 64*1024)
					session->peer->bitrate = 64*1024;
			}
			JANUS_LOG(LOG_WARN, "Getting a lot of NACKs (slow %s) for %s, forcing a lower REMB: %"SCNu64"\n",
				uplink ? "uplink" : "downlink", video ? "video" : "audio", uplink ? session->peer->bitrate : session->bitrate);
			/* ... and send a new REMB back */
			char rtcpbuf[24];
			janus_rtcp_remb((char *)(&rtcpbuf), 24, uplink ? session->peer->bitrate : session->bitrate);
			gateway->relay_rtcp(uplink ? session->peer->handle : handle, 1, rtcpbuf, 24);
			/* As a last thing, notify the affected user about this */
			json_t *event = json_object();
			json_object_set_new(event, "videocall", json_string("event"));
			json_t *result = json_object();
			json_object_set_new(result, "status", json_string("slow_link"));
			json_object_set_new(result, "bitrate", json_integer(uplink ? session->peer->bitrate : session->bitrate));
			json_object_set_new(event, "result", result);
			char *event_text = json_dumps(event, JSON_INDENT(3) | JSON_PRESERVE_ORDER);
			json_decref(event);
			event = NULL;
			gateway->push_event(uplink ? session->peer->handle : handle, &janus_videocall_plugin, NULL, event_text, NULL, NULL);
			g_free(event_text);
		}
	}
}
Beispiel #28
0
/* encode a tpl (kv frame) as json. */
void *enc_worker(void *thread_id) {
  char buf[MAX_BUF], *key, *val;
  json_t *o = json_object();
  int rc=-1, len, nc;
  tpl_node *tn;

  while (CF.shutdown == 0) {
    len = nn_recv(CF.ingress_socket_pull, buf, MAX_BUF, 0);
    if (len < 0) {
      fprintf(stderr,"nn_recv: %s\n", nn_strerror(errno));
      goto done;
    }
    /* decode, then re-encode as json */
    json_object_clear(o);
    tn = tpl_map("A(ss)",&key,&val); assert(tn);
    if (tpl_load(tn,TPL_MEM,buf,len) < 0) goto done;
    while(tpl_unpack(tn,1) > 0) {
      json_t *jval = json_string(val);
      json_object_set_new(o, key, jval); 
      free(key); key=NULL;
      free(val); val=NULL;
    }
    tpl_free(tn);

    /* dump the json object, then newline-terminate it. */
    if (CF.verbose>1) json_dumpf(o, stderr, JSON_INDENT(1));
    char *dump = json_dumps(o, JSON_INDENT(0));
    size_t dump_len = strlen(dump);

    /* give the buffer to nano, from here it goes to kaf thread */
    nc = nn_send(CF.egress_socket_push, dump, dump_len, 0);
    free(dump);
    if (nc < 0) {
      fprintf(stderr,"nn_send: %s\n", nn_strerror(errno));
      goto done;
    }
  }

  rc = 0;

 done:
  CF.shutdown = 1;
  json_decref(o);
  return NULL;
}
Beispiel #29
0
void print_json_stream(json_t *json, FILE *stream) {
    char *json_str = json_dumps(json, JSON_INDENT(0));
    if (json_str) {
        fprintf(stream, "%s\n", json_str);
        free(json_str);
    }

    return;
}
Beispiel #30
0
void LSCompiler::processExecutableConfig(AssemblyBuilder *ab)
{
    lmAssert(loomConfigJSON, "loomConfigJSON not initialized");

    utHashTable<utHashedString, utString> defs;

    for (UTsize i = 0; i < LSLuaState::getNumCommandlineArgs(); i++)
    {
        const char *arg = LSLuaState::getCommandlineArg(i).c_str();

        if ((strlen(arg) >= 3) && (arg[0] == '-') && (arg[1] == 'D'))
        {
            char key[1024];
            char value[1024];

            lmAssert(strlen(arg) < 1023, "argument buffer overflow");

            key[0] = value[0] = 0;

            strcpy(key, &arg[2]);

            if (strstr(arg, "="))
            {
                key[strstr(arg, "=") - arg - 2] = 0;
                strcpy(value, strstr(arg, "=") + 1);
            }

            // value defaults to true
            if (!value[0])
            {
                sprintf(value, "true");
            }

            defs.insert(key, value);
        }
    }

    // Add command line defines to config

    json_t *json = json_deep_copy(loomConfigJSON);

    utHashTable<utHashedString, utString>::Iterator itr = defs.iterator();

    while (itr.hasMoreElements())
    {
        const char *key   = itr.peekNextKey().str().c_str();
        const char *value = itr.peekNextValue().c_str();

        json_object_set_new(json, key, json_string(value));

        itr.next();
    }

    const char *out = json_dumps(json, JSON_INDENT(3) | JSON_COMPACT);

    ab->setLoomConfig(out);
}