コード例 #1
0
ファイル: ASDocGen.c プロジェクト: cooljeanius/AfterStep
void 
write_options_keywords(const char *source_dir, const char *syntax_dir, SyntaxDef *syntax, ASXMLInterpreterState *state )
{
#define MAX_SYNTAX_RECURSION_LEVEL	32
	static int syntax_recursion_level = -1;
	static SyntaxDef* syntax_recursion_stack[MAX_SYNTAX_RECURSION_LEVEL];

	int i, max_i = 0 ;
	TermDef **sorted_list ; 
	while(syntax->terms[max_i].keyword) ++max_i;

	if( max_i == 0 ) return ;

	if (syntax_recursion_level+1 >= MAX_SYNTAX_RECURSION_LEVEL)
	{
		show_error ("Excessive recursion into nested Syntaxes. Syntax doc path = \"%s\".", syntax->doc_path );
		return;
	}
	for (i = syntax_recursion_level; i >= 0 ; --i)
		if (syntax_recursion_stack[i] == syntax) 
			return;
	++syntax_recursion_level;
	syntax_recursion_stack[syntax_recursion_level] = syntax;

	sorted_list = safecalloc( max_i, sizeof(TermDef*));
	for (i = 0; i < max_i; i++)
		sorted_list[i] = &(syntax->terms[i]) ; 
	qsort(sorted_list, max_i, sizeof(TermDef*), (int (*)())sort_terms_by_alpha );
	for (i = 0; i < max_i; i++)
	{	
		SyntaxDef *sub_syntax = sorted_list[i]->sub_syntax ; 
		if( sub_syntax == pPopupFuncSyntax ) 
			sub_syntax = pFuncSyntax ;

		if (sub_syntax)
			gen_syntax_doc( source_dir, state->dest_dir, sub_syntax, state->doc_type );
		if( isalnum( sorted_list[i]->keyword[0] ) )					
			convert_xml_file( syntax_dir, sorted_list[i]->keyword, state );
	}
	free( sorted_list );

	syntax_recursion_stack[syntax_recursion_level] = NULL;
	--syntax_recursion_level;
}
コード例 #2
0
ファイル: timer.c プロジェクト: Vaevictusnet/afterstep-devel
void
timer_new (time_t msec, void (*handler) (void *), void *data)
{
	Timer        *timer;
	time_t        sec, usec;

	timer = (Timer *) safecalloc (1, sizeof (Timer));

	timer->next = timer_first;
	timer_first = timer;

	timer_get_time (&sec, &usec);
	timer->sec = sec + (msec * 1000 + usec) / 1000000;
	timer->usec = (msec * 1000 + usec) % 1000000;
	timer->data = data;
	timer->handler = handler;

	LOCAL_DEBUG_OUT( "added task for data = %p, sec = %ld, usec = %ld", data, timer->sec, timer->usec );

}
コード例 #3
0
ファイル: freestor.c プロジェクト: Remmy/afterstep
/* Create new FreeStorage Elem and add it to the supplied storage's tail */
static FreeStorageElem *CreateFreeStorageElem (SyntaxDef * syntax,
																							 FreeStorageElem ** tail,
																							 TermDef * pterm, int id)
{
	FreeStorageElem *fs = NULL;

	if (pterm == NULL)
		if ((pterm = FindTerm (syntax, TT_ANY, id)) == NULL)
			return NULL;

	fs = (FreeStorageElem *) safecalloc (1, sizeof (FreeStorageElem));
	if (fs) {
		fs->term = pterm;
		if (tail) {
			fs->next = *tail;
			*tail = fs;
		}
	}
	return fs;
}
コード例 #4
0
ファイル: Wharf.c プロジェクト: Remmy/afterstep
WharfConfig *CreateWharfConfig ()
{
	WharfConfig *config =
			(WharfConfig *) safecalloc (1, sizeof (WharfConfig));

	/* let's initialize Base config with some nice values: */
	config->geometry.flags = WidthValue | HeightValue;
	config->geometry.width = config->geometry.height = 64;
	config->withdraw_style = WITHDRAW_ON_EDGE_BUTTON_AND_SHOW;

	config->AlignContents = WHARF_DEFAULT_AlignContents;
	config->ShowHints = WHARF_DEFAULT_ShowHints;

	config->more_stuff = NULL;

	config->CompositionMethod = WHARF_DEFAULT_CompositionMethod;
	config->FolderOffset = WHARF_DEFAULT_FolderOffset;
	config->OrthogonalFolderOffset = WHARF_DEFAULT_OrthogonalFolderOffset;

	return config;
}
コード例 #5
0
static int
place_new_record (ASDatabase * db, wild_reg_exp * regexp)
{
	int           res = -1;

	if (db && regexp)
	{
		register int  i;
		ASDatabaseRecord *tmp;

		/* we have to find a location for regexp, by comparing it to others.
		 * longer regexps should go first.
		 * If we find exactly the same regexp - then we replace record.
		 * Otherwise we reallocate space as needed.
		 */
		 /* No we f*****g don't! DB entries should be stored in the same order 
			as they are in the file ! I can't belive I was so f*****g stupid ! 
			All we should check for is if the regexp is already in the list. */
			
		for (i = 0; i < db->styles_num; i++)
		{
			res = compare_wild_reg_exp (db->styles_table[i].regexp, regexp);
			if (res == 0)
				return i;
			/* see above comment else if (res < 0)
				break;
			 */
		}

		res = i;

		if (db->allocated_num < db->styles_num + 1)
		{									   /* reallocating memory as needed : */
			db->allocated_num = db->styles_num + 1;
			/* we always want to allocate a little more space to prevent too many reallocs */
			db->allocated_num += db->allocated_num >> 1;
			tmp = (ASDatabaseRecord *) safecalloc (db->allocated_num, sizeof (ASDatabaseRecord));
			if (db->styles_table && res > 0)
				memcpy (tmp, db->styles_table, sizeof (ASDatabaseRecord) * res);
		} else								   /* we can use the same memory */
コード例 #6
0
ファイル: freestor.c プロジェクト: Remmy/afterstep
FreeStorageElem *AddFreeStorageElem (SyntaxDef * syntax,
																		 FreeStorageElem ** tail,
																		 TermDef * pterm, int id, ...)
{
	FreeStorageElem *fs = CreateFreeStorageElem (syntax, tail, pterm, id);

	if (fs) {
		va_list ap;
		int len = 0;
		char *v;

		va_start (ap, id);
		while ((v = va_arg (ap, char *)) != NULL) {
			fs->argc++;
			len += strlen (v) + 1;
		}
		va_end (ap);

		if (fs->argc > 0) {
			char *dst;
			int pos = 0;

			fs->argv = safecalloc (fs->argc, sizeof (char *));
			dst = safemalloc (len);

			va_start (ap, id);
			while ((v = va_arg (ap, char *)) != NULL) {
				int i = 0;

				do {
					dst[i] = v[i];
				}
				while (v[i++]);
				fs->argv[pos++] = dst;
				dst += i;
			}
			va_end (ap);
		}
	}
コード例 #7
0
ファイル: afterbase.c プロジェクト: krafczyk/root-5.34.09-ams
char*
asim_load_binary_file(const char* realfilename, long *file_size_return)
{
	struct stat st;
	FILE* fp;
	char* data = NULL ;

	/* Get the file size. */
	if (stat(realfilename, &st)) return NULL;
	/* Open the file. */
	fp = fopen(realfilename, "rb");
	if ( fp != NULL ) 
	{
		long len ; 
		/* Read in the file. */
		data = safecalloc(1, st.st_size + 1);
		len = fread(data, 1, st.st_size, fp);
		if( file_size_return ) 
			*file_size_return = len ; 
		fclose(fp);
	}
	return data;
}
コード例 #8
0
ファイル: xutil.c プロジェクト: Remmy/afterstep
Bool
aftershow_connect_x_gui(AfterShowContext *ctx)
{
	if (!ctx->gui.x.valid)
	{
		int i;
		AfterShowXScreen *scr;
		ctx->gui.x.dpy = XOpenDisplay(ctx->display);
		if (ctx->gui.x.dpy != NULL)
		{
			ctx->gui.x.fd = XConnectionNumber (ctx->gui.x.dpy);
			ctx->gui.x.screens_num = get_flags(ctx->flags, AfterShow_SingleScreen)?1:ScreenCount (ctx->gui.x.dpy);	
			ctx->gui.x.screens = scr = safecalloc(ctx->gui.x.screens_num, sizeof(AfterShowXScreen));

			for (i = 0; i < ctx->gui.x.screens_num; ++i)
			{
				scr->screen = i;
				scr->root.magic = MAGIC_AFTERSHOW_X_WINDOW;
				scr->root.screen = scr;
				aftershow_setup_root_x_window (ctx, &(scr->root));
				scr->windows = create_ashash( 0, NULL, NULL, NULL ); 
				++scr;
			}
			ctx->gui.x.first_screen = 0;
			ctx->gui.x.valid = True;
			show_progress( "X display \"%s\" connected. Servicing %d screens.", ctx->display?ctx->display:"", ctx->gui.x.screens_num);
		}else
		{
			if (ctx->display)
	        	show_error("failed to initialize X Window session for display \"%s\"", ctx->display);
			else
				show_error("failed to initialize X Window session for default display");
		}
	}

	return ctx->gui.x.valid;
}
コード例 #9
0
ファイル: module.c プロジェクト: Vaevictusnet/afterstep-devel
ASMessage    *
CheckASMessageFine (int t_sec, int t_usec)
{
	fd_set        in_fdset;
	ASMessage    *msg = NULL;
	struct timeval tv;
	int           fd = get_module_in_fd();

	if( fd < 0 ) 
		return NULL;

	FD_ZERO (&in_fdset);
	FD_SET (fd, &in_fdset);
	tv.tv_sec = t_sec;
	tv.tv_usec = t_usec;
#ifdef __hpux
	while (select (fd + 1, (int *)&in_fdset, 0, 0, (t_sec < 0) ? NULL : &tv) == -1)
		if (errno != EINTR)
			break;
#else
	while (select (fd + 1, &in_fdset, 0, 0, (t_sec < 0) ? NULL : &tv) == -1)
		if (errno != EINTR)
			break;
#endif
	if (FD_ISSET (fd, &in_fdset))
	{
		msg = (ASMessage *) safecalloc (1, sizeof (ASMessage));
		if (ReadASPacket (fd, msg->header, &(msg->body)) <= 0)
		{
			free (msg);
			msg = NULL;
		}
	}

	return msg;
}
コード例 #10
0
ファイル: main.c プロジェクト: Remmy/afterstep
void reloadButtons ()
{
	int i;
	static char *button_imgs[BUTTONS_NUM][2] = {{"mount-white", "mount-green-pressed"},
																							{"unmount-white", "unmount-red-pressed"},
																							{"eject-white", "eject-red-pressed"}};
	static int button_contexts[BUTTONS_NUM] = { MOUNT_CONTEXT, UNMOUNT_CONTEXT, EJECT_CONTEXT};																							
	int btn_size = (AppState.tileWidth - 15) / 2;

	for ( i = 0 ; i < BUTTONS_NUM ; ++i){
		if (AppState.buttons[i] == NULL)	
			AppState.buttons[i] = safecalloc (1, sizeof(struct button_t));
		else
			free_button_resources (AppState.buttons[i]);

		load_button (AppState.buttons[i], button_imgs[i], Scr.image_manager );
		AppState.buttons[i]->context = button_contexts[i];
		LOCAL_DEBUG_OUT ("button[%d].size = %dx%d, image %dx%d", i,
										AppState.buttons[i]->width, AppState.buttons[i]->height, 
	                  AppState.buttons[i]->pressed.image?AppState.buttons[i]->pressed.image->width:0, 
										AppState.buttons[i]->pressed.image?AppState.buttons[i]->pressed.image->height:0);
		scale_button (AppState.buttons[i], btn_size, btn_size, Scr.asv);
	}
}
コード例 #11
0
ファイル: afterbase.c プロジェクト: krafczyk/root-5.34.09-ams
static char *
do_replace_envvar (char *path)
{
	char         *data = path, *tmp;
	char         *home = getenv ("HOME");
	int           pos = 0, len, home_len = 0;

	if (path == NULL)
		return NULL;
	if (*path == '\0')
		return path;
	len = strlen (path);
	if (home)
		home_len = strlen (home);

	while (*(data + pos))
	{
		char         *var;
		int           var_len, end_pos;

		while (*(data + pos) != '$' && *(data + pos))
		{
			if (*(data + pos) == '~' && *(data + pos + 1) == '/')
			{
				if (pos > 0)
					if (*(data + pos - 1) != ':')
					{
						pos += 2;
						continue;
					}
				if (home == NULL)
					*(data + (pos++)) = '.';
				else
				{
					len += home_len;
					tmp = safecalloc (1, len);
					strncpy (tmp, data, pos);
					strcpy (tmp + pos, home);
					strcpy (tmp + pos + home_len, data + pos + 1);
					if( data != path )
						free (data);
					data = tmp;
					pos += home_len;
				}
			}
			pos++;
		}
		if (*(data + pos) == '\0')
			break;
		/* found $ sign - trying to replace var */
		if ((var = find_envvar (data + pos + 1, &end_pos)) == NULL)
		{
			++pos;
			continue;
		}
		var_len = strlen (var);
		len += var_len;
		tmp = safecalloc (1, len);
		strncpy (tmp, data, pos);
		strcpy (tmp + pos, var);
		strcpy (tmp + pos + var_len, data + pos + end_pos + 1);
		if( data != path )
			free (data);
		data = tmp;
	}
	return data;
}
コード例 #12
0
MyStyle *
mystyle_create_from_definition (struct ASHashTable *list, MyStyleDefinition * def)
{
	int           i;
	MyStyle      *style;

	if (def == NULL || def->Name == NULL)
		return NULL;

	if ((style = mystyle_find (def->Name)) == NULL)
		style = mystyle_new_with_name (def->Name);

	if (def->inherit)
	{
		for (i = 0; i < def->inherit_num; ++i)
		{
			MyStyle      *parent;
			if (def->inherit[i])
			{
				if ((parent = mystyle_find_or_get_from_file (list, def->inherit[i])) != NULL)
					mystyle_merge_styles (parent, style, True, False);
				else
					show_error ("unknown style to inherit: %s\n", def->inherit[i]);
			}
		}
	}
	if( def->Font )
	{
		if (get_flags(style->user_flags, F_FONT))
		{
			unload_font (&style->font);
			clear_flags(style->user_flags, F_FONT);
		}
		set_string(&(style->font.name), mystrdup(def->Font));
		set_flags(style->user_flags, F_FONT);
	}
	if( get_flags(def->set_flags, MYSTYLE_TextStyle ) )
	{
		set_flags( style->user_flags, F_TEXTSTYLE );
		style->text_style = def->TextStyle;
	}
	if( get_flags(def->set_flags, MYSTYLE_SLICE_SET ) )
	{
		set_flags( style->user_flags, F_SLICE );
		style->slice_x_start = def->SliceXStart;
		style->slice_x_end = def->SliceXEnd;
		style->slice_y_start = def->SliceYStart;
		style->slice_y_end = def->SliceYEnd;
	}
	if( get_flags(def->set_flags, MYSTYLE_BlurSize ) )
	{
		set_flags( style->user_flags, F_BLUR );
		style->blur_x = def->BlurSize.width;
		style->blur_y = def->BlurSize.height;
  	}
	if( def->ForeColor )
	{
		if (parse_argb_color (def->ForeColor, &(style->colors.fore)) != def->ForeColor)
			set_flags(style->user_flags, F_FORECOLOR);
		else
    		show_error("unable to parse Forecolor \"%s\"", def->ForeColor);
	}
	if( def->BackColor )
	{
		if (parse_argb_color (def->BackColor, &(style->colors.back)) != def->BackColor)
		{
			style->relief.fore = GetHilite (style->colors.back);
			style->relief.back = GetShadow (style->colors.back);
			set_flags(style->user_flags, F_BACKCOLOR);
		}else
    		show_error("unable to parse BackColor \"%s\"", def->BackColor);
	}
	if( def->overlay != NULL )
	{
		MyStyle *o = mystyle_find_or_get_from_file (list, def->overlay );
		if ( o != NULL)
		{
			style->overlay = o;
			style->overlay_type = def->overlay_type ;
		}else
			show_error ("unknown style to be overlayed with: %s\n", def->overlay );
		set_flags(style->user_flags, F_OVERLAY);
	}
	
	if( def->texture_type > 0 && def->texture_type <= TEXTURE_GRADIENT_END )
	{
		int           type = def->back_grad_type;
		ASGradient    gradient = {0};
		Bool          success = False;

		if( type <= TEXTURE_OLD_GRADIENT_END )
		{
			ARGB32 color1 = ARGB32_White, color2 = ARGB32_Black;
			parse_argb_color( def->back_grad_colors[0], &color1 );
			parse_argb_color( def->back_grad_colors[1], &color2 );
			if ((type = mystyle_parse_old_gradient (type, color1, color2, &gradient)) >= 0)
			{
				if (style->user_flags & F_BACKGRADIENT)
				{
					free (style->gradient.color);
					free (style->gradient.offset);
				}
				style->gradient = gradient;
				style->gradient.type = mystyle_translate_grad_type (type);
				LOCAL_DEBUG_OUT( "style %p type = %d", style, style->gradient.type );
				success = True ;
			} else
            	show_error("Error in MyStyle \"%s\": invalid gradient type %d", style->name, type);
		}else
		{
			int i ;
			gradient.npoints = def->back_grad_npoints;
			gradient.color = safecalloc(gradient.npoints, sizeof(ARGB32));
			gradient.offset = safecalloc(gradient.npoints, sizeof(double));
			for( i = 0 ; i < gradient.npoints ; ++i )
			{
				ARGB32 color = ARGB32_White;
				parse_argb_color (def->back_grad_colors[i], &color );
				gradient.color[i] = color ;
				gradient.offset[i] = def->back_grad_offsets[i] ;
			}
			gradient.offset[0] = 0.0;
			gradient.offset[gradient.npoints - 1] = 1.0;
			if (style->user_flags & F_BACKGRADIENT)
			{
				 free (style->gradient.color);
				 free (style->gradient.offset);
			}
			style->gradient = gradient;
			style->gradient.type = mystyle_translate_grad_type (type);
			success = True ;
		}
		if( success )
		{
			style->texture_type = def->texture_type;
			set_flags( style->user_flags, F_BACKGRADIENT );
		}else
		{
			if (gradient.color != NULL)
				free (gradient.color);
			if (gradient.offset != NULL)
				free (gradient.offset);
            show_error("Error in MyStyle \"%s\": bad gradient", style->name);
		}
	}else if( def->texture_type > TEXTURE_GRADIENT_END && def->texture_type <= TEXTURE_TEXTURED_END )
	{
		int type = def->texture_type;

		if ( get_flags(style->user_flags, F_BACKPIXMAP) )
		{
			mystyle_free_back_icon(style);
			clear_flags (style->user_flags, F_BACKTRANSPIXMAP | F_BACKPIXMAP);
		}
		clear_flags (style->inherit_flags, F_BACKTRANSPIXMAP | F_BACKPIXMAP);
        LOCAL_DEBUG_OUT( "calling mystyle_free_back_icon for style %p", style );

		if (type == TEXTURE_TRANSPARENT || type == TEXTURE_TRANSPARENT_TWOWAY)
		{							   /* treat second parameter as ARGB tint value : */
			if (parse_argb_color (def->back_pixmap, &(style->tint)) == def->back_pixmap)
				style->tint = TINT_LEAVE_SAME;	/* use no tinting by default */
			else if (type == TEXTURE_TRANSPARENT)
				style->tint = (style->tint >> 1) & 0x7F7F7F7F;	/* converting old style tint */
/*LOCAL_DEBUG_OUT( "tint is 0x%X (from %s)",  style->tint, tmp);*/
			set_flags (style->user_flags, F_BACKPIXMAP);
			style->texture_type = type;
		} else
        {  /* treat second parameter as an image filename : */
        	if ( load_icon(&(style->back_icon), def->back_pixmap, get_screen_image_manager(NULL) ))
コード例 #13
0
void
HandleMyStyleSpecialTerm (MyStyleDefinition *msd, FreeStorageElem *fs)
{
	ConfigItem    item;
	item.memory = NULL;

	if (!ReadConfigItem (&item, fs))
		return;

	switch (fs->term->id)
	{
		 case MYSTYLE_Inherit_ID:
		 	{
				int pos = msd->inherit_num++;
				msd->inherit = realloc( msd->inherit, sizeof(char*) * msd->inherit_num );
				msd->inherit[pos] = item.data.string;
			}
			break;
		 case MYSTYLE_BackGradient_ID:
			if( fs->argc != 3 )
				show_error( "invalid number of colors in BackGradient definition (%d)", fs->argc );
			else
			{
				free_MSD_back_grad (msd);

				msd->back_grad_type = item.data.integer;
				msd->texture_type = mystyle_parse_old_gradient (msd->back_grad_type, 0, 0, NULL);
				msd->back_grad_npoints = 2 ;
				msd->back_grad_colors = safemalloc (2 * sizeof(char*));
				msd->back_grad_offsets = safemalloc (2 * sizeof(double));
				msd->back_grad_colors[0] = mystrdup (fs->argv[1]);
				msd->back_grad_colors[1] = mystrdup (fs->argv[2]);
				msd->back_grad_offsets[1] = 0.0 ;
				msd->back_grad_offsets[1] = 1.0 ;
			}
			break;
		 case MYSTYLE_BackMultiGradient_ID:
			if( fs->argc < 4 )
				show_error( "invalid number of colors in BackMultiGradient definition (%d)", fs->argc );
			else
			{
				int i ;
				free_MSD_back_grad (msd);

				msd->back_grad_type = item.data.integer;
				msd->texture_type = mystyle_parse_old_gradient (msd->back_grad_type, 0, 0, NULL);
				msd->back_grad_npoints = ((fs->argc-1)+1)/2 ;
				msd->back_grad_colors = safecalloc( msd->back_grad_npoints, sizeof(char*));
				msd->back_grad_offsets = safecalloc( msd->back_grad_npoints, sizeof(double));
				for( i = 0 ; i < msd->back_grad_npoints ; ++i )
				{
					msd->back_grad_colors[i] = mystrdup (fs->argv[i*2+1]);
					if( i*2 + 2 < fs->argc )
						msd->back_grad_offsets[i] = atof(fs->argv[i*2+2]);
				}
				msd->back_grad_offsets[msd->back_grad_npoints-1] = 1.0 ;
			}
			break;
		 case MYSTYLE_BackPixmap_ID:
		 	{
				set_string( &(msd->back_pixmap), item.data.string );
				msd->texture_type = item.index;
			}
			break;
		 case MYSTYLE_Overlay_ID:
		 	{
				if (fs->argc > 1)
				{
					set_string( &(msd->overlay), stripcpy2 (fs->argv[1], False) );
					msd->overlay_type = item.data.integer;
				}else
		            show_error("Error in MyStyle \"%s\": Overlay option uses format :  \"Overlay <type> <mystyle name>\". Ignoring.", msd->Name);
			}
			break;
		 default:
			 item.ok_to_free = 1;
	}	
	ReadConfigItem (&item, NULL);
}
コード例 #14
0
ファイル: network.c プロジェクト: eausky/tinyproxy
ssize_t
readline(int fd, char **whole_buffer)
{
	ssize_t whole_buffer_len;
	char buffer[SEGMENT_LEN];
	char *ptr;

	ssize_t ret;
	ssize_t diff;

	struct read_lines_s {
		char *data;
		size_t len;
		struct read_lines_s *next;
	};
	struct read_lines_s *first_line, *line_ptr;

	first_line = safecalloc(sizeof(struct read_lines_s), 1);
	if (!first_line)
		return -ENOMEM;

	line_ptr = first_line;

	whole_buffer_len = 0;
	for (;;) {
		ret = recv(fd, buffer, SEGMENT_LEN, MSG_PEEK);
		if (ret <= 0)
			goto CLEANUP;

		ptr = memchr(buffer, '\n', ret);
		if (ptr)
			diff = ptr - buffer + 1;
		else
			diff = ret;

		whole_buffer_len += diff;

		/*
		 * Don't allow the buffer to grow without bound. If we
		 * get to more than MAXIMUM_BUFFER_LENGTH close.
		 */
		if (whole_buffer_len > MAXIMUM_BUFFER_LENGTH) {
			ret = -ERANGE;
			goto CLEANUP;
		}

		line_ptr->data = safemalloc(diff);
		if (!line_ptr->data) {
			ret = -ENOMEM;
			goto CLEANUP;
		}

		recv(fd, line_ptr->data, diff, 0);
		line_ptr->len = diff;

		if (ptr) {
			line_ptr->next = NULL;
			break;
		}

		line_ptr->next = safecalloc(sizeof(struct read_lines_s), 1);
		if (!line_ptr->next) {
			ret = -ENOMEM;
			goto CLEANUP;
		}
		line_ptr = line_ptr->next;
	}

	*whole_buffer = safemalloc(whole_buffer_len + 1);
	if (!*whole_buffer) {
		ret = -ENOMEM;
		goto CLEANUP;
	}

	*(*whole_buffer + whole_buffer_len) = '\0';

	whole_buffer_len = 0;
	line_ptr = first_line;
	while (line_ptr) {
		memcpy(*whole_buffer + whole_buffer_len, line_ptr->data,
		       line_ptr->len);
		whole_buffer_len += line_ptr->len;

		line_ptr = line_ptr->next;
	}

	ret = whole_buffer_len;

      CLEANUP:
	do {
		line_ptr = first_line->next;
		if (first_line->data)
			safefree(first_line->data);
		safefree(first_line);
		first_line = line_ptr;
	} while (first_line);

	return ret;
}
コード例 #15
0
ファイル: Feel.c プロジェクト: Vaevictusnet/afterstep-devel
FeelConfig *
ParseFeelOptions (const char *filename, char *myname)
{
    ConfigData cd ; 
	ConfigDef *ConfigReader;
    FeelConfig *config = CreateFeelConfig ();
	FreeStorageElem *Storage = NULL, *pCurr;
    ConfigItem item;

	cd.filename = filename ; 
	ConfigReader = InitConfigReader (myname, &FeelSyntax, CDT_Filename, cd, BindingSpecialFunc);
	if (!ConfigReader)
  		return config;

    item.memory = NULL;
	PrintConfigReader (ConfigReader);
	ParseConfig (ConfigReader, &Storage);

	/* getting rid of all the crap first */
    StorageCleanUp (&Storage, &(config->more_stuff), CF_DISABLED_OPTION);

	for (pCurr = Storage; pCurr; pCurr = pCurr->next)
  	{
  	    if (pCurr->term == NULL)
			continue;
        if (ReadFlagItem (NULL, &(config->feel->flags), pCurr, FeelFlagsXref))
            continue;
        if (!ReadConfigItem (&item, pCurr))
			continue;
        switch (pCurr->term->id)
		{
            case FEEL_ClickTime_ID          :
                config->feel->ClickTime = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_ClickTime);
                break ;
            case FEEL_OpaqueMove_ID         :
                config->feel->OpaqueMove = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_OpaqueMove);
                break ;
            case FEEL_OpaqueResize_ID       :
                config->feel->OpaqueResize = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_OpaqueResize);
                break ;
            case FEEL_AutoRaise_ID          :
                config->feel->AutoRaiseDelay = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_AutoRaise);
                break ;
            case FEEL_AutoReverse_ID        :
                config->feel->AutoReverse = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_AutoReverse);
                break ;
            case FEEL_ShadeAnimationSteps_ID :
                config->feel->ShadeAnimationSteps = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_ShadeAnimationSteps);
                break ;

            case FEEL_XorValue_ID           :
                config->feel->XorValue = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_XorValue);
                break ;
            case FEEL_Xzap_ID               :
                config->feel->Xzap = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_Xzap);
                break ;
            case FEEL_Yzap_ID               :
                config->feel->Yzap = item.data.integer;
                set_flags (config->feel->set_val_flags, FEEL_Yzap);
                break ;

            case FEEL_Cursor_ID             :                   /* TT_INTEGER */
				/* TODO: backport from as-devel : */
                /*if ( item.index  > 0 && item.index < MAX_CURSORS)
                    config->feel->standard_cursors[item.index] = item.data.integer ;
				 */
                break ;
            case FEEL_CustomCursor_ID       :                   /* TT_BUTTON  */
				/* TODO: backport from as-devel : */
				/*
					if ( item.index  > 0 && item.index < MAX_CURSORS)
                	{
                    	if( config->feel->custom_cursors[item.index] )
                        	destroy_ascursor( &(config->feel->custom_cursors[item.index]));
                    	config->feel->custom_cursors[item.index] = item.data.cursor ;
                	}
				 */
                break ;

            case FEEL_ClickToRaise_ID       :                   /* TT_BITLIST */
                config->feel->RaiseButtons = item.data.integer ;
                set_flags (config->feel->set_val_flags, FEEL_ClickToRaise);
                set_flags (config->feel->set_flags, ClickToRaise);
				set_flags (config->feel->flags, ClickToRaise);
                break ;

            case FEEL_EdgeScroll_ID         :                   /* TT_INTARRAY*/
				item.ok_to_free = 1;
                if( item.data.int_array.size > 0 )
                {
                    config->feel->EdgeScrollX = item.data.int_array.array[0];
                    if( item.data.int_array.size > 1 )
                        config->feel->EdgeScrollY = item.data.int_array.array[1];
                    set_flags (config->feel->set_val_flags, FEEL_EdgeScroll );
                }
                break ;
            case FEEL_EdgeResistance_ID     :                   /* TT_INTARRAY*/
				item.ok_to_free = 1;
                if( item.data.int_array.size > 0 )
                {
                    config->feel->EdgeResistanceScroll = item.data.int_array.array[0];
                    if( item.data.int_array.size > 1 )
                        config->feel->EdgeResistanceMove = item.data.int_array.array[1];
                    set_flags (config->feel->set_val_flags, FEEL_EdgeResistance );
                }
                break ;

            case FEEL_Popup_ID              :
				/* TODO: backport from as-devel : */
                /* FreeStorage2MenuData( pCurr, &item, config->feel->Popups ); */
                break ;
            case FEEL_Function_ID           :
                FreeStorage2ComplexFunction( pCurr, &item, config->feel->ComplexFunctions );
                break ;
            case FEEL_Mouse_ID              :
                if( item.data.binding.sym )
                    if( isdigit( (int)item.data.binding.sym[0] ) && pCurr->sub )
                    {
                        int button_num = item.data.binding.sym[0] - '0' ;
                        if( button_num >= 0 && button_num <= MAX_MOUSE_BUTTONS &&
                            pCurr->sub->term->type == TT_FUNCTION )
                        {
                            ConfigItem func_item ;
                            func_item.memory = NULL ;
                            if( ReadConfigItem( &func_item, pCurr->sub ) )
							{
								MouseButton *tmp = safecalloc( 1, sizeof(MouseButton) );
								tmp->Button = button_num ;
								tmp->Modifier = item.data.binding.mods ;
								tmp->Context = item.data.binding.context ;
								tmp->fdata = func_item.data.function ;
								func_item.data.function = NULL ;
								tmp->NextButton = config->feel->MouseButtonRoot ;
								config->feel->MouseButtonRoot = tmp ;
							}
                            if( func_item.data.function )
                            {
                                func_item.ok_to_free = 1;
                                ReadConfigItem( &func_item, NULL );
                            }
                        }
                    }
                item.ok_to_free = 1;
                break ;
            case FEEL_Key_ID                :
                ParseKeyBinding( &item, pCurr->sub, &(config->feel->FuncKeyRoot) );
                break ;
          default:
				item.ok_to_free = 1;
		}
    }
	ReadConfigItem (&item, NULL);

	DestroyConfig (ConfigReader);
	DestroyFreeStorage (&Storage);
	return config;
}
コード例 #16
0
ファイル: Wharf.c プロジェクト: Remmy/afterstep
WharfButton *CreateWharfButton ()
{
	WharfButton *btn = (WharfButton *) safecalloc (1, sizeof (WharfButton));

	return btn;
}
コード例 #17
0
ファイル: afterbase.c プロジェクト: krafczyk/root-5.34.09-ams
char         *
asim_find_file (const char *file, const char *pathlist, int type)
{
	char 		  *path;
	register int   len;
	int            max_path = 0;
	register char *ptr;
	register int   i;
	Bool local = False ;

	if (file == NULL)
		return NULL;
#ifdef _WIN32
#define PATH_SEPARATOR_CHAR ';'
#define PATH_CHAR '\\'
#else
#define PATH_SEPARATOR_CHAR ':'
#define PATH_CHAR '/'
#endif
	
	if (*file == PATH_CHAR || *file == '~' || ((pathlist == NULL) || (*pathlist == '\0')))
		local = True ;
	else if( file[0] == '.' && (file[1] == PATH_CHAR || (file[1] == '.' && file[2] == PATH_CHAR))) 
		local = True ;
	else if( strncmp( file, "$HOME", 5) == 0 ) 
		local = True ;
	if( local ) 
	{
		path = put_file_home (file);
		if ( access (path, type) == 0 )
		{
			return path;
		}
		free (path);
		return NULL;
	}
/*	return put_file_home(file); */
	for (i = 0; file[i]; i++);
	len = i ;
	for (ptr = (char *)pathlist; *ptr; ptr += i)
	{
		if (*ptr == PATH_SEPARATOR_CHAR )
			ptr++;
		for (i = 0; ptr[i] && ptr[i] != PATH_SEPARATOR_CHAR; i++);
		if (i > max_path)
			max_path = i;
	}

	path = safecalloc (1, max_path + 1 + len + 1);
	strcpy( path+max_path+1, file );
	path[max_path] = PATH_CHAR ;

	ptr = (char*)&(pathlist[0]) ;
	while( ptr[0] != '\0' )
	{
		int skip ;
		for( i = 0 ; ptr[i] == PATH_SEPARATOR_CHAR; ++i );
		ptr += i ;
		for( i = 0 ; ptr[i] != PATH_SEPARATOR_CHAR && ptr[i] != '\0'; ++i );
		skip = i ;
		if( i > 0 && ptr[i-1] == PATH_CHAR )
			i-- ;
		if( i > 0 )
		{
			register char *try_path = path+max_path-i;
			strncpy( try_path, ptr, i );
			if (access(try_path, type) == 0)
			{
				char* res = mystrdup(try_path);
				free( path );
				return res;
			}
		}
		ptr += skip ;
	}
	free (path);
	return NULL;
}
コード例 #18
0
void 
gen_index( const char *dest_dir, const char *file, ASDocType doc_type, Bool user_docs )
{
	ASXMLInterpreterState state;
	if( (doc_type == DocType_HTML	|| doc_type == DocType_PHP ) && Index->items_num > 0 )
	{	
		ASHashableValue *values;
		ASHashData *data;
		int items_num, i ;
		Bool sublist = False ; 
		char *sublist_name= NULL ; 
		int sublist_name_len = 1 ;
		if( !start_doc_file( dest_dir, file, NULL, doc_type, NULL, NULL, NULL, &state, DOC_CLASS_None, DocClass_TopicIndex ) )	
			return ;
		LOCAL_DEBUG_OUT( "sorting hash items : ... %s", "" );
		values = safecalloc( Index->items_num, sizeof(ASHashableValue));
		data = safecalloc( Index->items_num, sizeof(ASHashData));
		items_num = sort_hash_items (Index, values, (void**)data, 0);
		
		if( user_docs )
		{	
			if( doc_type == DocType_PHP )
			{	
				fprintf( state.dest_fp, PHPXrefFormat, "visualdoc","Developer documentation index","API/index", "" );
				fprintf( state.dest_fp, PHPXrefFormat, "graphics","Installed data files catalogue","index", "" );
			}else if( doc_type == DocType_HTML )
			{	
 				fprintf( state.dest_fp,  "<A href=\"API/index.html\">Developer documentation index</A>&nbsp;&nbsp;\n" );
				fprintf( state.dest_fp,  "<A href=\"data/index.html\">Installed data files catalogue</A>\n" );			   
			}
		}else
		{	  
			if( doc_type == DocType_PHP )
			{
				fprintf( state.dest_fp, PHPXrefFormat, "visualdoc","User documentation index","index", "" );
				fprintf( state.dest_fp, PHPXrefFormat, "graphics","Installed data files catalogue","index", "" );
			}
			else if( doc_type == DocType_HTML )
			{
 				fprintf( state.dest_fp,  "<A href=\"../index.html\">User documentation index</A>&nbsp;&nbsp;\n" );
				fprintf( state.dest_fp,  "<A href=\"../data/index.html\">Installed data files catalogue</A>\n" );
			}
		}
		fprintf( state.dest_fp, "<hr>\n<p><UL class=\"dense\">\n" );
		for( i = 0 ; i < items_num ; ++i ) 
		{
			char *item_text = (char*)values[i];
			if( sublist_name ) 
			{	
				if( strncmp( item_text, sublist_name, sublist_name_len ) == 0 ) 
				{
					if( !sublist ) 
					{
						fprintf( state.dest_fp, "\n<UL>\n" );
	  					sublist = True ;
					}
					item_text += sublist_name_len ;
					while( *item_text != '\0' && isspace( *item_text ) ) 
						++item_text ;
				}else if( sublist ) 
				{	
					sublist = False ;
					fprintf( state.dest_fp, "\n</UL>\n" );
				}
			}
			if( !sublist ) 
			{	
				sublist_name = item_text ; 
				sublist_name_len = strlen( sublist_name );
			}
			fprintf( state.dest_fp, "<LI class=\"dense\">" );

			if( state.doc_type == DocType_HTML	)
				fprintf( state.dest_fp, "<A href=\"%s\">%s</A>", data[i].cptr, item_text );
			else if( doc_type == DocType_PHP ) 
			{
				char *url = data[i].cptr ;
				char *ptr = &(url[strlen(url)-4]) ;	  
				if( *ptr == '.' ) 
					*ptr = '\0';
				fprintf( state.dest_fp, PHPXrefFormat, "visualdoc",item_text, url, "" );
				if( *ptr == '\0' ) 
					*ptr = '.';
			}
			fprintf( state.dest_fp, "</LI>\n" );
		}	 
		if( sublist ) 
			fprintf( state.dest_fp, "</UL>\n" );
		fprintf( state.dest_fp, "</UL>\n" );
		free( data );
		free( values );
		end_doc_file( &state );	 	  
	}
}
コード例 #19
0
ファイル: user_main.c プロジェクト: magore/esp8266_ili9341
void ntp_setup(void)
{
    tv_t tv;
    tz_t tz;
	time_t sec;
	struct ip_info getinfo;


	// Wait until we have an IP address before we set the time
    if(!network_init)
		return;

	if(ntp_init == 0)
    {
        ip_addr_t *addr = (ip_addr_t *)safecalloc(sizeof(ip_addr_t),1);

		// form pool.ntp.org
		ipaddr_aton("206.108.0.131", addr);
		sntp_setserver(1,addr);
		ipaddr_aton("167.114.204.238", addr);
		sntp_setserver(2,addr);

#if 0
		// Alternate time setting if the local router does NTP
		if(wifi_get_ip_info(0, &getinfo))
		{
			printf("NTP:0 GW: %s\n", ipv4_2str(getinfo.gw.addr));
			printf("NTP:0 IP: %s\n", ipv4_2str(getinfo.ip.addr));
			sntp_setserver(1, & getinfo.gw);
			sntp_setserver(2, & getinfo.ip);
		}
		else
		{
			printf("NTP:0 failed to get GW address\n");
			return;
		}
#endif

        if( sntp_set_timezone(0) )
		{
			printf("NTP: set_timeone OK\n");
			sntp_init();
            safefree(addr);
		    ntp_init = 1;
            printf("NTP:1\n");
		}
		else
		{
			printf("NTP: set_timeone Failed\n");
		}
    }

	if(ntp_init == 1)
	{
		// they hard coded it to +8 hours from GMT
		if( (sec = sntp_get_current_timestamp()) > 10 )
		{
			sntp_stop();
			ntp_init = 2;
		}
	}
	if(ntp_init == 2)
	{
		time_t s;

		tm_t *p;

		printf("NTP:2\n");

		// they return GMT + 8
        // sec = sec - (8UL * 3600UL);

        tv.tv_sec = sec;
		printf("ntp_init: %s\n", asctime(gmtime(&sec)));
		printf("ntp_init: %s\n", ctime_gm(&sec));

        tv.tv_usec = 0;
        tz.tz_minuteswest = 300;
		tz.tz_dsttime = 0;

        settimeofday(&tv, &tz);

        printf("SEC:%ld\n",sec);
        printf("TIME:%s\n", ctime(&sec));
		printf("Zone: %d\n", (int) sntp_get_timezone());
		ntp_init = 3;

		set_dst(tv.tv_sec);

		print_dst_gmt();
		print_dst();

		p = gmtime(&tv.tv_sec);
		mktime(p);
		printf("Localtime: %s\n", asctime(p));
    }
}
コード例 #20
0
ファイル: filter.c プロジェクト: eausky/tinyproxy
/*
 * Initializes a linked list of strings containing hosts/urls to be filtered
 */
