Пример #1
0
t_player	*add_player(t_player *player, int left, int right, char *name)
{
  t_player	*node;
  t_player	*tmp;

  if (player == NULL)
    {
      if ((player = malloc(sizeof(t_player))) == NULL)
	return (NULL);
      if ((player->name = my_strdup(name)) == NULL)
	return (NULL);
      player = init_moto(player);
      player = init_keys(player, left, right);
      player->next = NULL;
      return (player);
    }
  tmp = player;
  if ((node = malloc(sizeof(*node))) == NULL)
    return (NULL);
  if ((node->name = my_strdup(name)) == NULL)
    return (NULL);
  node = init_moto(node);
  node = init_keys(node, left, right);
  while (tmp && tmp->next)
    tmp = tmp->next;
  tmp->next = node;
  node->next = NULL;
  return (player);
}
Пример #2
0
GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env,
		gui::IGUIElement* parent, s32 id, IMenuManager *menumgr) :
	GUIModalMenu(env, parent, id, menumgr)
{
	activeKey = -1;
	init_keys();
}
Пример #3
0
char		*line_edition(char **env)
{
  int		(*keys_actions[15])(void);
  int		ret;

  if (isatty(0) == 0)
    return (get_next_line(0));
  if ((g_line = malloc(sizeof(t_line))) == NULL)
    return (print_and_return_ptr(NULL, "Allocation error.\n"));
  if ((ret = get_termcaps(env) == 1) || ret == -1 || (set_termcaps(1) == -1))
    return (get_next_line(0));
  g_line->pos = 0;
  g_line->cmd = NULL;
  signal(SIGINT, &free_line);
  init_actions(keys_actions);
  init_keys();
  ret = loop_keys(keys_actions);
  if (set_termcaps(0) == -1)
    return (NULL);
  if (ret == 0)
    {
      if (line_ret() == -1)
	return (NULL);
      return (g_line->cmd);
    }
  return (NULL);
}
Пример #4
0
    void CamaraLucida::init( 
            string config_path, Depthmap* depthmap )
    {
        this->depthmap = depthmap; 
        this->config_path = config_path;

        xml.loadFile(config_path);
        xml.pushTag("camaralucida");

        int dxoff = xml.getValue("depth_xoff", -8); 

        init_keys(); 
        init_events();

        config = new Config( &xml );

        Calibration calib( config ); 

        proj = new OpticalDevice( calib.proj_config() );
        depth = new cml::Kinect( calib.depth_config(), dxoff );
        rgb = new OpticalDevice( calib.rgb_config() );

        mesh = new Mesh( 
                config->mesh_step, 
                depth->width(), depth->height(),
                config->tex_width, config->tex_height );

        renderer = new Renderer(config, proj, depth, rgb);

        depthmap->init( depth, mesh );

        _debug = false;
        _render_help = false;
    };
Пример #5
0
	void CamaraLucida::init_cml(string kinect_calibration_filename,
								string proj_calibration_filename,
								string xml_config_filename)
	{
		_inited = true;
		
		xml_config.loadFile(xml_config_filename);
		xml_config.pushTag("camaralucida");
		
		calib.near = xml_config.getValue("near", 0.1);
		calib.far = xml_config.getValue("far", 20.0);
		
		load_data(kinect_calibration_filename, proj_calibration_filename);
		
		proj_loc = ofVec3f(	proj_RT[12], proj_RT[13], proj_RT[14] );	
		proj_fwd = ofVec3f(	proj_RT[8], proj_RT[9], proj_RT[10] );
		proj_up = ofVec3f( proj_RT[4], proj_RT[5], proj_RT[6] );
		proj_trg = proj_loc + proj_fwd;
		
		rgb_loc = ofVec3f( rgb_RT[12], rgb_RT[13], rgb_RT[14] );	
		rgb_fwd = ofVec3f( rgb_RT[8], rgb_RT[9], rgb_RT[10] );
		rgb_up = ofVec3f( rgb_RT[4], rgb_RT[5], rgb_RT[6] );
		rgb_trg = rgb_loc + rgb_fwd;
		
		init_keys();
		init_events();
		init_gl_scene_control();
	}
