示例#1
0
文件: time.c 项目: LuaDist/lua-apr
int lua_apr_time_format(lua_State *L)
{
  char formatted[1024];
  apr_status_t status;
  const char *format;

  luaL_checktype(L, 1, LUA_TSTRING);
  format = lua_tostring(L, 1);

  if (strcmp(format, "ctime") == 0) {
    status = apr_ctime(formatted, time_check(L, 2));
    if (status != APR_SUCCESS)
      return push_error_status(L, status);
    lua_pushlstring(L, formatted, APR_CTIME_LEN - 1);
    return 1;
  } else if (strcmp(format, "rfc822") == 0) {
    status = apr_rfc822_date(formatted, time_check(L, 2));
    if (status != APR_SUCCESS)
      return push_error_status(L, status);
    lua_pushlstring(L, formatted, APR_RFC822_DATE_LEN - 1);
    return 1;
  } else {
    apr_time_exp_t components = { 0 };
    apr_size_t length = count(formatted);
    time_check_exploded(L, 2, &components, 1);
    status = apr_strftime(formatted, &length, length, format, &components);
    if (status != APR_SUCCESS)
      return push_error_status(L, status);
    lua_pushlstring(L, formatted, length);
    return 1;
  }
}
示例#2
0
文件: time.c 项目: LuaDist/lua-apr
int lua_apr_time_explode(lua_State *L)
{
  apr_time_exp_t components;
  apr_status_t status;
  apr_time_t time;
  char *field;
  int i;

  time = time_check(L, 1);
  if (!lua_toboolean(L, 2))
    /* Explode the time according to the local timezone by default. */
    status = apr_time_exp_lt(&components, time);
  else
    /* Or explode the time according to (an offset from) GMT instead. */
    status = apr_time_exp_tz(&components, time,
        lua_isboolean(L, 2) ? 0 : (apr_int32_t) luaL_checkinteger(L, 2));
  if (status != APR_SUCCESS)
    return push_error_status(L, status);

  /* Copy numeric fields of exploded time to Lua table. */
  lua_createtable(L, 0, count(fields) + 1);
  for (i = 0; i < count(fields); i++) {
    field = (char*)&components + fields[i].byte_offset;
    lua_pushinteger(L, *(apr_int32_t*)field + fields[i].value_offset);
    lua_setfield(L, -2, fields[i].name);
  }

  /* Copy boolean `isdst' field. */
  lua_pushboolean(L, components.tm_isdst);
  lua_setfield(L, -2, "isdst");

  return 1;
}
示例#3
0
文件: io_file.c 项目: LuaDist/lua-apr
int lua_apr_file_mtime_set(lua_State *L)
{
  apr_status_t status;
  const char *path;
  apr_time_t mtime;

  path = luaL_checkstring(L, 1);
  mtime = time_check(L, 2);
  status = apr_file_mtime_set(path, mtime, to_pool(L));

  return push_status(L, status);
}
示例#4
0
文件: ran.cpp 项目: giangnvbk1989/NFV
void* generate_traffic(void *arg) {
	int ue_num;
	bool time_exceeded;
	
	ue_num = *((int*)arg);
	time_exceeded = false;
	while (1) {
		Client to_mme;
		UE ue(ue_num);

		to_mme.bind_client();
		to_mme.fill_server_details(g_mme_port, g_mme_addr);
		to_mme.connect_with_server(ue_num);	
		attach(ue, to_mme);
		send_traffic(ue);
		detach(ue, to_mme);
		time_check(g_start_time, g_req_duration, time_exceeded);
		if (time_exceeded) {
			break;
		}
	}
	return NULL;
}
示例#5
0
int main(int argc, char *argv[])
{
   /*
    * Alloc the global structures
    * We can access these structs via the macro in ec_globals.h
    */
        
   globals_alloc();
  
   GBL_PROGRAM = strdup(EC_PROGRAM);
   GBL_VERSION = strdup(EC_VERSION);
   SAFE_CALLOC(GBL_DEBUG_FILE, strlen(EC_PROGRAM) + strlen("-") + strlen(EC_VERSION) + strlen("_debug.log") + 1, sizeof(char));
   sprintf(GBL_DEBUG_FILE, "%s-%s_debug.log", GBL_PROGRAM, EC_VERSION);
   
   DEBUG_INIT();
   DEBUG_MSG("main -- here we go !!");

   /* initialize the filter mutex */
   filter_init_mutex();
   
   /* register the main thread as "init" */
   ec_thread_register(EC_PTHREAD_SELF, "init", "initialization phase");
   
   /* activate the signal handler */
   signal_handler();
   
   /* ettercap copyright */
   fprintf(stdout, "\n" EC_COLOR_BOLD "%s %s" EC_COLOR_END " copyright %s %s\n\n", 
         GBL_PROGRAM, GBL_VERSION, EC_COPYRIGHT, EC_AUTHORS);
   
   /* getopt related parsing...  */
   parse_options(argc, argv);

   /* check the date */
   time_check();

   /* load the configuration file */
   load_conf();
  
   /* 
    * get the list of available interfaces 
    * 
    * this function will not return if the -I option was
    * specified on command line. it will instead print the
    * list and exit
    */
   capture_getifs();
   
   /* initialize the user interface */
   ui_init();
   
   /* initialize the network subsystem */
   network_init();
   
   /* 
    * always disable the kernel ip forwarding (except when reading from file).
    * the forwarding will be done by ettercap.
    */
   if(!GBL_OPTIONS->read && !GBL_OPTIONS->unoffensive && !GBL_OPTIONS->only_mitm) {
      disable_ip_forward();
	
#ifdef OS_LINUX
      if (!GBL_OPTIONS->read)
      	disable_interface_offload();
#endif
      /* binds ports and set redirect for ssl wrapper */
      if(GBL_SNIFF->type == SM_UNIFIED && GBL_OPTIONS->ssl_mitm)
         ssl_wrap_init();
   }
   
   /* 
    * drop root privileges 
    * we have already opened the sockets with high privileges
    * we don't need anymore root privs.
    */
   drop_privs();

/***** !! NO PRIVS AFTER THIS POINT !! *****/

   /* load all the plugins */
   plugin_load_all();

   /* print how many dissectors were loaded */
   conf_dissectors();
   
   /* load the mac-fingerprints */
   manuf_init();

   /* load the tcp-fingerprints */
   fingerprint_init();
   
   /* load the services names */
   services_init();
   
   /* load http known fileds for user/pass */
   http_fields_init();

#ifdef HAVE_EC_LUA
   /* Initialize lua */
   ec_lua_init();
#endif

   /* set the encoding for the UTF-8 visualization */
   set_utf8_encoding((u_char*)GBL_CONF->utf8_encoding);
  
   /* print all the buffered messages */
   if (GBL_UI->type == UI_TEXT)
      USER_MSG("\n");
   
   ui_msg_flush(MSG_ALL);

/**** INITIALIZATION PHASE TERMINATED ****/
   
   /* 
    * we are interested only in the mitm attack i
    * if entered, this function will not return...
    */
   if (GBL_OPTIONS->only_mitm)
      only_mitm();
   
   /* create the dispatcher thread */
   ec_thread_new("top_half", "dispatching module", &top_half, NULL);

   /* this thread becomes the UI then displays it */
   ec_thread_register(EC_PTHREAD_SELF, GBL_PROGRAM, "the user interface");
   ui_start();

/******************************************** 
 * reached only when the UI is shutted down 
 ********************************************/

   /* Call all the proper stop methods to ensure
    * that no matter what UI was selected, everything is 
    * turned off gracefully */
   clean_exit(0);

   return 0; //Never reaches here
}
void generic_sys_coordinator::on_system_update()
{
	if(m_request_termination)
	{
		return;
	}

	time_check();

	bool result;
	{
		std::lock_guard< std::mutex > guard(m_sys_mutex);
		result = m_sys->update(nullptr);
		m_system_st = result ? SystemState::Active : SystemState::Completed;
	}
	++m_step;

	m_ready_to_display = true;

	auto uinf = m_sys->get_update_info();
	if(uinf.type == rtp::i_system::update_info::Type::Realtime)
	{
		if(m_system_st == SystemState::Completed || (m_step % RenderPeriod == 0))
		{
			update_widgets();
		}

		if(m_system_st == SystemState::Active)
		{
			m_timer.expires_at(m_timer.expires_at() + boost::posix_time::milliseconds(1000.0f / uinf.frequency));
			m_timer.async_wait(boost::bind(&generic_sys_coordinator::on_system_update, this));
		}
		else if(m_finish_cb)
		{
			m_finish_cb();
		}
	}
	else
	{
		if(m_widget->get_drawer()->is_animated())
		{
			auto anim_drawer = static_cast<rtp::animated_system_drawer*>(m_widget->get_drawer());
			anim_drawer->start();

			// Initiate animation sequence
			m_timer.expires_at(m_timer.expires_at() + boost::posix_time::milliseconds(1000.0f / AnimationFreq));
			m_timer.async_wait(boost::bind(&generic_sys_coordinator::on_animation_update, this));
		}
		else if(m_system_st == SystemState::Active)
		{
			m_timer.expires_at(m_timer.expires_at() + boost::posix_time::milliseconds(1000.0f / NonRealtimeFreq));
			m_timer.async_wait(boost::bind(&generic_sys_coordinator::on_system_update, this));
		}
		else if(m_finish_cb)
		{
			m_finish_cb();
		}

		// Draw
		update_widgets();
	}
}
示例#7
0
int main(int argc, const char **argv)
{
	INT t0 = os_ticks();
	INT verbose_level = 0;
	INT xmax = 1000000;
	INT ymax = 1000000;
	INT xmax_out = 1000000;
	INT ymax_out = 1000000;
	INT f_i = FALSE;
	INT f_e = FALSE;
	INT i;
	BYTE fname_base[1000];
	BYTE fname_out[1000];
	BYTE ext[1000];
	INT f_no_circletext = FALSE;
	INT f_circle = FALSE;
	INT f_file = FALSE;
	const BYTE *fname = NULL;
	INT f_on_circle = FALSE;
	INT f_graph = FALSE;
	INT f_rad = FALSE;
	INT rad = 3000;
	INT f_embedded = FALSE;
	INT f_scale = FALSE;
	double scale = .45;
	INT f_line_width = FALSE;
	double line_width = 1.5;
	INT f_placeholder_labels = FALSE;
	INT f_circletext = FALSE;
	INT f_count_leaves = FALSE;

#if 0
	if (argc <= 1) {
		print_usage();
		exit(1);
		}
#endif
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "-v") == 0) {
			verbose_level = atoi(argv[i + 1]);
			cout << "-v " << verbose_level <<endl;
			}
		else if (strcmp(argv[i], "-x") == 0) {
			xmax = atoi(argv[i + 1]);
			i++;
			cout << "-x " << xmax << endl;
			}
		else if (strcmp(argv[i], "-y") == 0) {
			ymax = atoi(argv[i + 1]);
			i++;
			cout << "-y " << ymax << endl;
			}
		else if (strcmp(argv[i], "-x_out") == 0) {
			xmax_out = atoi(argv[i + 1]);
			i++;
			cout << "-x_out " << xmax_out << endl;
			}
		else if (strcmp(argv[i], "-y_out") == 0) {
			ymax_out = atoi(argv[i + 1]);
			i++;
			cout << "-y_out " << ymax_out << endl;
			}
		else if (strcmp(argv[i], "-i") == 0) {
			f_i = TRUE;
			cout << "-i " << endl;
			}
		else if (strcmp(argv[i], "-e") == 0) {
			f_e = TRUE;
			cout << "-e " << endl;
			}
		else if (strcmp(argv[i], "-circletext") == 0) {
			f_circletext = TRUE;
			cout << "-circletext " << endl;
			}
		else if (strcmp(argv[i], "-circle") == 0) {
			f_circle = TRUE;
			cout << "-circle " << endl;
			}
		else if (strcmp(argv[i], "-on_circle") == 0) {
			f_on_circle = TRUE;
			cout << "-on_circle " << endl;
			}
		else if (strcmp(argv[i], "-file") == 0) {
			f_file = TRUE;
			fname = argv[++i];
			cout << "-file " << fname << endl;
			}
		else if (strcmp(argv[i], "-graph") == 0) {
			f_graph = TRUE;
			graph_nb_V = atoi(argv[++i]);
			f_type = TRUE;
			the_type = "as_graph";
			cout << "-graph " << graph_nb_V << endl;
			}
		else if (strcmp(argv[i], "-graph_perm") == 0) {
			f_graph_perm = TRUE;
			graph_nb_V = atoi(argv[++i]);
			INT j;
			for (j = 0; j < graph_nb_V; j++) {
				graph_perm[j] = atoi(argv[++i]);
				}
			cout << "-graph_perm " << graph_nb_V << " ";
			INT_vec_print(cout, graph_perm, graph_nb_V);
			cout << endl;
			}
		else if (strcmp(argv[i], "-rad") == 0) {
			f_rad = TRUE;
			rad = atoi(argv[++i]);
			cout << "-rad " << rad << endl;
			}
		else if (strcmp(argv[i], "-multiple_circles") == 0) {
			f_multiple_circles = TRUE;
			nb_circles = atoi(argv[++i]);
			cout << "-multiple_circles " << nb_circles << endl;
			}
		else if (strcmp(argv[i], "-embedded") == 0) {
			f_embedded = TRUE;
			cout << "-embedded" << endl;
			}
		else if (strcmp(argv[i], "-scale") == 0) {
			f_scale = TRUE;
			sscanf(argv[++i], "%lf", &scale);
			cout << "-scale " << scale << endl;
			}
		else if (strcmp(argv[i], "-line_width") == 0) {
			f_line_width = TRUE;
			sscanf(argv[++i], "%lf", &line_width);
			cout << "-line_width " << line_width << endl;
			}
		else if (strcmp(argv[i], "-placeholder_labels") == 0) {
			f_placeholder_labels = TRUE;
			cout << "-placeholder_labels " << endl;
			}
		else if (strcmp(argv[i], "-count_leaves") == 0) {
			f_count_leaves = TRUE;
			cout << "-count_leaves " << endl;
			}
		}

	if (!f_file) {
		cout << "please use option -file <fname>" << endl;
		exit(1);
		}
	strcpy(fname_base, fname);
	get_extension_if_present(fname_base, ext);
	chop_off_extension_if_present(fname_base, ext);
	sprintf(fname_out, "%s", fname_base);
		
	tree T;

	cout << "Trying to read file " << fname << " of size " << file_size(fname) << endl;

	if (file_size(fname) <= 0) {
		cout << "treedraw.out the input file " << fname << " does not exist" << endl;
		exit(1);
		}
	T.init(fname, xmax, ymax, verbose_level);
	
	if (/* T.nb_nodes > 200 ||*/ f_no_circletext) {
		f_circletext = FALSE;
		}
	if (f_on_circle) {
		T.root->place_on_circle(xmax, ymax, T.max_depth);
		}

	if (f_count_leaves) {
		T.f_count_leaves = TRUE;
		}

	if (f_graph) {
		cout << "treedraw.out drawing as graph" << endl;
		T.draw(fname_out, xmax, ymax, xmax_out, ymax_out, rad, f_circle, f_circletext, 
			f_i, f_e, TRUE, draw_vertex_callback, f_embedded, f_on_circle, 
			scale, line_width);
		}
	else if (f_placeholder_labels) {
		T.draw(fname_out, xmax, ymax, xmax_out, ymax_out, rad, f_circle, f_circletext, 
			f_i, f_e, TRUE, draw_vertex_callback_placeholders, f_embedded, f_on_circle, 
			scale, line_width);
		}
	else {
		T.draw(fname_out, xmax, ymax, xmax_out, ymax_out, rad, f_circle, f_circletext, 
			f_i, f_e, FALSE, NULL, f_embedded, f_on_circle, 
			scale, line_width);
		}
	
	time_check(cout, t0);
	cout << endl;
}