void
filter_init(void)
{
	FILE *fd;
	struct filter_list *p;
	char buf[FILTER_BUFFER_LEN];
	char *s;
	int cflags;

	if (!fl && !already_init) {
		fd = fopen(config.filter, "r");
		if (fd) {
			p = NULL;

			cflags = REG_NEWLINE | REG_NOSUB;
			if (config.filter_extended)
				cflags |= REG_EXTENDED;
			if (!config.filter_casesensitive)
				cflags |= REG_ICASE;

			while (fgets(buf, FILTER_BUFFER_LEN, fd)) {
				/*
				 * Remove any trailing white space and
				 * comments.
				 */
				s = buf;
				while (*s) {
					if (isspace((unsigned char)*s)) break;
					if (*s == '#') {
						/*
						 * If the '#' char is preceeded by
						 * an escape, it's not a comment
						 * string.
						 */
						if (s == buf || *(s - 1) != '\\')
							break;
					}
					++s;
				}
				*s = '\0';

				/* skip leading whitespace */
				s = buf;
				while (*s && isspace((unsigned char)*s))
					s++;

				/* skip blank lines and comments */
				if (*s == '\0')
					continue;

				if (!p)	/* head of list */
					fl = p =
					    safecalloc(1,
						       sizeof(struct
							      filter_list));
				else {	/* next entry */
					p->next =
					    safecalloc(1,
						       sizeof(struct
							      filter_list));
					p = p->next;
				}

				p->pat = safestrdup(s);
				p->cpat = safemalloc(sizeof(regex_t));
				if ((err = regcomp(p->cpat, p->pat, cflags)) != 0) {
					fprintf(stderr, "Bad regex in %s: %s\n",
						config.filter, p->pat);
					exit(EX_DATAERR);
				}
			}
			if (ferror(fd)) {
				perror("fgets");
				exit(EX_DATAERR);
			}
			fclose(fd);

			already_init = 1;
		}
	}
}
コード例 #21
0
ファイル: Feel.c プロジェクト: Vaevictusnet/afterstep-devel
AutoExecConfig *
CreateAutoExecConfig ()
{
  AutoExecConfig *config = (AutoExecConfig *) safecalloc (1, sizeof (AutoExecConfig));
  return config;
}
コード例 #22
0
ファイル: Feel.c プロジェクト: Vaevictusnet/afterstep-devel
/* returns:
 *            0 on success
 *              1 if data is empty
 *              2 if ConfigWriter cannot be initialized
 *
 */