Пример #6
0
void svndump_init(const char *filename)
{
	buffer_init(filename);
	repo_init();
	reset_dump_ctx(~0);
	reset_rev_ctx(0);
	reset_node_ctx(NULL);
	init_keys();
}
Пример #7
0
GUISettingsMenu::GUISettingsMenu(
	gui::IGUIEnvironment* env,
	gui::IGUIElement*
	parent,
	s32 id,
	IMenuManager *menumgr,
	bool is_ingame
):
	GUIModalMenu(env, parent, id, menumgr),
	m_accepted(false),
	m_is_ingame(is_ingame)
{
	activeKey = -1;
	init_keys();
	m_data.fancy_trees = g_settings->getBool("new_style_leaves");
	m_data.smooth_lighting = g_settings->getBool("smooth_lighting");
	m_data.clouds_3d = g_settings->getBool("enable_3d_clouds");
	m_data.opaque_water = g_settings->getBool("opaque_water");
	m_data.fullscreen = g_settings->getBool("fullscreen");
	m_data.particles = g_settings->getBool("enable_particles");
	m_data.mip_map = g_settings->getBool("mip_map");
	m_data.anisotropic_filter = g_settings->getBool("anisotropic_filter");
	m_data.bilinear_filter = g_settings->getBool("bilinear_filter");
	m_data.trilinear_filter = g_settings->getBool("trilinear_filter");
	m_data.hotbar = g_settings->getBool("old_hotbar");
	m_data.wield_index = g_settings->getBool("enable_wieldindex");
	m_data.volume = g_settings->getFloat("sound_volume");

	keynames[VLKC_FORWARD] = wgettext("Forward");
	keynames[VLKC_BACKWARD] = wgettext("Backward");
	keynames[VLKC_LEFT] = wgettext("Left");
	keynames[VLKC_RIGHT] = wgettext("Right");
	keynames[VLKC_JUMP] = wgettext("Jump");
	keynames[VLKC_SNEAK] = wgettext("Sneak");
	keynames[VLKC_INVENTORY] = wgettext("Inventory");
	keynames[VLKC_USE] = wgettext("Use Item");
	keynames[VLKC_CHAT] = wgettext("Chat");
	keynames[VLKC_COMMAND] = wgettext("Command");
	keynames[VLKC_RANGE] = wgettext("Range Select");
	keynames[VLKC_FREEMOVE] = wgettext("Toggle Fly");
	keynames[VLKC_UP] = wgettext("Up");
	keynames[VLKC_DOWN] = wgettext("Down");
	keynames[VLKC_RUN] = wgettext("Run");
	keynames[VLKC_EXAMINE] = wgettext("Examine/Open");
	keynames[VLKC_SCREENSHOT] = wgettext("Take Screenshot");
	keynames[VLKC_TOGGLE_HUD] = wgettext("Show/Hide HUD");
	keynames[VLKC_TOGGLE_CHAT] = wgettext("Show/Hide Chat");
	keynames[VLKC_TOGGLE_FOG] = wgettext("Toggle Fog");
	keynames[VLKC_TOGGLE_CAMERA] = NULL;
	keynames[VLKC_TOGGLE_DEBUG] = NULL;
	keynames[VLKC_TOGGLE_PROFILER] = NULL;
	keynames[VLKC_RANGE_PLUS] = wgettext("Increase Viewing Range");
	keynames[VLKC_RANGE_MINUS] = wgettext("Decrease Viewing Range");
	keynames[VLKC_PRINT_DEBUG] = NULL;
	keynames[VLKC_SELECT_PREV] = wgettext("Previous Item");
	keynames[VLKC_SELECT_NEXT] = wgettext("Next Item");
}
Пример #8
0
GUIKeyChangeMenu::GUIKeyChangeMenu(gui::IGUIEnvironment* env,
				gui::IGUIElement* parent, s32 id, IMenuManager *menumgr) :
