Beispiel #1
0
void compose_json_counters(json_t *obj, struct chained_cache *cc)
{
  if (cc->flow_type != NF9_FTYPE_EVENT && cc->flow_type != NF9_FTYPE_OPTION) {
    json_object_set_new_nocheck(obj, "packets", json_integer((json_int_t)cc->packet_counter));
    json_object_set_new_nocheck(obj, "bytes", json_integer((json_int_t)cc->bytes_counter));
  }
}
static
int dslink_response_send_closed(DSLink *link, json_t *rid) {
    json_t *top = json_object();
    if (!top) {
        return DSLINK_ALLOC_ERR;
    }

    json_t *resps = json_array();
    if (!resps) {
        json_delete(top);
        return DSLINK_ALLOC_ERR;
    }
    json_object_set_new_nocheck(top, "responses", resps);
    json_t *resp = json_object();
    if (!resp) {
        json_delete(top);
        return DSLINK_ALLOC_ERR;
    }
    json_array_append_new(resps, resp);
    json_object_set(resp, "rid", rid);
    json_object_set_new_nocheck(resp, "stream", json_string("closed"));
    dslink_ws_send_obj(link->_ws, top);
    json_delete(top);
    return 0;
}
Beispiel #3
0
void compose_json_src_host_country(json_t *obj, struct chained_cache *cc)
{
  char empty_string[] = "";

  if (strlen(cc->primitives.src_ip_country.str))
    json_object_set_new_nocheck(obj, "country_ip_src", json_string(cc->primitives.src_ip_country.str));
  else
    json_object_set_new_nocheck(obj, "country_ip_src", json_string(empty_string));
}
Beispiel #4
0
void compose_json_dst_host_pocode(json_t *obj, struct chained_cache *cc)
{
  char empty_string[] = "";

  if (strlen(cc->primitives.dst_ip_pocode.str))
    json_object_set_new_nocheck(obj, "pocode_ip_dst", json_string(cc->primitives.dst_ip_pocode.str));
  else
    json_object_set_new_nocheck(obj, "pocode_ip_dst", json_string(empty_string));
}
Beispiel #5
0
void compose_json_tunnel_proto(json_t *obj, struct chained_cache *cc)
{
  char misc_str[VERYSHORTBUFLEN];

  if (!config.num_protos && (cc->ptun->tunnel_proto < protocols_number))
    json_object_set_new_nocheck(obj, "tunnel_ip_proto", json_string(_protocols[cc->ptun->tunnel_proto].name));
  else
    json_object_set_new_nocheck(obj, "tunnel_ip_proto", json_integer((json_int_t)cc->ptun->tunnel_proto));
}
Beispiel #6
0
void compose_json_dst_host_country(json_t *obj, struct chained_cache *cc)
{
  char empty_string[] = "";

  if (cc->primitives.dst_ip_country.id > 0)
    json_object_set_new_nocheck(obj, "country_ip_dst", json_string(GeoIP_code_by_id(cc->primitives.dst_ip_country.id)));
  else
    json_object_set_new_nocheck(obj, "country_ip_dst", json_string(empty_string));
}
Beispiel #7
0
void compose_json_timestamp_stitching(json_t *obj, struct chained_cache *cc)
{
  char tstamp_str[VERYSHORTBUFLEN];

  compose_timestamp(tstamp_str, VERYSHORTBUFLEN, &cc->stitch->timestamp_min, TRUE, config.timestamps_since_epoch);
  json_object_set_new_nocheck(obj, "timestamp_min", json_string(tstamp_str));

  compose_timestamp(tstamp_str, VERYSHORTBUFLEN, &cc->stitch->timestamp_max, TRUE, config.timestamps_since_epoch);
  json_object_set_new_nocheck(obj, "timestamp_max", json_string(tstamp_str));
}
Beispiel #8
0
void *compose_purge_init_json(char *writer_name, pid_t writer_pid)
{
  char event_type[] = "purge_init", wid[SHORTSHORTBUFLEN];
  json_t *obj = json_object();

  json_object_set_new_nocheck(obj, "event_type", json_string(event_type));

  snprintf(wid, SHORTSHORTBUFLEN, "%s/%u", writer_name, writer_pid);
  json_object_set_new_nocheck(obj, "writer_id", json_string(wid));

  return obj;
}
void dslink_response_send_val(DSLink *link,
                              DSNode *node,
                              uint32_t sid) {
    if (!node->value_timestamp) {
        return;
    }

    json_t *top = json_object();
    if (!top) {
        return;
    }

    json_t *resps = json_array();
    if (!resps) {
        json_delete(top);
        return;
    }
    json_object_set_new_nocheck(top, "responses", resps);

    json_t *resp = json_object();
    if (!resp) {
        json_delete(top);
        return;
    }
    json_array_append_new(resps, resp);
    json_object_set_new_nocheck(resp,
                                "rid", json_integer(0));

    json_t *updates = json_array();
    if (!updates) {
        json_delete(top);
        return;
    }
    json_object_set_new_nocheck(resp, "updates", updates);

    json_t *update = json_array();
    if (!update) {
        json_delete(top);
        return;
    }

    json_array_append_new(updates, update);
    json_array_append_new(update, json_integer(sid));
    json_array_append(update, node->value);
    json_array_append(update, node->value_timestamp);

    dslink_ws_send_obj(link->_ws, top);
    json_delete(top);
}
Beispiel #10
0
void compose_json_mpls_vpn_rd(json_t *obj, struct chained_cache *cc)
{
  char rd_str[VERYSHORTBUFLEN];

  bgp_rd2str(rd_str, &cc->pbgp->mpls_vpn_rd);
  json_object_set_new_nocheck(obj, "mpls_vpn_rd", json_string(rd_str));
}
Beispiel #11
0
void compose_json_peer_dst_ip(json_t *obj, struct chained_cache *cc)
{
  char ip_address[INET6_ADDRSTRLEN];

  addr_to_str(ip_address, &cc->pbgp->peer_dst_ip);
  json_object_set_new_nocheck(obj, "peer_ip_dst", json_string(ip_address));
}
Beispiel #12
0
void compose_json_dst_mac(json_t *obj, struct chained_cache *cc)
{
  char mac[18];
  
  etheraddr_string(cc->primitives.eth_dhost, mac);
  json_object_set_new_nocheck(obj, "mac_dst", json_string(mac));
}
Beispiel #13
0
void *compose_purge_close_json(char *writer_name, pid_t writer_pid, int purged_entries, int total_entries, int duration)
{
  char event_type[] = "purge_close", wid[SHORTSHORTBUFLEN];
  json_t *obj = json_object();

  json_object_set_new_nocheck(obj, "event_type", json_string(event_type));

  snprintf(wid, SHORTSHORTBUFLEN, "%s/%u", writer_name, writer_pid);
  json_object_set_new_nocheck(obj, "writer_id", json_string(wid));

  json_object_set_new_nocheck(obj, "purged_entries", json_integer((json_int_t)purged_entries));
  json_object_set_new_nocheck(obj, "total_entries", json_integer((json_int_t)total_entries));
  json_object_set_new_nocheck(obj, "duration", json_integer((json_int_t)duration));

  return obj;
}
Beispiel #14
0
void compose_json_dst_net(json_t *obj, struct chained_cache *cc)
{
  char ip_address[INET6_ADDRSTRLEN];

  addr_to_str(ip_address, &cc->primitives.dst_net);
  json_object_set_new_nocheck(obj, "net_dst", json_string(ip_address));
}
Beispiel #15
0
void compose_json_timestamp_arrival(json_t *obj, struct chained_cache *cc)
{
  char tstamp_str[VERYSHORTBUFLEN];

  compose_timestamp(tstamp_str, VERYSHORTBUFLEN, &cc->pnat->timestamp_arrival, TRUE, config.timestamps_since_epoch);
  json_object_set_new_nocheck(obj, "timestamp_arrival", json_string(tstamp_str));
}
Beispiel #16
0
void compose_json_etype(json_t *obj, struct chained_cache *cc)
{
  char misc_str[VERYSHORTBUFLEN];

  sprintf(misc_str, "%x", cc->primitives.etype);
  json_object_set_new_nocheck(obj, "etype", json_string(misc_str));
}
Beispiel #17
0
void compose_json_tunnel_dst_host(json_t *obj, struct chained_cache *cc)
{
  char ip_address[INET6_ADDRSTRLEN];

  addr_to_str(ip_address, &cc->ptun->tunnel_dst_ip);
  json_object_set_new_nocheck(obj, "tunnel_ip_dst", json_string(ip_address));
}
Beispiel #18
0
void compose_json_post_nat_src_host(json_t *obj, struct chained_cache *cc)
{
  char ip_address[INET6_ADDRSTRLEN];

  addr_to_str(ip_address, &cc->pnat->post_nat_src_ip);
  json_object_set_new_nocheck(obj, "post_nat_ip_src", json_string(ip_address));
}
Beispiel #19
0
void compose_json_tcp_flags(json_t *obj, struct chained_cache *cc)
{
  char misc_str[VERYSHORTBUFLEN];

  sprintf(misc_str, "%u", cc->tcp_flags);
  json_object_set_new_nocheck(obj, "tcp_flags", json_string(misc_str));
}
Beispiel #20
0
void ConnectionInstance::sendError(int error) {
    string outstr("ERR ");
    json_t* topnode = json_object();
    json_object_set_new_nocheck(topnode, "number",
            json_integer(error)
            );
    json_object_set_new_nocheck(topnode, "message",
            json_string_nocheck(LuaConstants::getErrorMessage(error).c_str())
            );
    const char* errstr = json_dumps(topnode, JSON_COMPACT);
    outstr += errstr;
    MessagePtr message(MessageBuffer::FromString(outstr));
    send(message);
    free((void*) errstr);
    json_decref(topnode);
    DLOG(INFO) << "Sending error to connection: " << outstr;
}
Beispiel #21
0
void compose_json_history(json_t *obj, struct chained_cache *cc)
{
  if (cc->basetime.tv_sec) {
    char tstamp_str[VERYSHORTBUFLEN];
    struct timeval tv;

    tv.tv_sec = cc->basetime.tv_sec;
    tv.tv_usec = 0;
    compose_timestamp(tstamp_str, VERYSHORTBUFLEN, &tv, FALSE, config.timestamps_since_epoch);
    json_object_set_new_nocheck(obj, "stamp_inserted", json_string(tstamp_str));

    tv.tv_sec = time(NULL);
    tv.tv_usec = 0;
    compose_timestamp(tstamp_str, VERYSHORTBUFLEN, &tv, FALSE, config.timestamps_since_epoch);
    json_object_set_new_nocheck(obj, "stamp_updated", json_string(tstamp_str));
  }
}
Beispiel #22
0
void ConnectionInstance::sendError(int error, string message) {
    string outstr("ERR ");
    json_t* topnode = json_object();
    json_object_set_new_nocheck(topnode, "number",
            json_integer(error)
            );
    json_t* messagenode = json_string(message.c_str());
    if (!messagenode)
        messagenode = json_string_nocheck("There was an error encoding this error message. Please report this to Kira.");
    json_object_set_new_nocheck(topnode, "message", messagenode);
    const char* errstr = json_dumps(topnode, JSON_COMPACT);
    outstr += errstr;
    MessagePtr outMessage(MessageBuffer::FromString(outstr));
    send(outMessage);
    free((void*) errstr);
    json_decref(topnode);
    DLOG(INFO) << "Sending custom error to connection: " << outstr;
}
Beispiel #23
0
void compose_json_label(json_t *obj, struct chained_cache *cc)
{
  char empty_string[] = "", *str_ptr;

  vlen_prims_get(cc->pvlen, COUNT_INT_LABEL, &str_ptr);
  if (!str_ptr) str_ptr = empty_string;

  json_object_set_new_nocheck(obj, "label", json_string(str_ptr));
}
Beispiel #24
0
int json_object_set_new(json_t *json, const char *key, json_t *value)
{
    if(!key || !utf8_check_string(key, -1))
    {
        json_decref(value);
        return -1;
    }

    return json_object_set_new_nocheck(json, key, value);
}
Beispiel #25
0
void compose_json_ndpi_class(json_t *obj, struct chained_cache *cc)
{
  char ndpi_class[SUPERSHORTBUFLEN];
  struct pkt_primitives *pbase = &cc->primitives;

  snprintf(ndpi_class, SUPERSHORTBUFLEN, "%s/%s",
	ndpi_get_proto_name(pm_ndpi_wfl->ndpi_struct, pbase->ndpi_class.master_protocol),
	ndpi_get_proto_name(pm_ndpi_wfl->ndpi_struct, pbase->ndpi_class.app_protocol));

  json_object_set_new_nocheck(obj, "class", json_string(ndpi_class));
}
Beispiel #26
0
void ServerState::saveChannels() {
    DLOG(INFO) << "Saving channels.";
    json_t* root = json_object();
    json_t* publicarray = json_array();
    json_t* privatearray = json_array();
    for (chanptrmap_t::const_iterator i = channelMap.begin(); i != channelMap.end(); ++i) {
        ChannelPtr chan = i->second;
        if (chan->getType() == CT_PUBLIC) {
            json_array_append_new(publicarray, chan->saveChannel());
        } else if (chan->getType() == CT_PUBPRIVATE) {
            json_array_append_new(privatearray, chan->saveChannel());
        }
    }
    json_object_set_new_nocheck(root, "public", publicarray);
    json_object_set_new_nocheck(root, "private", privatearray);
    const char* chanstr = json_dumps(root, JSON_INDENT(4));
    string contents = chanstr;
    free((void*) chanstr);
    json_decref(root);
    fsaveFile("./channels.json", contents);
}
Beispiel #27
0
static
void send_invoke_request(DownstreamNode *node,
                         json_t *req,
                         uint32_t rid,
                         const char *path,
                         PermissionLevel maxPermission) {
    json_t *top = json_object();
    json_t *reqs = json_array();
    json_object_set_new_nocheck(top, "requests", reqs);
    json_array_append(reqs, req);

    json_object_set_new_nocheck(req, "rid", json_integer(rid));
    json_object_set_new_nocheck(req, "path", json_string_nocheck(path));
    if (maxPermission < PERMISSION_CONFIG) {
        json_object_set_new_nocheck(req, "permit",
                                    json_string_nocheck(permission_level_str(maxPermission)));
    }

    broker_ws_send_obj(node->link, top);
    json_decref(top);
}
Beispiel #28
0
void compose_json_custom_primitives(json_t *obj, struct chained_cache *cc)
{
  char empty_string[] = "";
  int cp_idx;

  for (cp_idx = 0; cp_idx < config.cpptrs.num; cp_idx++) {
    if (config.cpptrs.primitive[cp_idx].ptr->len != PM_VARIABLE_LENGTH) {
      char cp_str[VERYSHORTBUFLEN];

      custom_primitive_value_print(cp_str, VERYSHORTBUFLEN, cc->pcust, &config.cpptrs.primitive[cp_idx], FALSE);
      json_object_set_new_nocheck(obj, config.cpptrs.primitive[cp_idx].name, json_string(cp_str));
    }
    else {
      char *label_ptr = NULL;

      vlen_prims_get(cc->pvlen, config.cpptrs.primitive[cp_idx].ptr->type, &label_ptr);
      if (!label_ptr) label_ptr = empty_string;
      json_object_set_new_nocheck(obj, config.cpptrs.primitive[cp_idx].name, json_string(label_ptr));
    }
  }
}
Beispiel #29
0
/**
 * @param  search   The search result
 */
static void get_search(sp_search *search)
{
        int i;
        json_t *json = json_object();

        json_t *tracks = json_array();
        json_object_set_new(json, "tracks", tracks);
        for (i = 0; i < sp_search_num_tracks(search); ++i){
            json_array_append_new(tracks, get_track(sp_search_track(search, i)));
        }
        json_object_set_new_nocheck(json, "query", json_string_nocheck(sp_search_query(search)));
        cmd_sendresponse(json, 200);
}
Beispiel #30
0
void ConnectionInstance::sendDebugReply(string message) {
    string outstr("ZZZ ");
    json_t* topnode = json_object();
    json_t* messagenode = json_string(message.c_str());
    if (!messagenode)
        messagenode = json_string_nocheck("Failed to parse the debug reply as a valid UTF-8 string.");
    json_object_set_new_nocheck(topnode, "message", messagenode);
    const char* replystr = json_dumps(topnode, JSON_COMPACT);
    outstr += replystr;
    free((void*) replystr);
    json_decref(topnode);
    MessagePtr outMessage(MessageBuffer::FromString(outstr));
    send(outMessage);
}