int
WriteFeelOptions (const char *filename, char *myname,
		  FeelConfig * config, unsigned long flags)
{
	ConfigDef *ConfigWriter = NULL;
    FreeStorageElem *Storage = NULL, **tail = &Storage;
    int i ;

	if (config == NULL)
  		return 1;
	if ((ConfigWriter = InitConfigWriter (myname, &FeelSyntax, CDT_Filename,
			  (void *) filename)) == NULL)
	    return 2;

    CopyFreeStorage (&Storage, config->more_stuff);

	/* building free storage here */
    /* flags : */
    tail = Flags2FreeStorage (&FeelSyntax, tail, FeelFlagsXref, config->feel->flags, config->feel->flags);

    /* integer parameters : */
    if (get_flags (config->feel->set_flags, FEEL_ClickTime))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->ClickTime, FEEL_ClickTime_ID);
    if (get_flags (config->feel->set_flags, FEEL_OpaqueMove))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->OpaqueMove, FEEL_OpaqueMove_ID);
    if (get_flags (config->feel->set_flags, FEEL_OpaqueResize))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->OpaqueResize, FEEL_OpaqueResize_ID);
    if (get_flags (config->feel->set_flags, FEEL_AutoRaise))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->AutoRaiseDelay, FEEL_AutoRaise_ID);
    if (get_flags (config->feel->set_flags, FEEL_AutoReverse))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->AutoReverse, FEEL_AutoReverse_ID);
    if (get_flags (config->feel->set_flags, FEEL_DeskAnimationType))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->DeskAnimationType, FEEL_DeskAnimationType_ID);
    if (get_flags (config->feel->set_flags, FEEL_DeskAnimationSteps))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->DeskAnimationSteps, FEEL_DeskAnimationSteps_ID);
    if (get_flags (config->feel->set_flags, FEEL_ShadeAnimationSteps))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->ShadeAnimationSteps, FEEL_ShadeAnimationSteps_ID);

    if (get_flags (config->feel->set_flags, FEEL_XorValue))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->XorValue, FEEL_XorValue_ID);
    if (get_flags (config->feel->set_flags, FEEL_Xzap))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->Xzap, FEEL_Xzap_ID);
    if (get_flags (config->feel->set_flags, FEEL_Yzap))
        tail = Integer2FreeStorage (&FeelSyntax, tail, NULL, config->feel->Yzap, FEEL_Yzap_ID);

    for( i = 0 ; i < MAX_CURSORS ; i++ )
    {
        if (config->feel->standard_cursors[i] != 0)
            tail = Integer2FreeStorage (&FeelSyntax, tail, &i, config->feel->standard_cursors[i], FEEL_Cursor_ID);
        if (config->feel->custom_cursors[i] != NULL)
            tail = ASCursor2FreeStorage (&FeelSyntax, tail, i, config->feel->custom_cursors[i], FEEL_CustomCursor_ID);
    }

    if (get_flags (config->feel->set_flags, FEEL_ClickToRaise))
        Bitlist2FreeStorage( &FeelSyntax, tail, config->feel->RaiseButtons, FEEL_ClickToRaise_ID);

    if (get_flags (config->feel->set_flags, FEEL_EdgeScroll))
        Integer2FreeStorage( &FeelSyntax, tail, &(config->feel->EdgeScrollX), config->feel->EdgeScrollY, FEEL_EdgeScroll_ID);
    if (get_flags (config->feel->set_flags, FEEL_EdgeResistance))
        Integer2FreeStorage( &FeelSyntax, tail, &(config->feel->EdgeResistanceScroll), config->feel->EdgeResistanceMove, FEEL_EdgeResistance_ID);

    /* complex functions : */
    if( config->feel->funcs_list )
        if( config->feel->funcs_list->items_num )
        {
            ComplexFunction **list ;

            list = safecalloc( config->feel->funcs_list->items_num, sizeof(ComplexFunction*));
            if( (i = sort_hash_items( config->feel->funcs_list, NULL, (void**)list, 0 )) > 0 )
                while ( --i >= 0 )
                    tail = ComplexFunction2FreeStorage( &FeelSyntax, tail, list[i]);
            free( list );
        }
    /* menus */
    /* menus writing require additional work due to the nature of the problem -
     * menus can come from file or directory or from feel file itself.
     * plus there has to be some mechanismus in place in order to preserve
     * .include configuration when menu is saved as directory.
     *          Sasha.
     */
    /* this is preliminary code that only saves menus into feel file itself  - make sure
     * you remove all the other menus from the feel->menus_list prior to calling this */
    if( config->feel->menus_list )
        if( config->feel->menus_list->items_num )
        {
            MenuData **list ;
            register int i ;
            list = safecalloc( config->feel->menus_list->items_num, sizeof(MenuData*));
            if( (i = sort_hash_items( config->feel->menus_list, NULL, (void**)list, 0 )) > 0 )
                while ( --i >= 0 )
                    tail = MenuData2FreeStorage( &FeelSyntax, tail, list[i]);
            free( list );
        }
    /* mouse bindings : */
    for( i = 0 ; i < MAX_MOUSE_BUTTONS+1 ; i++ )
    {
        char btn_id[2] ;
        btn_id[0] = '0'+i ;
        btn_id[1] = '\0' ;
        tail = Contexts2FreeStorage( &FeelSyntax, tail, btn_id, &(config->feel->mouse[i]), FEEL_Mouse_ID );
    }

    /* keyboard bindings : */
    if( config->feel->keyboard )
        if( config->feel->keyboard->items_num > 0 )
        {
            ASHashableValue  *keys;
            ASInputContexts **contexts;
            unsigned int items_num = config->feel->keyboard->items_num ;

            keys = safecalloc( items_num, sizeof(ASHashableValue) );
            contexts = safecalloc( items_num, sizeof(ASInputContexts*) );
            items_num = sort_hash_items( config->feel->keyboard, keys, (void**)contexts, 0 );
            for( i = 0 ; i < items_num ; i++ )
            {
                KeySym keysym = (KeySym)keys[i];
                tail = Contexts2FreeStorage( &FeelSyntax, tail, XKeysymToString(keysym), contexts[i], FEEL_Key_ID );
            }
        }

    /* writing config into the file */
	WriteConfig (ConfigWriter, Storage, CDT_Filename, (void **) &filename, flags);
	DestroyFreeStorage (&Storage);
    DestroyConfig (ConfigWriter);

	if (Storage)
  	{
    	fprintf (stderr,
	  		     "\n%s:Config Writing warning: Not all Free Storage discarded! Trying again...",
	      		 myname);
    	DestroyFreeStorage (&Storage);
  		fprintf (stderr, (Storage != NULL) ? " failed." : " success.");
    }
	return 0;
}
コード例 #23
0
/* NULL terminated list of names/aliases sorted in order of descending importance */
ASDatabaseRecord *
fill_asdb_record (ASDatabase * db, char **names, ASDatabaseRecord * reusable_memory, Bool dup_strings)
{
	ASDatabaseRecord *db_rec = NULL;

	if (db && names)
	{
		if (reusable_memory)
		{
			db_rec = reusable_memory;
			memset (db_rec, 0x00, sizeof (ASDatabaseRecord));
		} else
			db_rec = (ASDatabaseRecord *) safecalloc (1, sizeof (ASDatabaseRecord));

		db_rec->magic = MAGIC_ASDBRECORD;

		/* TODO : */
		/* build list of matching styles in order of descending importance */
		if (build_matching_list (db, names))
		{									   /* go through the list trying to extract as much data as possible  */
			register int  i;

			match_flags (&(db_rec->set_flags), &(db_rec->flags), db, MATCH_Flags);
			if (get_flags (db_rec->set_flags, STYLE_BUTTONS))
				match_flags (&(db_rec->set_buttons), &(db_rec->buttons), db, MATCH_Buttons);

			match_data_flags (&(db_rec->set_data_flags), db);
			
			if (get_flags (db_rec->set_data_flags, STYLE_STARTUP_DESK))
				db_rec->desk = match_int (db, MATCH_Desk);
			if (get_flags (db_rec->set_data_flags, STYLE_LAYER))
				db_rec->layer = match_int (db, MATCH_layer);
			if (get_flags (db_rec->set_data_flags, STYLE_VIEWPORTX))
			{
				LOCAL_DEBUG_OUT( "Matching viewport_x%s","");	  
				db_rec->viewport_x = match_int (db, MATCH_ViewportX);
			}
			if (get_flags (db_rec->set_data_flags, STYLE_VIEWPORTY))
				db_rec->viewport_y = match_int (db, MATCH_ViewportY);
			if (get_flags (db_rec->set_data_flags, STYLE_BORDER_WIDTH))
				db_rec->border_width = match_int (db, MATCH_border_width);
			if (get_flags (db_rec->set_data_flags, STYLE_HANDLE_WIDTH))
				db_rec->resize_width = match_int (db, MATCH_resize_width);
			if (get_flags (db_rec->set_data_flags, STYLE_GRAVITY))
				db_rec->gravity = match_int (db, MATCH_gravity);
			if (get_flags (db_rec->set_data_flags, STYLE_WINDOW_OPACITY))
				db_rec->window_opacity = match_int (db, MATCH_window_opacity);

			if (get_flags (db_rec->set_data_flags, STYLE_DEFAULT_GEOMETRY))
				db_rec->default_geometry = *((ASGeometry *) match_struct (db, MATCH_DefaultGeometry));

			if (get_flags (db_rec->set_data_flags, STYLE_ICON))
				db_rec->icon_file = match_string (db, MATCH_Icon, 0, dup_strings);
			if (get_flags (db_rec->set_data_flags, STYLE_FRAME))
				db_rec->frame_name = match_string (db, MATCH_Frame, 0, dup_strings);
			if (get_flags (db_rec->set_data_flags, STYLE_WINDOWBOX))
				db_rec->windowbox_name = match_string (db, MATCH_Windowbox, 0, dup_strings);
			if (get_flags (db_rec->set_flags, STYLE_MYSTYLES))
				for (i = 0; i < BACK_STYLES; i++)
					if (db_rec->window_styles[i])
						db_rec->window_styles[i] = match_string (db, MATCH_MyStyle, i, dup_strings);
		}
	}
	return db_rec;
}
コード例 #24
0
static inline ASDeskSession *
create_desk_session ()
{
	ASDeskSession *session = (ASDeskSession *) safecalloc (1, sizeof (ASDeskSession));
	return session;
}
コード例 #25
0
ASDatabaseRecord *
make_asdb_record (name_list * nl, struct wild_reg_exp *regexp, ASDatabaseRecord * reusable_memory)
{
	ASDatabaseRecord *db_rec = NULL;
	register int  i;

	if (nl)
	{
		if (reusable_memory)
		{
			db_rec = reusable_memory;
			memset (db_rec, 0x00, sizeof (ASDatabaseRecord));
		} else
			db_rec = (ASDatabaseRecord *) safecalloc (1, sizeof (ASDatabaseRecord));

		db_rec->magic = MAGIC_ASDBRECORD;

		db_rec->regexp = regexp;

		db_rec->set_flags = nl->set_flags;
		db_rec->flags = nl->flags;
		db_rec->set_data_flags = nl->set_data_flags;
		/* TODO: implement set_buttons/buttons in name_list as well */
		db_rec->set_buttons = nl->on_buttons | nl->off_buttons;
		db_rec->buttons = nl->on_buttons;

		if (db_rec->set_buttons != 0)
			set_flags (db_rec->set_flags, STYLE_BUTTONS);

		db_rec->default_geometry = nl->default_geometry;
		db_rec->desk = nl->Desk;
		db_rec->layer = nl->layer;
		db_rec->viewport_x = nl->ViewportX;
		LOCAL_DEBUG_OUT( "nl->name = \"%s\", nl->ViewportX = %d", nl->name, nl->ViewportX );
		db_rec->viewport_y = nl->ViewportY;
		db_rec->border_width = nl->border_width;
		db_rec->resize_width = nl->resize_width;
		db_rec->gravity = nl->gravity;
		db_rec->window_opacity = nl->window_opacity;

		if (nl->icon_file)
		{
			db_rec->icon_file = nl->icon_file;
			nl->icon_file = NULL;
		}
		if (nl->frame_name)
		{
			db_rec->frame_name = nl->frame_name;
			nl->frame_name = NULL;
		}
		if (nl->windowbox_name)
		{
			db_rec->windowbox_name = nl->windowbox_name;
			nl->windowbox_name = NULL;
		}
		for (i = 0; i < BACK_STYLES; i++)
			if (nl->window_styles[i])
			{
				db_rec->window_styles[i] = nl->window_styles[i];
				nl->window_styles[i] = NULL;
				set_flags (db_rec->set_flags, STYLE_MYSTYLES);
			}
		db_rec->own_strings = True;
	}
	return db_rec;
}
コード例 #26
0
ファイル: interface.c プロジェクト: cooljeanius/AfterStep
void
on_make_xml_clicked(GtkButton *clicked_button, gpointer user_data)
{
	ASGtkImageDir *id = ASGTK_IMAGE_DIR(user_data);
	ASGtkMakeXMLDlg *mx = safecalloc( 1, sizeof( ASGtkMakeXMLDlg ) );
	GtkWidget *frame, *box, *box2 ;
	Bool files_added = False; 
	int response ;
	const char *name ;
		
	mx->entry = asgtk_image_dir_get_selection( id );
	if( mx->entry == NULL ) 
	{
		free( mx ); 	  
		return;
	}
	mx->dlg = gtk_dialog_new_with_buttons( "Making new XML based on selected image", 
											GTK_WINDOW(WallpaperState.main_window),
										   	GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, 
											GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
											GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
											NULL
										  );
//	g_signal_connect_swapped (  GTK_OBJECT (mx->dlg), "response",              
//								G_CALLBACK (gtk_widget_destroy), GTK_OBJECT (mx->dlg));
    gtk_container_set_border_width (GTK_CONTAINER (mx->dlg), 5);
    //gtk_widget_set_size_request (mx->dlg, 400, 300);

	mx->scale_check_box = gtk_check_button_new_with_label( "Scale image to screen size" );
	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(mx->scale_check_box), TRUE );
	colorize_gtk_widget( mx->scale_check_box, get_colorschemed_style_normal() );
    gtk_box_pack_start (GTK_BOX (GTK_DIALOG(mx->dlg)->vbox), mx->scale_check_box, FALSE, FALSE, 0);

	mx->color_check_box = gtk_check_button_new_with_label( "Adjust image color based on selected Color Scheme." );
	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(mx->color_check_box), TRUE );
	//colorize_gtk_widget( mx->color_check_box, get_colorschemed_style_normal() );
    //gtk_box_pack_start (GTK_BOX (GTK_DIALOG(mx->dlg)->vbox), mx->color_check_box, FALSE, FALSE, 0);
	
	g_signal_connect ((gpointer) mx->color_check_box, "clicked", G_CALLBACK (set_make_xml_widgets_sensitive), mx);

		   
	frame = gtk_frame_new(NULL);
    gtk_box_pack_start (GTK_BOX (GTK_DIALOG(mx->dlg)->vbox), frame, FALSE, FALSE, 5);
	gtk_frame_set_label_widget( GTK_FRAME(frame), mx->color_check_box );

	box = gtk_vbox_new( TRUE, 5 );
	gtk_container_add (GTK_CONTAINER (frame), box);
	gtk_container_set_border_width (GTK_CONTAINER (box), 5);

	mx->tint_radio = gtk_radio_button_new_with_label( NULL, "Use Tinting (suitable for mostly grayscale images)" );
	gtk_box_pack_start (GTK_BOX (box), mx->tint_radio, FALSE, FALSE, 0);
	mx->hsv_radio = gtk_radio_button_new_with_label_from_widget( GTK_RADIO_BUTTON(mx->tint_radio), "Use Hue rotation (suitable for colorfull images)" );
	gtk_box_pack_start (GTK_BOX (box), mx->hsv_radio, FALSE, FALSE, 0);
	colorize_gtk_widget( frame, get_colorschemed_style_normal() );
	gtk_widget_show_all (box);
	gtk_widget_show (box);
	   
	mx->border_check_box = gtk_check_button_new_with_label( "Draw Border around the image" );
	gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(mx->border_check_box), TRUE );
	colorize_gtk_widget( mx->border_check_box, get_colorschemed_style_normal() );

	g_signal_connect ((gpointer) mx->border_check_box, "clicked", G_CALLBACK (set_make_xml_widgets_sensitive), mx);    
	
	frame = gtk_frame_new(NULL);
    gtk_box_pack_start (GTK_BOX (GTK_DIALOG(mx->dlg)->vbox), frame, FALSE, FALSE, 5);
	gtk_frame_set_label_widget( GTK_FRAME(frame), mx->border_check_box );

	box = gtk_vbox_new( TRUE, 5 );
	gtk_container_set_border_width (GTK_CONTAINER (box), 5);
	gtk_container_add (GTK_CONTAINER (frame), box);

	mx->solid_check_box = gtk_check_button_new_with_label( "Draw solid bevel" );
	gtk_box_pack_start (GTK_BOX (box), mx->solid_check_box, FALSE, FALSE, 0);

	box2 = gtk_hbox_new( FALSE, 5 );
	gtk_box_pack_start (GTK_BOX (box), box2, TRUE, TRUE, 0);

	mx->single_color_check_box = gtk_check_button_new_with_label( "Use single color" );
	gtk_box_pack_start (GTK_BOX (box2), mx->single_color_check_box, FALSE, FALSE, 0); 
	mx->outline_check_box  = gtk_check_button_new_with_label( "Outline image" );
	gtk_box_pack_start (GTK_BOX (box2), mx->outline_check_box, FALSE, FALSE, 0); ; 
	
	gtk_widget_show_all (box2);
	
	box2 = gtk_hbox_new( FALSE, 5 );
	gtk_box_pack_start (GTK_BOX (box), box2, TRUE, TRUE, 0);

	gtk_box_pack_start (GTK_BOX (box2), gtk_label_new("Border width : "), FALSE, FALSE, 0);
	mx->border_width = gtk_spin_button_new_with_range( 1.0, Scr.MyDisplayWidth/2, 1.0 ); 
	gtk_box_pack_start (GTK_BOX (box2), mx->border_width, FALSE, FALSE, 0);
	gtk_widget_show_all (box2);
	
	colorize_gtk_widget( frame, get_colorschemed_style_normal() );
	gtk_widget_show_all (box);
	gtk_widget_show (box);
	
	box2 = gtk_hbox_new( FALSE, 5 );
	gtk_container_set_border_width (GTK_CONTAINER (box2), 5);
	gtk_box_pack_start (GTK_BOX (GTK_DIALOG(mx->dlg)->vbox), box2, FALSE, FALSE, 0);
	gtk_box_pack_start (GTK_BOX (box2), gtk_label_new("New Background name : "), FALSE, FALSE, 0);
	mx->back_name = gtk_entry_new(); 
	gtk_box_pack_start (GTK_BOX (box2), mx->back_name, TRUE, TRUE, 0);
	gtk_widget_show_all (box2);

	gtk_widget_show_all (mx->dlg);

	do
	{	
		response = gtk_dialog_run( GTK_DIALOG(mx->dlg) );
		if( response == GTK_RESPONSE_ACCEPT ) 
		{	
			name = gtk_entry_get_text( GTK_ENTRY(mx->back_name) );
			if( name == NULL || strlen(name) == 0 ) 
				asgtk_warning2( WallpaperState.main_window, "Empty name specified for a new background.", NULL, NULL ); 	   				   		   			   			
			else
				break;
		}
	}while( response == GTK_RESPONSE_ACCEPT ); 
	if( response == GTK_RESPONSE_ACCEPT ) 
	{
		if( make_xml_from_image( mx, id ) ) 
		{
			files_added = True ;	  
			make_minixml_from_image( mx, id ); 
		}
	}	 
	if( files_added ) 
		asgtk_info2( WallpaperState.main_window, "New background \"%s\" file created.", name, NULL );	  
	
	make_xml_dlg_destroy( mx );
	if( files_added ) 
		asgtk_image_dir_refresh( id );
}
コード例 #27
0
ファイル: audit.c プロジェクト: Remmy/afterstep
void
count_alloc (const char *fname, int line, void *ptr, size_t length, int type)
{
    mem          *m = NULL;
	ASHashResult  res ;
	ASHashData hdata = {0};

    if( service_mode > 0 )
		return ;
	if( allocs_hash == NULL )
	{
		service_mode++ ;
		allocs_hash = create_ashash( 256, pointer_hash_value, NULL, mem_destroy );
		fprintf( stderr, "MEMORY AUDIT: count_alloc() called from %s:%d: allocs hash table created with pointer %p\n", fname, line, allocs_hash );
		service_mode-- ;
	}else if( ptr == allocs_hash ) 
		return;		

	if( get_hash_item( allocs_hash, (ASHashableValue)ptr, &hdata.vptr ) == ASH_Success )
	{
		m = (mem*)hdata.vptr ;
		if( type != (C_MEM|C_ADD_HASH_OPTIONAL_ITEM) )
		{	
			show_error( "Same pointer value 0x%lX is being counted twice!\n  Called from %s:%d - previously allocated in %s:%d", (unsigned long)ptr, fname, line, m->fname, m->line );
			print_simple_backtrace();
#ifdef DEBUG_ALLOC_STRICT
			{	char *segv = NULL ;	*segv = 0 ;  }
#endif
		}else
			return ;
	}else if( deallocated_used > 0 )
    {
        m = deallocated_mem[--deallocated_used];
/*        show_warning( "<mem> reusing deallocation cache  - element %d, pointer %p auditing service memory used (%lu )\n   Called from %s:%d",
                        deallocated_used, m, total_service, fname, line );
 */ }else
    {
		m = safecalloc (1, sizeof (mem));
        if( total_service+sizeof(mem) > AUDIT_SERVICE_MEM_LIMIT )
        {
            show_error( "<mem> too much auditing service memory used (%lu - was %lu)- aborting, please investigate.\n   Called from %s:%d",
                        total_service+sizeof(mem), total_service, fname, line );
            print_simple_backtrace();
			output_unfreed_mem (stderr);
#ifdef DEBUG_ALLOC_STRICT
{	char *segv = NULL ;	*segv = 0 ;  }
#endif
            exit(0);
        }
        total_service += sizeof(mem);
        if( total_service > max_service )
            max_service = total_service ;
    }
    m->fname = fname;
	m->line = line;
	m->length = length;
	m->type = type;
	m->ptr = ptr;
	m->freed = 0;

	allocations++;
	if ((type & 0xff) == C_MEM)
	{
		total_alloc += length;
		if (total_alloc > max_alloc)
			max_alloc = total_alloc;
	} else
	{
		total_x_alloc += length;
		if (total_x_alloc > max_x_alloc)
			max_x_alloc = total_x_alloc;
	}
	if (allocations - deallocations > max_allocations)
		max_allocations = allocations - deallocations;

	if( (res = add_hash_item( allocs_hash, (ASHashableValue)ptr, m )) != ASH_Success )
		show_error( "failed to log allocation for pointer 0x%lX - result = %d", ptr, res);
    else
    {
        if( total_service+sizeof(ASHashItem) > AUDIT_SERVICE_MEM_LIMIT )
        {
            show_error( "<add_hash_item> too much auditing service memory used (%lu - was %lu)- aborting, please investigate.\n   Called from %s:%d",
                        total_service+sizeof(ASHashItem), total_service, fname, line );
            print_simple_backtrace();
#ifdef DEBUG_ALLOC_STRICT
{	char *segv = NULL ;	*segv = 0 ;  }
#endif
            exit(0);
        }
        total_service += sizeof(ASHashItem);
        if( total_service > max_service )
            max_service = total_service ;
    }
}
コード例 #28
0
ファイル: reqs.c プロジェクト: OPSF/uClinux
/*
 * Break the request line apart and figure out where to connect and
 * build a new request line. Finally connect to the remote server.
 */