GUIModalMenu(env, parent, id, menumgr)
{
	shift_down = false;
	activeKey = -1;
	this->key_used_text = NULL;
	init_keys();
	for(size_t i=0; i<key_settings.size(); i++)
		this->key_used.push_back(key_settings.at(i)->key);
}
Пример #9
0
SETUP()
{
	static int mode_flags[] = {
		MF_USES_REGS | MF_USES_COUNT,
		MF_USES_INPUT,
		MF_USES_COUNT
	};

	init_keys(MODES_COUNT, mode_flags);
	vle_mode_set(NORMAL_MODE, VMT_PRIMARY);
	init_builtin_keys();
}
Пример #10
0
void
init_modes(void)
{
	LOG_FUNC_ENTER;

	int i;

	init_keys(MODES_COUNT, (int*)&mode_flags);

	for(i = 0; i < MODES_COUNT; ++i)
	{
		mode_init_funcs[i]();
	}
}
Пример #11
0
int	events(t_game *game)
{
  view(game);
  draw_mini_map(game);
  mlx_put_image_to_window(game->window->mlx_ptr, game->window->mlx_win,	\
			  game->window->img, 0, 0);
  mlx_put_image_to_window(game->window->mlx_ptr, game->window->mlx_win,\
			  game->window->mini_map, 30, 30);
  init_keys(game);
  mlx_hook(game->window->mlx_win, KeyPress, KeyPressMask, &hook_press, game);
  mlx_hook(game->window->mlx_win, KeyRelease, KeyReleaseMask, &hook_release,\
	   game);
  mlx_loop_hook(game->window->mlx_ptr, &gere_key, game);
  mlx_loop(game->window->mlx_ptr);
}
Пример #12
0
file_t * create_file(char * where, char * filename) {
	file_t * file = malloc(sizeof(file_t));
	file->term = init_term();
	file->buff = init_buff();
	file->modbuff = init_buff();
	file->rend = init_renderer();
	file->path = where;
	file->filename = filename;
	file->size = 0;
	file->is_modal = 0;

	init_keys();
	init_func(file);
	return file;
}
Пример #13
0
static t_env	*init_env(int **map)
{
	t_env *e;

	e = (t_env*)malloc(sizeof(t_env) * 1);
	ft_init_sdl(e);
	ft_create_win_sdl(e, 0, 0);
	e->rend = ft_init_renderer(e);
	e->map = map;
	init_cam(&e->cam);
	init_keys(e);
	load_image(e, "ressources/menu.bmp");
	load_sound(e, "ressources/test.wav");
	return (e);
}
Пример #14
0
int main() {
    srand(44);
    init_keys();

    char *doc = calloc(1, 1);
    size_t doc_len = 0;
    char *line = NULL;
    size_t n = 0;
    while (getline(&line, &n, stdin) != -1) {
    	size_t line_len = strlen(line);
    	doc = realloc(doc, doc_len + line_len);
    	strncpy(doc + doc_len, line, line_len - 1);
    	doc_len += line_len - 1;
    	doc[doc_len] = '\0';
    }
    size_t num_bytes = num_bytes_from_base64(doc_len);
    char *as_bytes = calloc(num_bytes + 1, 1);
    num_bytes = base64_to_bytes(doc, as_bytes, num_bytes);

    char *decrypted = calloc(num_bytes + 1, 1);
    char *encrypted = calloc(num_bytes + 1, 1);
    aes_decrypt(as_bytes, decrypted, num_bytes, "YELLOW SUBMARINE");

    ctr_crypt(decrypted, encrypted, num_bytes, nonce, key);  //  E = C = P ^ K

    char *a = calloc(num_bytes + 1, 1);
    memset(a, 'a', num_bytes);
    memcpy(decrypted, encrypted, num_bytes);
    edit(encrypted, num_bytes, 0, a);  // D = A ^ K; 
    xor(decrypted, encrypted, num_bytes, decrypted);  // D = (A ^ K) ^ (P ^ K) = A ^ P
    xor(decrypted, a, num_bytes, decrypted);  // D = (A ^ P) ^ A = P

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

    free(doc);
    free(as_bytes);
    free(encrypted);
    free(decrypted);
    free(a);
}
Пример #15
0
int main(void)
{
    int done=0;
    srand(time(NULL));
    initXWindows();
    Game game;
    DefineRagdoll(&game);
    init_opengl(&game);
    create_sounds();
    play();
    //declare game object
    init_keys();
    clock_gettime(CLOCK_REALTIME, &timePause);
    clock_gettime(CLOCK_REALTIME, &timeStart);

    //start animation
    while(!done) {
	while(XPending(dpy)) {
	    XEvent e;
	    XNextEvent(dpy, &e);
	    check_mouse(&e, &game);
	    check_resize(&game, &e);
	    done = check_keys(&e);
	}
	clock_gettime(CLOCK_REALTIME, &timeCurrent);
	timeSpan = timeDiff(&timeStart, &timeCurrent);
	timeCopy(&timeStart, &timeCurrent);
	physicsCountdown += timeSpan;
	while(physicsCountdown >= physicsRate) {
	    movement(&game);
	    physicsCountdown -= physicsRate;
	}
	render(&game);
	glXSwapBuffers(dpy, win);
    }
    cleanupXWindows();
    cleanup_fonts();
    return 0;
}
Пример #16
0
void testApp::setup()
{
	ofSetLogLevel(OF_LOG_VERBOSE);
	ofSetWindowPosition(0,0);
	
	init_kinect();
	
	init_keys();
	debug_depth_texture = true;
	
	tex_width = 1024;
	tex_height = 768;
	
	mesh = new cml::Mesh_openni(&depth_generator);
	
	camluc.init(ofToDataPath("camara_lucida/openni_calibration.yml"),
				ofToDataPath("camara_lucida/openni_projector_calibration.yml"),
				ofToDataPath("camara_lucida/camara_lucida_config.xml"),
				mesh, tex_width, tex_height, 1);
	
	ofAddListener(camluc.render_texture, this, &testApp::render_texture);
	ofAddListener(camluc.render_hud, this, &testApp::render_hud);
}
Пример #17
0
int dis_initialize(dis_context_t dis_ctx)
{
	int ret = DIS_RET_SUCCESS;
	dis_metadata_config_t dis_meta_cfg = NULL;


	/* Initialize outputs */
	dis_stdio_init(dis_ctx->cfg.verbosity, dis_ctx->cfg.log_file);

	dis_printf(L_INFO, PROGNAME " by " AUTHOR ", v" VERSION " (compiled for " __OS "/" __ARCH ")\n");
#ifdef VERSION_DBG
	dis_printf(L_INFO, "Compiled version: " VERSION_DBG "\n");
#endif

	if(dis_ctx->cfg.verbosity >= L_DEBUG)
		dis_print_args(dis_ctx);


	/*
	 * Check parameters given
	 */
	if(!dis_ctx->cfg.volume_path)
	{
		dis_printf(L_CRITICAL, "No BitLocker volume path given. Abort.\n");
		dis_destroy(dis_ctx);
		return DIS_RET_ERROR_VOLUME_NOT_GIVEN;
	}



	/* Open the volume as a (big) normal file */
	dis_printf(L_DEBUG, "Trying to open '%s'...\n", dis_ctx->cfg.volume_path);
	dis_ctx->fve_fd = dis_open(dis_ctx->cfg.volume_path, O_RDWR|O_LARGEFILE);
	if(dis_ctx->fve_fd < 0)
	{
		/* Trying to open it in read-only if O_RDWR doesn't work */
		dis_ctx->fve_fd = dis_open(
			dis_ctx->cfg.volume_path,
			O_RDONLY|O_LARGEFILE
		);

		if(dis_ctx->fve_fd < 0)
		{
			dis_printf(
				L_CRITICAL,
				"Failed to open %s: %s\n",
				dis_ctx->cfg.volume_path, strerror(errno)
			);
			dis_destroy(dis_ctx);
			return DIS_RET_ERROR_FILE_OPEN;
		}

		dis_ctx->cfg.flags |= DIS_FLAG_READ_ONLY;
		dis_printf(
			L_WARNING,
			"Failed to open %s for writing. Falling back to read-only.\n",
			dis_ctx->cfg.volume_path
		);
	}

	dis_printf(L_DEBUG, "Opened (fd #%d).\n", dis_ctx->fve_fd);

	dis_ctx->io_data.volume_fd = dis_ctx->fve_fd;

	checkupdate_dis_state(dis_ctx, DIS_STATE_AFTER_OPEN_VOLUME);


	/* To print UTF-32 strings */
	setlocale(LC_ALL, "");

	/*
	 * The metadata configuration is freed when calling dis_metadata_destroy()
	 */
	dis_meta_cfg = dis_metadata_config_new();
	dis_meta_cfg->fve_fd       = dis_ctx->fve_fd;
	dis_meta_cfg->force_block  = dis_ctx->cfg.force_block;
	dis_meta_cfg->offset       = dis_ctx->cfg.offset;
	dis_meta_cfg->init_stop_at = dis_ctx->cfg.init_stop_at;

	dis_ctx->metadata = dis_metadata_new(dis_meta_cfg);
	if(dis_ctx->metadata == NULL)
	{
		dis_printf(L_CRITICAL, "Can't allocate metadata object. Abort.\n");
		dis_destroy(dis_ctx);
		return DIS_RET_ERROR_ALLOC;
	}

	ret = dis_metadata_initialize(dis_ctx->metadata);
	dis_ctx->curr_state = dis_meta_cfg->curr_state;
	if(ret != DIS_RET_SUCCESS)
	{
		/*
		 * If it's less than 0, then it's an error, if not, it's an early
		 * return of this function.
		 */
		if(ret < 0)
			dis_destroy(dis_ctx);
		return ret;
	}


	/*
	 * If the state of the volume is currently decrypted, there's no key to grab
	 */
	if(dis_ctx->metadata->information->curr_state != METADATA_STATE_DECRYPTED)
	{
		/*
		 * Get the keys -- VMK & FVEK -- for dec/encryption operations
		 */
		if((ret = dis_get_access(dis_ctx)) != DIS_RET_SUCCESS)
		{
			/*
			 * If it's less than 0, then it's an error, if not, it's an early
			 * return of this function.
			 */
			if(ret < 0)
			{
				dis_printf(L_CRITICAL, "Unable to grab VMK or FVEK. Abort.\n");
				dis_destroy(dis_ctx);
			}
			return ret;
		}

		/*
		 * Init the crypto structure
		 */
		dis_ctx->io_data.crypt = dis_crypt_new(
			dis_metadata_sector_size(dis_ctx->metadata),
			dis_ctx->metadata->dataset->algorithm
		);

		/*
		 * Init the decrypt keys' contexts
		 */
		if(init_keys(
			dis_metadata_set_dataset(dis_ctx->metadata, NULL),
			dis_ctx->io_data.fvek,
			dis_ctx->io_data.crypt) != DIS_RET_SUCCESS)
		{
			dis_printf(L_CRITICAL, "Can't initialize keys. Abort.\n");
			dis_destroy(dis_ctx);
			return DIS_RET_ERROR_CRYPTO_INIT;
		}
	}


	/*
	 * Fill the dis_iodata_t structure which will be used for encryption &
	 * decryption afterward
	 */
	if((ret = prepare_crypt(dis_ctx)) != DIS_RET_SUCCESS)
		dis_printf(L_CRITICAL, "Can't prepare the crypt structure. Abort.\n");


	// TODO add the DIS_STATE_BEFORE_DECRYPTION_CHECKING event here, so add the check here too


	/* Don't do the check for each and every enc/decryption operation */
	dis_ctx->io_data.volume_state = TRUE;

	int look_state = dis_ctx->cfg.flags & DIS_FLAG_DONT_CHECK_VOLUME_STATE;
	if(look_state == 0 &&
		!check_state(dis_ctx->metadata))
	{
		dis_ctx->io_data.volume_state = FALSE;
		ret = DIS_RET_ERROR_VOLUME_STATE_NOT_SAFE;
	}

	/* Clean everything before returning if there's an error */
	if(ret != DIS_RET_SUCCESS)
		dis_destroy(dis_ctx);
	else
		dis_ctx->curr_state = DIS_STATE_COMPLETE_EVERYTHING;

	return ret;
}
Пример #18
0
/*
  Open for reading data the current file in the zipfile.
  If there is no error and the file is opened, the return value is UNZ_OK.
*/
int ZEXPORT unzOpenCurrentFile3 (
    unzFile file,
    int* method,
    int* level,
    int raw,
    const char* password)
{
    int err=UNZ_OK;
    uInt iSizeVar;
    unz_s* s;
    file_in_zip_read_info_s* pfile_in_zip_read_info;
    uLong offset_local_extrafield;  /* offset of the local extra field */
    uInt  size_local_extrafield;    /* size of the local extra field */
#    ifndef NOUNCRYPT
    char source[12];
#    else
    if (password != NULL)
        return UNZ_PARAMERROR;
#    endif

    if (file==NULL)
        return UNZ_PARAMERROR;
    s=(unz_s*)file;
    if (!s->current_file_ok)
        return UNZ_PARAMERROR;

    if (s->pfile_in_zip_read != NULL)
        unzCloseCurrentFile(file);

    if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar,
                &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
        return UNZ_BADZIPFILE;

    pfile_in_zip_read_info = (file_in_zip_read_info_s*)
                                        ALLOC(sizeof(file_in_zip_read_info_s));
    if (pfile_in_zip_read_info==NULL)
        return UNZ_INTERNALERROR;

    pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
    pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
    pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
    pfile_in_zip_read_info->pos_local_extrafield=0;
    pfile_in_zip_read_info->raw=raw;

    if (pfile_in_zip_read_info->read_buffer==NULL)
    {
        TRYFREE(pfile_in_zip_read_info);
        return UNZ_INTERNALERROR;
    }

    pfile_in_zip_read_info->stream_initialised=0;

    if (method!=NULL)
        *method = (int)s->cur_file_info.compression_method;

    if (level!=NULL)
    {
        *level = 6;
        switch (s->cur_file_info.flag & 0x06)
        {
          case 6 : *level = 1; break;
          case 4 : *level = 2; break;
          case 2 : *level = 9; break;
        }
    }

    if ((s->cur_file_info.compression_method!=0) &&
        (s->cur_file_info.compression_method!=Z_DEFLATED))
        err=UNZ_BADZIPFILE;

    pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
    pfile_in_zip_read_info->crc32=0;
    pfile_in_zip_read_info->compression_method =
            s->cur_file_info.compression_method;
    pfile_in_zip_read_info->filestream=s->filestream;
    pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
    pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;

    pfile_in_zip_read_info->stream.total_out = 0;

    if ((s->cur_file_info.compression_method==Z_DEFLATED) &&
        (!raw))
    {
      pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
      pfile_in_zip_read_info->stream.zfree = (free_func)0;
      pfile_in_zip_read_info->stream.opaque = (voidpf)0;
      pfile_in_zip_read_info->stream.next_in = (Bytef*)0;
      pfile_in_zip_read_info->stream.avail_in = 0;

      err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
      if (err == Z_OK)
        pfile_in_zip_read_info->stream_initialised=1;
      else
      {
        TRYFREE(pfile_in_zip_read_info);
        return err;
      }
        /* windowBits is passed < 0 to tell that there is no zlib header.
         * Note that in this case inflate *requires* an extra "dummy" byte
         * after the compressed stream in order to complete decompression and
         * return Z_STREAM_END.
         * In unzip, i don't wait absolutely Z_STREAM_END because I known the
         * size of both compressed and uncompressed data
         */
    }
    pfile_in_zip_read_info->rest_read_compressed =
            s->cur_file_info.compressed_size ;
    pfile_in_zip_read_info->rest_read_uncompressed =
            s->cur_file_info.uncompressed_size ;


    pfile_in_zip_read_info->pos_in_zipfile =
            s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
              iSizeVar;

    pfile_in_zip_read_info->stream.avail_in = (uInt)0;

    s->pfile_in_zip_read = pfile_in_zip_read_info;

#    ifndef NOUNCRYPT
    if (password != NULL)
    {
        int i;
        s->pcrc_32_tab = get_crc_table();
        init_keys(password,s->keys,s->pcrc_32_tab);
        if (ZSEEK(s->z_filefunc, s->filestream,
                  s->pfile_in_zip_read->pos_in_zipfile +
                     s->pfile_in_zip_read->byte_before_the_zipfile,
                  SEEK_SET)!=0)
            return UNZ_INTERNALERROR;
        if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12)
            return UNZ_INTERNALERROR;

        for (i = 0; i<12; i++)
            zdecode(s->keys,s->pcrc_32_tab,source[i]);

        s->pfile_in_zip_read->pos_in_zipfile+=12;
        s->encrypted=1;
    }
