Exemple #1
0
static char *
album_list(struct req *self)
{
	return query_list(
		self->db,
		"SELECT DISTINCT album FROM music");
}
Exemple #2
0
void on_add_log::on_request(const ioremap::swarm::network_request &/*req*/,
                            const boost::asio::const_buffer &buffer)
{
	try {
		std::string request(boost::asio::buffer_cast<const char*>(buffer),
		                    boost::asio::buffer_size(buffer));
		ioremap::swarm::network_query_list query_list(request);

		if(!query_list.has_item(consts::USER_ITEM) ||
		   !query_list.has_item(consts::DATA_ITEM) ||
		   (!query_list.has_item(consts::TIME_ITEM) &&
		    !query_list.has_item(consts::KEY_ITEM)))
			throw std::invalid_argument("user, data, time or key");

		if(query_list.has_item(consts::KEY_ITEM)) {
			get_server()
			->get_provider()
			->add_log(query_list.item_value(consts::USER_ITEM),
			          query_list.item_value(consts::KEY_ITEM),
			          ioremap::elliptics::data_pointer::copy(query_list.item_value(consts::DATA_ITEM)),
			          std::bind(&on_add_log::on_finish,
			                    shared_from_this(),
			                    std::placeholders::_1));
		}
		else if(query_list.has_item("time")) {
			get_server()
			->get_provider()
			->add_log(query_list.item_value(consts::USER_ITEM),
			          boost::lexical_cast<uint64_t>(query_list.item_value(consts::TIME_ITEM)),
			          ioremap::elliptics::data_pointer::copy(query_list.item_value(consts::DATA_ITEM)),
			          std::bind(&on_add_log::on_finish,
			                    shared_from_this(),
			                    std::placeholders::_1));
		}
		else
			throw std::invalid_argument("Key and time are missed");
	}
	catch(ioremap::elliptics::error&) {
		get_reply()->send_error(ioremap::swarm::network_reply::internal_server_error);
	}
	catch(...) {
		get_reply()->send_error(ioremap::swarm::network_reply::bad_request);
	}
}
Exemple #3
0
int
main (int argc, char **argv)
{
  int status = 0;
  int i;
  char *filename = NULL;

  progname = argv[0];

  bufsiz = resolv_number (BGPDUMP_BUFSIZ_DEFAULT, NULL);
  nroutes = resolv_number (ROUTE_LIMIT_DEFAULT, NULL);

  status = bgpdump_getopt (argc, argv);

  argc -= optind;
  argv += optind;

  if (status)
    return status;

  if (argc == 0)
    {
      printf ("specify rib files.\n");
      usage ();
      exit (-1);
    }

  if (verbose)
    {
      printf ("bufsiz = %llu\n", bufsiz);
      printf ("nroutes = %llu\n", nroutes);
    }

  /* default cmd */
  if (! brief && ! show && ! route_count && ! plen_dist && ! udiff &&
      ! lookup && ! peer_table_only && ! stat && ! compat_mode &&
      ! autsiz && ! heatmap)
    show++;

  if (stat)
    peer_stat_init ();

  char *buf;
  buf = malloc (bufsiz);
  if (! buf)
    {
      printf ("can't malloc %lluB-size buf: %s\n",
              bufsiz, strerror (errno));
      exit (-1);
    }

  peer_table_init ();

  if (peer_spec_size)
    {
      for (i = 0; i < peer_spec_size; i++)
        {
          peer_route_table[i] = route_table_create ();
          peer_route_size[i] = 0;
          peer_ptree[i] = ptree_create ();
        }
    }

  if (lookup)
    {
      route_init ();
      ptree[AF_INET] = ptree_create ();
      ptree[AF_INET6] = ptree_create ();
    }

  if (udiff)
    {
      diff_table[0] = malloc (nroutes * sizeof (struct bgp_route));
      diff_table[1] = malloc (nroutes * sizeof (struct bgp_route));
      assert (diff_table[0] && diff_table[1]);
      memset (diff_table[0], 0, nroutes * sizeof (struct bgp_route));
      memset (diff_table[1], 0, nroutes * sizeof (struct bgp_route));

      if (udiff_lookup)
        {
          diff_ptree[0] = ptree_create ();
          diff_ptree[1] = ptree_create ();
        }
    }

  /* for each rib files. */
  for (i = 0; i < argc; i++)
    {
      filename = argv[i];

      file_format_t format;
      struct access_method *method;
      void *file;
      size_t ret;

      format = get_file_format (filename);
      method = get_access_method (format);
      file = method->fopen (filename, "r");
      if (! file)
        {
          fprintf (stderr, "# could not open file: %s\n", filename);
          continue;
        }

      size_t datalen = 0;

      while (1)
        {
          ret = method->fread (buf + datalen, bufsiz - datalen, 1, file);
          if (debug)
            printf ("read: %lu bytes to buf[%lu]. total %lu bytes\n",
                    ret, datalen, ret + datalen);
          datalen += ret;

          /* end of file. */
          if (ret == 0 && method->feof (file))
            {
              if (debug)
                printf ("read: end-of-file.\n");
              break;
            }

          bgpdump_process (buf, &datalen);

          if (debug)
            printf ("process rest: %lu bytes\n", datalen);
        }

      if (datalen)
        {
          printf ("warning: %lu bytes unprocessed data remains: %s\n",
                  datalen, filename);
        }
      method->fclose (file);

      /* For each end of the processing of files. */
      if (route_count)
        {
          peer_route_count_show ();
          peer_route_count_clear ();
        }

      if (plen_dist)
        {
          peer_route_count_by_plen_show ();
          peer_route_count_by_plen_clear ();
        }
    }

  /* query_table construction. */
  if (lookup)
    {
      query_limit = 0;

      if (lookup_file)
        query_limit = query_file_count (lookup_file);

      if (lookup_addr)
        query_limit++;

      query_init ();

      if (lookup_addr)
        query_addr (lookup_addr);

      if (lookup_file)
        query_file (lookup_file);

      if (debug)
        query_list ();
    }

  /* query to route_table (ptree). */
  if (lookup)
    {
      if (benchmark)
        benchmark_start ();

      if (peer_spec_size)
        {
          for (i = 0; i < peer_spec_size; i++)
            {
              printf ("peer %d:\n", peer_spec_index[i]);
              if (verbose)
                ptree_list (peer_ptree[i]);
              ptree_query (peer_ptree[i], query_table, query_size);
            }
        }
      else
        {
          if (verbose)
            ptree_list (ptree[qaf]);
          ptree_query (ptree[qaf], query_table, query_size);
        }

      if (benchmark)
        {
          benchmark_stop ();
          benchmark_print (query_size);
        }
    }

  if (heatmap)
    {
      for (i = 0; i < peer_spec_size; i++)
        {
          heatmap_image_hilbert_gplot (i);
          heatmap_image_hilbert_data (i);
          //heatmap_image_hilbert_data_aspath_max_distance (i);
        }
    }

  if (lookup)
    {
      free (query_table);
      ptree_delete (ptree[AF_INET]);
      ptree_delete (ptree[AF_INET6]);
      route_finish ();
    }

  if (udiff)
    {
      free (diff_table[0]);
      free (diff_table[1]);

      if (lookup)
        {
          ptree_delete (diff_ptree[0]);
          ptree_delete (diff_ptree[1]);
        }
    }

  if (stat)
    {
      peer_stat_show ();
      //peer_stat_finish ();
    }

  free (buf);

  return status;
}