static struct request_s *
process_request(struct conn_s *connptr, hashmap_t hashofheaders)
{
	char *url;
	struct request_s *request;

	int ret;

	size_t request_len;

	/* NULL out all the fields so frees don't cause segfaults. */
	request = safecalloc(1, sizeof(struct request_s));
	if (!request)
		return NULL;

	request_len = strlen(connptr->request_line) + 1;

	request->method = safemalloc(request_len);
	url = safemalloc(request_len);
	request->protocol = safemalloc(request_len);

	if (!request->method || !url || !request->protocol) {
		safefree(url);
		free_request_struct(request);

		return NULL;
	}

	ret =
	    sscanf(connptr->request_line, "%[^ ] %[^ ] %[^ ]",
		   request->method, url, request->protocol);
	if (ret < 2) {
		log_message(LOG_ERR,
			    "process_request: Bad Request on file descriptor %d",
			    connptr->client_fd);
		indicate_http_error(connptr, 400, "Bad Request",
				    "detail", "Request has an invalid format",
				    "url", url,
				    NULL);

		safefree(url);
		free_request_struct(request);

		return NULL;
	}

	/* 
	 * FIXME: We need to add code for the simple HTTP/0.9 style GET
	 * request.
	 */

	if (!url) {
		log_message(LOG_ERR,
			    "process_request: Null URL on file descriptor %d",
			    connptr->client_fd);
		indicate_http_error(connptr, 400, "Bad Request",
				    "detail", "Request has an empty URL",
				    "url", url,
				    NULL);

		safefree(url);
		free_request_struct(request);

		return NULL;
	}

	if (strncasecmp(url, "http://", 7) == 0
	    || (UPSTREAM_CONFIGURED() && strncasecmp(url, "ftp://", 6) == 0)) {
		char *skipped_type = strstr(url, "//") + 2;

		if (extract_http_url(skipped_type, request) < 0) {
			indicate_http_error(connptr, 400, "Bad Request",
					    "detail", "Could not parse URL",
					    "url", url,
					    NULL);

			safefree(url);
			free_request_struct(request);

			return NULL;
		}
	} else if (strcmp(request->method, "CONNECT") == 0) {
		if (extract_ssl_url(url, request) < 0) {
			indicate_http_error(connptr, 400, "Bad Request",
					    "detail", "Could not parse URL",
					    "url", url,
					    NULL);

			safefree(url);
			free_request_struct(request);

			return NULL;
		}

		/* Verify that the port in the CONNECT method is allowed */
		if (check_allowed_connect_ports(request->port) <= 0) {
			indicate_http_error(connptr, 403, "Access violation",
					    "detail", "The CONNECT method not allowed " \
					              "with the port you tried to use.",
					    "url", url,
					    NULL);
			log_message(LOG_INFO, "Refused CONNECT method on port %d",
				    request->port);

			safefree(url);
			free_request_struct(request);

			return NULL;
		}
		
		connptr->connect_method = TRUE;
	} else {
#ifdef TRANSPARENT_PROXY
		/*
		 * This section of code is used for the transparent proxy
		 * option.  You will need to configure your firewall to
		 * redirect all connections for HTTP traffic to tinyproxy
		 * for this to work properly.
		 *
		 * This code was written by Petr Lampa <*****@*****.**>
		 */
		int length;
		char *data;
		length = hashmap_entry_by_key(hashofheaders, "host", (void **)&data);
		if (length <= 0) {
			struct sockaddr_in dest_addr;

			if (getsockname(connptr->client_fd, (struct sockaddr *)&dest_addr, &length) < 0) {
				log_message(LOG_ERR,
					    "process_request: cannot get destination IP for %d",
					    connptr->client_fd);
				indicate_http_error(connptr, 400, "Bad Request",
						    "detail", "Unknown destination",
						    "url", url,
						    NULL);
				safefree(url);
				free_request_struct(request);
				return NULL;
			} 
			request->host = safemalloc(17);
			strcpy(request->host, inet_ntoa(dest_addr.sin_addr));
			request->port = ntohs(dest_addr.sin_port);
			request->path = safemalloc(strlen(url) + 1);
			strcpy(request->path, url);
			safefree(url);
			build_url(&url, request->host, request->port, request->path);
			log_message(LOG_INFO,
				    "process_request: trans IP %s %s for %d",
				    request->method, url, connptr->client_fd);
		} else {
			request->host = safemalloc(length+1);
			if (sscanf(data, "%[^:]:%hu", request->host, &request->port) != 2) {
				strcpy(request->host, data);
				request->port = HTTP_PORT;
			}
			request->path = safemalloc(strlen(url) + 1);
			strcpy(request->path, url);
			safefree(url);
			build_url(&url, request->host, request->port, request->path);
			log_message(LOG_INFO,
				    "process_request: trans Host %s %s for %d",
				    request->method, url, connptr->client_fd);
		}
		if (config.ipAddr &&
		    strcmp(request->host, config.ipAddr) == 0) {
			log_message(LOG_ERR,
				    "process_request: destination IP is localhost %d",
				    connptr->client_fd);
			indicate_http_error(connptr, 400, "Bad Request",
					    "detail", "You tried to connect to the machine the proxy is running on",
					    "url", url,
					    NULL);
			safefree(url);
			free_request_struct(request);
			return NULL;
		}
#else
		log_message(LOG_ERR,
			    "process_request: Unknown URL type on file descriptor %d",
			    connptr->client_fd);
		indicate_http_error(connptr, 400, "Bad Request",
				    "detail", "Unknown URL type",
				    "url", url,
				    NULL);

		safefree(url);
		free_request_struct(request);

		return NULL;
#endif
	}

#ifdef FILTER_ENABLE
	/*
	 * Filter restricted domains/urls
	 */
	if (config.filter) {
		if (config.filter_url)
			ret = filter_url(url);
		else
			ret = filter_domain(request->host);

		if (ret) {
			update_stats(STAT_DENIED);

			if (config.filter_url)
				log_message(LOG_NOTICE,
					    "Proxying refused on filtered url \"%s\"",
					    url);
			else
				log_message(LOG_NOTICE,
					    "Proxying refused on filtered domain \"%s\"",
					    request->host);

			indicate_http_error(connptr, 403, "Filtered",
					    "detail", "The request you made has been filted",
					    "url", url,
					    NULL);

			safefree(url);
			free_request_struct(request);

			return NULL;
		}
	}
#endif

	safefree(url);

	/*
	 * Check to see if they're requesting the stat host
	 */
	if (config.stathost && strcmp(config.stathost, request->host) == 0) {
		log_message(LOG_NOTICE, "Request for the stathost.");
		connptr->show_stats = TRUE;

		free_request_struct(request);
		return NULL;
	}

	/*
	 * Break apart the protocol and update the connection structure.
	 */
	if (strncasecmp(request->protocol, "http", 4) == 0) {
		memcpy(request->protocol, "HTTP", 4);
		sscanf(request->protocol, "HTTP/%u.%u",
		       &connptr->protocol.major, &connptr->protocol.minor);
	}

	return request;
}
コード例 #29
0
void 
gen_glossary( const char *dest_dir, const char *file, ASDocType doc_type )
{
	ASXMLInterpreterState state;
	LOCAL_DEBUG_OUT( "Glossary has %ld items", Glossary->items_num);
	if( (doc_type == DocType_HTML	|| doc_type == DocType_PHP ) && Glossary->items_num > 0 )
	{	
		ASHashableValue *values;
		ASHashData *data;
		int items_num, col_length, i ;
		int col_end[3], col_curr[3], col_count = 3 ;
		Bool has_items = True, col_skipped[3] = {True, True, True};
		char c = '\0' ; 
				
		if( !start_doc_file( dest_dir, file, NULL, doc_type, NULL, NULL, NULL, &state, DOC_CLASS_None, DocClass_Glossary ) )	 
			return ;
		
		LOCAL_DEBUG_OUT( "sorting hash items : ... %s", "" );
		values = safecalloc( Glossary->items_num, sizeof(ASHashableValue));
		data = safecalloc( Glossary->items_num, sizeof(ASHashData));
		items_num = sort_hash_items (Glossary, values, (void**)data, 0);
		
		fprintf( state.dest_fp, "<p>\n" );
		for( i = 0 ; i < items_num ; ++i ) 
		{
			if( ((char*)values[i])[0] != c ) 
			{
				c = ((char*)values[i])[0] ;
				fprintf( state.dest_fp, "<A href=\"#glossary_%c\">%c</A> ", c, c );
			}	 
		}	 
		fprintf( state.dest_fp, "<hr>\n<p><table width=100%% cellpadding=0 cellspacing=0>\n" );
		
		if( state.doc_type == DocType_PHP	)
			col_count = 2 ;
		col_length = (items_num+col_count-1)/col_count ;

		col_curr[0] = 0 ; 
		col_end[0] = col_curr[1] = col_length ;
		col_end[1] = col_curr[2] = col_length*2 ;
		col_end[2] = items_num ;

		while( has_items )
		{
			int col ;
			fprintf( state.dest_fp, "<TR>" );
			has_items = False ; 
			for( col = 0 ; col < col_count ; ++col )
			{		
				int item = col_curr[col] ; 
				fprintf( state.dest_fp, "<TD width=33%% valign=top>" );
				if( item < col_end[col] && item < items_num ) 		   
				{	
					has_items = True ;
					col_skipped[col] = !col_skipped[col] && item > 0 && ((char*)values[item])[0] != ((char*)values[item-1])[0] ;
					if( !col_skipped[col] )
					{	  
						if( state.doc_type == DocType_HTML	)
							fprintf( state.dest_fp, "<A href=\"%s\">%s</A>", data[item].cptr, (char*)values[item] );
						else if( doc_type == DocType_PHP ) 
							fprintf( state.dest_fp, PHPXrefFormat, "visualdoc",(char*)values[item], data[item].cptr, "" );
						++(col_curr[col]) ; 
						col_skipped[col] = False ;
					}else
						fprintf( state.dest_fp, "<A name=\"glossary_%c\"> </A>", ((char*)values[item])[0] );
				}
				fprintf( state.dest_fp, " </TD>" );
			}
			fprintf( state.dest_fp, "</TR>\n" );
		}	 
		fprintf( state.dest_fp, "</table>\n" );
		
		free( data );
		free( values );
		end_doc_file( &state );	 	  
	}
}
コード例 #30
0
ファイル: main.c プロジェクト: Remmy/afterstep
ASVolume *ASVolume_create ()
{
	ASVolume *v;
	v = safecalloc (1, sizeof(ASVolume));
	return v;
}