#    endif


    return UNZ_OK;
}
Пример #19
0
gint scalliontor_start(ScallionTor* stor, gint argc, gchar *argv[]) {
	time_t now = time(NULL);

	update_approx_time(now);
	tor_threads_init();
	init_logging();

	/* tor_init() loses our logging, so set it before AND after */
	scalliontor_setLogging();
	if (tor_init(argc, argv) < 0) {
		return -1;
	}
//	scalliontor_setLogging();

	  /* load the private keys, if we're supposed to have them, and set up the
	   * TLS context. */
	gpointer idkey;
#ifdef SCALLION_NEWIDKEYNAME
	idkey = client_identitykey;
#else
	idkey = identitykey;
#endif
    if (idkey == NULL) {
	  if (init_keys() < 0) {
	    log_err(LD_BUG,"Error initializing keys; exiting");
	    return -1;
	  }
    }

	/* Set up the packed_cell_t memory pool. */
	init_cell_pool();

	/* Set up our buckets */
	connection_bucket_init();
	stats_prev_global_read_bucket = global_read_bucket;
	stats_prev_global_write_bucket = global_write_bucket;

	/* initialize the bootstrap status events to know we're starting up */
	control_event_bootstrap(BOOTSTRAP_STATUS_STARTING, 0);

	if (trusted_dirs_reload_certs()) {
		log_warn(LD_DIR,
			 "Couldn't load all cached v3 certificates. Starting anyway.");
	}
#ifndef SCALLION_NOV2DIR
	if (router_reload_v2_networkstatus()) {
		return -1;
	}
#endif
	if (router_reload_consensus_networkstatus()) {
		return -1;
	}

	/* load the routers file, or assign the defaults. */
	if (router_reload_router_list()) {
		return -1;
	}

	/* load the networkstatuses. (This launches a download for new routers as
	* appropriate.)
	*/
	directory_info_has_arrived(now, 1);

	/* !note that scallion intercepts the cpuworker functionality (rob) */
	if (server_mode(get_options())) {
		/* launch cpuworkers. Need to do this *after* we've read the onion key. */
		cpu_init();
	}

	/* set up once-a-second callback. */
	if (! second_timer) {
//		struct timeval one_second;
//		one_second.tv_sec = 1;
//		one_second.tv_usec = 0;
//
//		second_timer = periodic_timer_new(tor_libevent_get_base(),
//										  &one_second,
//										  second_elapsed_callback,
//										  NULL);
//		tor_assert(second_timer);

		_scalliontor_secondCallback(stor);
	}


#ifdef SCALLION_DOREFILLCALLBACKS
#ifndef USE_BUFFEREVENTS
  if (!refill_timer) {
    int msecs = get_options()->TokenBucketRefillInterval;
//    struct timeval refill_interval;
//
//    refill_interval.tv_sec =  msecs/1000;
//    refill_interval.tv_usec = (msecs%1000)*1000;
//
//    refill_timer = periodic_timer_new(tor_libevent_get_base(),
//                                      &refill_interval,
//                                      refill_callback,
//                                      NULL);
//    tor_assert(refill_timer);
    stor->refillmsecs = msecs;
	_scalliontor_refillCallback(stor);
  }
#endif
#endif

    /* run the startup events */
    scalliontor_notify(stor);

	return 0;
}
Пример #20
0
int main(void)
{
    int8_t byte_str[4];	    // Wird benutzt um hier ein Byte als String abzulegen

    // LCD Display intialisieren
    lcd_init();

    // Startmeldung ausgeben
    show_start_message();

    // Stepper Initialisieren
    init_stepper();

    // Motor Initialisieren
    init_motor();

    // Steursignale BYTE_READY, SYNC und SOE Initialisieren
    init_controll_signals();

    // Schreibschutz setzen
    clear_wps();

    // Timer0 --> GCR senden
    init_timer0();

    // Tasten Initialisieren
    init_keys();

    // Timer2 --> wird alle 1ms aufgerufen
    // z.B. zu Tasten entprellen
    init_timer2();

    // Meldung ausgeben, das auf SD Karte gewartet wird
    lcd_setcursor(0,2);
    lcd_string("Wait for SD-Karte...");

    // SD Karte initialisieren
    // Partition und Filesystem öffnen
    // Warten bis alles O.K. ist
    while(init_sd_card()){}

    lcd_clear();

    view_dir_entry(0,&file_entry);

#ifdef DEBUG_MODE
    lcd_setcursor(0,4);
    lcd_string("T:");

    lcd_setcursor(5,4);
    lcd_string("M:");

    lcd_setcursor(9,4);
    lcd_string("K:");

    lcd_setcursor(2,4);
    sprintf(byte_str,"%d",akt_half_track >> 1);
    lcd_string(byte_str);
#endif

    // Interrupts erlauben
    sei();

    while(1)
    {
	// Auf Steppermotor aktivität prüfen
	// und auswerten

	if(stepper_signal_r_pos != stepper_signal_w_pos)
	{
	    uint8_t stepper = stepper_signal_puffer[stepper_signal_r_pos++]>>2 | stepper_signal_puffer[stepper_signal_r_pos-1];

	    switch(stepper)
	    {
	    case 0x30: case 0x40: case 0x90: case 0xE0:
		// DEC
		stepper_dec();
		    stepper_signal_time = 0;
		    stepper_signal = 1;
		break;

	    case 0x10: case 0x60: case 0xB0: case 0xC0:
		// INC
		stepper_inc();
		    stepper_signal_time = 0;
		    stepper_signal = 1;
		break;
	    }
#ifdef DEBUG_MODE
	    lcd_setcursor(2,4);
	    lcd_string("   ");
	    lcd_setcursor(2,4);
	    sprintf(byte_str,"%d",akt_half_track >> 1);
	    lcd_string(byte_str);
#endif
	}
	else if(stepper_signal && (stepper_signal_time >= STEPPER_DELAY_TIME))
Пример #21
0
void initialise(void)
{
    HTpinsetup();
    HTsetup();
    init_keys();
}
Пример #22
0
/** Based on our interval and our estimated bandwidth, choose a
 * deterministic (but random-ish) time to wake up. */
static void
accounting_set_wakeup_time(void)
{
  char buf[ISO_TIME_LEN+1];
  char digest[DIGEST_LEN];
  crypto_digest_env_t *d_env;
  int time_in_interval;
  uint64_t time_to_exhaust_bw;
  int time_to_consider;

  if (! identity_key_is_set()) {
    if (init_keys() < 0) {
      log_err(LD_BUG, "Error initializing keys");
      tor_assert(0);
    }
  }

  format_iso_time(buf, interval_start_time);
  crypto_pk_get_digest(get_identity_key(), digest);

  d_env = crypto_new_digest_env();
  crypto_digest_add_bytes(d_env, buf, ISO_TIME_LEN);
  crypto_digest_add_bytes(d_env, digest, DIGEST_LEN);
  crypto_digest_get_digest(d_env, digest, DIGEST_LEN);
  crypto_free_digest_env(d_env);

  if (!expected_bandwidth_usage) {
    char buf1[ISO_TIME_LEN+1];
    char buf2[ISO_TIME_LEN+1];
    format_local_iso_time(buf1, interval_start_time);
    format_local_iso_time(buf2, interval_end_time);
    time_to_exhaust_bw = GUESS_TIME_TO_USE_BANDWIDTH;
    interval_wakeup_time = interval_start_time;

    log_notice(LD_ACCT,
           "Configured hibernation.  This interval begins at %s "
           "and ends at %s.  We have no prior estimate for bandwidth, so "
           "we will start out awake and hibernate when we exhaust our quota.",
           buf1, buf2);
    return;
  }

  time_in_interval = (int)(interval_end_time - interval_start_time);

  time_to_exhaust_bw =
    (get_options()->AccountingMax/expected_bandwidth_usage)*60;
  if (time_to_exhaust_bw > TIME_MAX) {
    time_to_exhaust_bw = TIME_MAX;
    time_to_consider = 0;
  } else {
    time_to_consider = time_in_interval - (int)time_to_exhaust_bw;
  }

  if (time_to_consider<=0) {
    interval_wakeup_time = interval_start_time;
  } else {
    /* XXX can we simplify this just by picking a random (non-deterministic)
     * time to be up? If we go down and come up, then we pick a new one. Is
     * that good enough? -RD */

    /* This is not a perfectly unbiased conversion, but it is good enough:
     * in the worst case, the first half of the day is 0.06 percent likelier
     * to be chosen than the last half. */
    interval_wakeup_time = interval_start_time +
      (get_uint32(digest) % time_to_consider);

    format_iso_time(buf, interval_wakeup_time);
  }

  {
    char buf1[ISO_TIME_LEN+1];
    char buf2[ISO_TIME_LEN+1];
    char buf3[ISO_TIME_LEN+1];
    char buf4[ISO_TIME_LEN+1];
    time_t down_time;
    if (interval_wakeup_time+time_to_exhaust_bw > TIME_MAX)
      down_time = TIME_MAX;
    else
      down_time = (time_t)(interval_wakeup_time+time_to_exhaust_bw);
    if (down_time>interval_end_time)
      down_time = interval_end_time;
    format_local_iso_time(buf1, interval_start_time);
    format_local_iso_time(buf2, interval_wakeup_time);
    format_local_iso_time(buf3, down_time);
    format_local_iso_time(buf4, interval_end_time);

    log_notice(LD_ACCT,
           "Configured hibernation.  This interval began at %s; "
           "the scheduled wake-up time %s %s; "
           "we expect%s to exhaust our quota for this interval around %s; "
           "the next interval begins at %s (all times local)",
           buf1,
           time(NULL)<interval_wakeup_time?"is":"was", buf2,
           time(NULL)<down_time?"":"ed", buf3,
           buf4);
  }
}
Пример #23
0
int main(int argc,char *argv[]){
   strcpy(fname,argv[1]);
   FILE *f=fopen(fname,"rb");
   if(read_header(f)){
      char ofname[0x400];
      strcpy(ofname,fname);
      char *ibuf;
      char *obuf;
      ibuf=header_buf+(lrc_offs-9);
      while(*ibuf==' '){
	 ibuf--;
      }
      *(ibuf+1)=0;
      size_t ol=0x200,il=(ibuf-(char *)header_buf)-0x16;
      if(il==lrc_offs-0x1F){
	 obuf=strrchr(ofname,'.');
	 char *p=obuf-1;
	 obuf+=5;
	 *obuf=0;
	 while(*p!='/'){
	    *(p+5)=*p;
	    p--;
	 }
	 p[1]='d';
	 p[2]='o';
	 p[3]='n';
	 p[4]='e';
	 p[5]='-';
	 
      }
      else{
	 ibuf=header_buf+0x18;
	 obuf=strrchr(ofname,'/');
	 strcpy(obuf,"/done-");
	 obuf+=6;
	 iconv_t cd=iconv_open("UTF-8","GBK");
	 iconv(cd,&ibuf,&il,&obuf,&ol);
	 iconv_close(cd);
	 obuf--;
      }
      fprintf(stderr,"INFO: %s\n",ofname);
      if(lrc_len){
	 char *lrc_str=malloc(lrc_len+0x100);
	 memset(lrc_str,0,lrc_len+0x100);
	 fseek(f,lrc_offs,SEEK_SET);
	 fread(lrc_str,1,lrc_len,f);
	 init_keys(lrc_offs);
	 decode_str(lrc_str,lrc_len);
	 strcpy(obuf,".LRC");
	 FILE *ff=fopen(ofname,"w+");
	 fwrite(lrc_str,1,lrc_len,ff);
	 fclose(ff);
	 free(lrc_str);
      }
      if(dat_len){
	 unsigned char *dat_str=malloc(dat_len+0x100);
	 memset(dat_str,0,dat_len+0x100);
	 fseek(f,dat_offs,SEEK_SET);
	 int read=fread(dat_str,1,dat_len,f);
	 init_keys(dat_offs);
	 decode_str(dat_str,dat_len);
	 int type_known=1;
	 if(strncmp(dat_str,"RIFF",4)==0&&strncmp(dat_str+8,"AVI LIST",8)==0){
	    strcpy(obuf,".AVI");
	 }
	 else if(strncmp(dat_str,"FWS",3)==0){
	    strcpy(obuf,".SWF");
	 }
	 else if(dat_str[0]==0xFF&&(dat_str[1]&0xE0)==0xE0){
	    strcpy(obuf,".MP3");
	 }
	 else{
	    int i;
	    fprintf(stderr,"ERR: Unknown header:");
	    for(i=0;i<10;i++){
	       fprintf(stderr," %02X",dat_str[i]);
	    }
	    fprintf(stderr,"\n");
	    strcpy(obuf,".DAT");
	    type_known=0;
	 }
	 if(type_known){
	    FILE *ff=fopen(ofname,"w+");
	    fwrite(dat_str,1,dat_len,ff);
	    fclose(ff);
	 }
	 else{
	    FILE *ff=fopen(ofname,"w+");
	    fwrite(dat_str,1,dat_len,ff);
	    fclose(ff);
	 }
	 free(dat_str);
      }
   }
   fclose(f);
}
Пример #24
0
int main(int argc, char *argv[], char *envp[])
{
	char	*channel;

	debug_init();
	srand((unsigned)time(NULL));
	time(&start_time);
	time(&idle_time);
	time(&now);
#ifdef WINNT
	fprintf(stdout, "%s %s\r\n", nap_version, internal_version);
	fprintf(stdout, "%s\r\n", main_version);
#else
	fprintf(stdout, "%s %s\n", nap_version, internal_version);
	fprintf(stdout, "%s\n",  main_version);
#endif
	channel = parse_args(argv, argc, envp);

	FD_ZERO(&readables);
	FD_ZERO(&writables);
	
	if (term_init(NULL))
		_exit(1);

/* 	my_signal(SIGQUIT, SIG_IGN, 0);*/
	my_signal(SIGHUP, irc_exit_old, 0);
	my_signal(SIGTERM, irc_exit_old, 0);
	my_signal(SIGPIPE, SIG_IGN, 0);
	my_signal(SIGINT, cntl_c, 0);
	my_signal(SIGALRM, nothing, 0);
        my_signal(SIGCHLD, child_reap, 0);
	my_signal(SIGCONT, term_cont, 0);
	my_signal(SIGWINCH, sig_refresh_screen, 0);
	my_signal(SIGUSR1, sigusr1, 0);
	        
	if (!init_screen()) 
	{
		create_new_screen();
		new_window(main_screen);
	}

	init_keys();
	init_keys2();
	init_variables();
#ifdef WANT_THREAD
	init_share_mutexes();
#ifdef WANT_NSLOOKUP
	start_dns();
#endif
#ifdef WANT_MP3PLAYER
	start_mp3();
#endif

#ifdef GTK
	start_tgtk();
#endif
#endif
	build_status(current_window, NULL, 0);
	update_input(UPDATE_ALL);

#ifndef WINNT
	charset_ibmpc();
#endif
	load_scripts();
	read_unfinished_list();
	if (auto_connect)
	{
		int serv = 0;
		reload_save(NULL, NULL, NULL, NULL, 0);
		if (starting_server != -1)
			serv = starting_server;
		connect_to_server_by_refnum(serv, -1, create);
		current_window->server = serv;
		xterm_settitle();
	} 
	else
	{
		if (do_get_napigator)
			get_napigator();
		display_server_list();
	}
			
	set_input_prompt(current_window, get_string_var(INPUT_PROMPT_VAR), 0);
	for (;;)
		io("main");
#ifdef GUI1
	gui_exit();
#else
	nappanic("get_line() returned");
#endif
	return (-((int)0xdead));
}
Пример #25
0
int main(void)
{
    int listenfd = 0, connfd = 0, i = 0, m_len, ack;
    struct sockaddr_in serv_addr;

    int sendBuff[mx_l], recvBuff[mx_l], message[mx_l];
    char str[mx_l], dummy;

    listenfd = socket(AF_INET, SOCK_STREAM, 0);
    system("clear");
    printf("Server Initialized\n");
    printf("1. Put server on auto reply\n2. Put server on custom reply mode\n");
    scanf("%d",&ack);
    dummy=getchar();

    memset(&serv_addr, '0', sizeof(serv_addr));
    memset(sendBuff, '0', sizeof(sendBuff));
    memset(recvBuff, '0', sizeof(recvBuff));

    serv_addr.sin_family = AF_INET;
    serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
    serv_addr.sin_port = htons(port);

    bind(listenfd, (struct sockaddr*)&serv_addr,sizeof(serv_addr));

    if(listen(listenfd, 10) == -1) {
        printf("Failed to listen\n");
        return -1;
    }

    init_keys(); // Initialize crypto keys

    while(1) {
        connfd = accept(listenfd, (struct sockaddr*)NULL ,NULL); // accept awaiting request
        puts("Connection with Client established\n");

        write(connfd, &pub_key, sizeof(pub_key));
        write(connfd, &ser_pub_key, sizeof(ser_pub_key));
        read(connfd, &cli_pub_key, sizeof(cli_pub_key));

        printf("pubic key = %d\n", pub_key);
        printf("Server public key = %d\n", ser_pub_key);
        printf("Client public key = %d\n", cli_pub_key);

        while(read(connfd, recvBuff, sizeof(recvBuff)-1)) {
            m_len=0;
            for (i=0;i<recvBuff[i]!=0;i++) {
                m_len++;
            }

            printf("\nMessage from client- (Encrypted message): \n");
            elgamal_decrypt(recvBuff, message, m_len, cli_pub_key, ser_pri_key);
            printf("Decrypted message from client: ");

            disp(message, m_len);

            if (ack==1) {
                strcpy(str, "Message recieved successfully");
            }

            else if (ack==2) {
                printf("Reply to client: ");
                gets(str);
            }

            write(connfd, str, sizeof(str)-1);
        }
    }
return 0;
}