Ejemplo n.º 1
0
static void mime_state_push(MIME_STATE *state, int def_ctype, int def_stype,
			            const char *boundary)
{
    MIME_STACK *stack;

    /*
     * RFC 2046 mandates that a boundary string be up to 70 characters long.
     * Some MTAs, including Postfix, include the fully-qualified MTA name
     * which can be longer, so we are willing to handle boundary strings that
     * exceed the RFC specification. We allow for message headers of up to
     * var_header_limit characters. In order to avoid denial of service, we
     * have to impose a configurable limit on the amount of text that we are
     * willing to store as a boundary string. Despite this truncation way we
     * will still correctly detect all intermediate boundaries and all the
     * message headers that follow those boundaries.
     */
    state->nesting_level += 1;
    stack = (MIME_STACK *) mymalloc(sizeof(*stack));
    stack->def_ctype = def_ctype;
    stack->def_stype = def_stype;
    if ((stack->bound_len = strlen(boundary)) > var_mime_bound_len)
	stack->bound_len = var_mime_bound_len;
    stack->boundary = mystrndup(boundary, stack->bound_len);
    stack->next = state->stack;
    state->stack = stack;
    if (msg_verbose)
	msg_info("PUSH boundary %s", stack->boundary);
}
Ejemplo n.º 2
0
char* countadd_mystrndup(const char *fname, int line, const char *a, int len)
{
	char *ptr = mystrndup(a, len );

    if( a != NULL )
		count_alloc (fname, line, ptr, strlen(ptr)+1, C_MEM | C_MYSTRNDUP);
	return ptr;
}
Ejemplo n.º 3
0
char *strip_extension( char *name, char *ext )
{
	if( name && ext )
	{
		int           nlen = strlen (name);
		int           elen = strlen (ext);

		if (nlen >= elen)
		{
			if (!strcmp (name + nlen - elen, ext))
				return mystrndup(name, nlen - elen);
			else if (!strncmp (name, ext, elen))
				return mystrndup(name+elen, nlen - elen);
		}
	}
	return name;
}
Ejemplo n.º 4
0
char *
mydirname(char *filename)
{                               /* determine directory component of "name" */
  char *p;

  /* find last '/' in name (if any) */
  for (p = filename + strlen(filename) - 1; p > filename; p--)
    if (*(p - 1) == '/')
      break;
  return (p == filename ? "." : mystrndup(filename, p - filename));
}
Ejemplo n.º 5
0
static char *strip_name_value (char *parm)
{
	if (parm) {
		int parm_len = strlen (parm);

		if (parm_len > 7 && strncmp (parm, "name=\"", 6) == 0) {
			return mystrndup (parm + 6, parm_len - 7);
		}
	}
	return NULL;
}
Ejemplo n.º 6
0
DICT   *dict_random_open(const char *name, int open_flags, int dict_flags)
{
    DICT_RANDOM *dict_random;
    char   *saved_name = 0;
    size_t  len;

    /*
     * Clarity first. Let the optimizer worry about redundant code.
     */
#define DICT_RANDOM_RETURN(x) do { \
	if (saved_name != 0) \
	    myfree(saved_name); \
	return (x); \
    } while (0)

    /*
     * Sanity checks.
     */
    if (open_flags != O_RDONLY)
	DICT_RANDOM_RETURN(dict_surrogate(DICT_TYPE_RANDOM, name,
					  open_flags, dict_flags,
				  "%s:%s map requires O_RDONLY access mode",
					  DICT_TYPE_RANDOM, name));

    /*
     * Split the name name into its constituent parts.
     */
    if ((len = balpar(name, "{}")) == 0 || name[len] != 0
	|| *(saved_name = mystrndup(name + 1, len - 2)) == 0)
	DICT_RANDOM_RETURN(dict_surrogate(DICT_TYPE_RANDOM, name,
					  open_flags, dict_flags,
					  "bad syntax: \"%s:%s\"; "
					  "need \"%s:{type:name...}\"",
					  DICT_TYPE_RANDOM, name,
					  DICT_TYPE_RANDOM));

    /*
     * Bundle up the result.
     */
    dict_random =
	(DICT_RANDOM *) dict_alloc(DICT_TYPE_RANDOM, name, sizeof(*dict_random));
    dict_random->dict.lookup = dict_random_lookup;
    dict_random->dict.close = dict_random_close;
    dict_random->dict.flags = dict_flags | DICT_FLAG_PATTERN;
    dict_random->replies = argv_splitq(saved_name, ", \t\r\n", "{}");
    dict_random->dict.owner.status = DICT_OWNER_TRUSTED;
    dict_random->dict.owner.uid = 0;

    DICT_RANDOM_RETURN(DICT_DEBUG (&dict_random->dict));
}
Ejemplo n.º 7
0
char	*ft_findpath(char **environ)
{
	int		i;
	char	*p;

	i = 0;
	p = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/texbin";
	while (environ[i] != '\0')
	{
		if (!(ft_strcmp(mystrndup(environ[i], ft_sc(environ[i], '=')), "PATH")))
			return (environ[i]);
		i++;
	}
	write(2, "no PATH -> Custom PATH -> done\n", 32);
	return (p);
}
Ejemplo n.º 8
0
int
atopixel (const char *val, int size)
{
	
  	int l = strlen (val);
	int res = 0; 
  	if (l >= 1)
	{	
  		if (val[l-1] == 'p' || val[l-1] == 'P' )
		{
			char *clean_val = mystrndup( val, l-1 );
			/* number was followed by a p/P
		 	* => number was already a pixel-value */
			res = atoi (clean_val);
		}else /* return s percent of size */
			res = (atoi (val) * size) / 100 ;
	}  	
	return res;
}
Ejemplo n.º 9
0
static void qmqpd_copy_sender(QMQPD_STATE *state)
{
    char   *end_prefix;
    char   *end_origin;
    int     verp_requested;
    static char verp_delims[] = "-=";

    /*
     * If the sender address looks like prefix@origin-@[], then request
     * variable envelope return path delivery, with an envelope sender
     * address of prefi@origin, and with VERP delimiters of x and =. This
     * way, the recipients will see envelope sender addresses that look like:
     * prefixuser=domain@origin.
     */
    state->where = "receiving sender address";
    netstring_get(state->client, state->buf, var_line_limit);
    VSTRING_TERMINATE(state->buf);
    verp_requested =
	((end_origin = vstring_end(state->buf) - 4) > STR(state->buf)
	 && strcmp(end_origin, "-@[]") == 0
	 && (end_prefix = strchr(STR(state->buf), '@')) != 0	/* XXX */
	 && --end_prefix < end_origin - 2	/* non-null origin */
	 && end_prefix > STR(state->buf));	/* non-null prefix */
    if (verp_requested) {
	verp_delims[0] = end_prefix[0];
	if (verp_delims_verify(verp_delims) != 0) {
	    state->err |= CLEANUP_STAT_CONT;	/* XXX */
	    vstring_sprintf(state->why_rejected, "Invalid VERP delimiters: \"%s\". Need two characters from \"%s\"",
			    verp_delims, var_verp_filter);
	}
	memmove(end_prefix, end_prefix + 1, end_origin - end_prefix - 1);
	vstring_truncate(state->buf, end_origin - STR(state->buf) - 1);
    }
    if (state->err == CLEANUP_STAT_OK
	&& REC_PUT_BUF(state->cleanup, REC_TYPE_FROM, state->buf) < 0)
	state->err = CLEANUP_STAT_WRITE;
    if (verp_requested)
	if (state->err == CLEANUP_STAT_OK
	    && rec_put(state->cleanup, REC_TYPE_VERP, verp_delims, 2) < 0)
	    state->err = CLEANUP_STAT_WRITE;
    state->sender = mystrndup(STR(state->buf), LEN(state->buf));
}
Ejemplo n.º 10
0
void    argv_addn(ARGV *argvp,...)
{
    char   *arg;
    ssize_t len;
    va_list ap;

    /*
     * Make sure that always argvp->argc < argvp->len.
     */
    va_start(ap, argvp);
    while ((arg = va_arg(ap, char *)) != 0) {
	if ((len = va_arg(ap, ssize_t)) < 0)
	    msg_panic("argv_addn: bad string length %ld", (long) len);
	if (ARGV_SPACE_LEFT(argvp) <= 0)
	    argv_extend(argvp);
	argvp->argv[argvp->argc++] = mystrndup(arg, len);
    }
    va_end(ap);
    argvp->argv[argvp->argc] = 0;
}
Ejemplo n.º 11
0
dirtree_t    *
dirtree_new_from_dir (const char *dir)
{
	
	dirtree_t    *tree = NULL ; 

	if( dir )
	{	
		char   *p;
		int start_mark = 0, end_mark ;
		register int i = 0 ;
		register char *ptr = (char*)dir ;
		tree = dirtree_new ();
	
		while( ptr[i] ) ++i ;
		end_mark = i ;

		p = tree->path = safemalloc( i+1 );
		do{ p[i] = ptr[i]; } while( --i >= 0 );
		while( --i > 0 )
			if( ptr[i] =='/' )
			{
				end_mark = i ;
				break ;
			}

		while( --i >= 0 )
			if( ptr[i] =='/' )
			{
				start_mark = i+1 ;
				break ;
			}
		tree->name = mystrndup (&(ptr[start_mark]), end_mark-start_mark);
		dirtree_fill_from_dir (tree);
	}
	return tree;
}
Ejemplo n.º 12
0
static void qmqpd_copy_recipients(QMQPD_STATE *state)
{
    int     ch;

    /*
     * Remember the first recipient. We are done when we read the over-all
     * netstring terminator.
     * 
     * XXX This approach violates abstractions, but it is a heck of a lot more
     * convenient than counting the over-all byte count down to zero, like
     * qmail does.
     */
    state->where = "receiving recipient address";
    while ((ch = VSTREAM_GETC(state->client)) != ',') {
	vstream_ungetc(state->client, ch);
	netstring_get(state->client, state->buf, var_line_limit);
	if (state->err == CLEANUP_STAT_OK
	    && REC_PUT_BUF(state->cleanup, REC_TYPE_RCPT, state->buf) < 0)
	    state->err = CLEANUP_STAT_WRITE;
	state->rcpt_count++;
	if (state->recipient == 0)
	    state->recipient = mystrndup(STR(state->buf), LEN(state->buf));
    }
}
Ejemplo n.º 13
0
char *
mysavestring(const char *string)
{
  assert(string != NULL);
  return mystrndup(string, strlen(string));
}
Ejemplo n.º 14
0
int     inet_addr_host(INET_ADDR_LIST *addr_list, const char *hostname)
{
    const char *myname = "inet_addr_host";
    int     sock;
    struct addrinfo *res0;
    struct addrinfo *res;
    int     aierr;
    ssize_t hostnamelen;
    const char *hname;
    const char *serv;
    int     initial_count = addr_list->used;
    INET_PROTO_INFO *proto_info;

    /*
     * The use of square brackets around an IPv6 addresses is required, even
     * though we don't enforce it as it'd make the code unnecessarily
     * complicated.
     * 
     * XXX AIX 5.1 getaddrinfo() does not allow "0" as service, regardless of
     * whether or not a host is specified.
     */
    if (*hostname == 0) {
	hname = 0;
	serv = "1";
    } else if (*hostname == '['
	       && hostname[(hostnamelen = strlen(hostname)) - 1] == ']') {
	hname = mystrndup(hostname + 1, hostnamelen - 2);
	serv = 0;
    } else {
	hname = hostname;
	serv = 0;
    }

    proto_info = inet_proto_info();
    if ((aierr = hostname_to_sockaddr(hname, serv, SOCK_STREAM, &res0)) == 0) {
	for (res = res0; res; res = res->ai_next) {

	    /*
	     * Safety net.
	     */
	    if (strchr((char *) proto_info->sa_family_list, res->ai_family) == 0) {
		msg_info("%s: skipping address family %d for host \"%s\"",
			 myname, res->ai_family, hostname);
		continue;
	    }

	    /*
	     * On Linux systems it is not unusual for user-land to be out of
	     * sync with kernel-land. When this is the case we try to be
	     * helpful and filter out address families that the library
	     * claims to understand but that are not supported by the kernel.
	     */
	    if ((sock = socket(res->ai_family, SOCK_STREAM, 0)) < 0) {
		msg_warn("%s: skipping address family %d: %m",
			 myname, res->ai_family);
		continue;
	    }
	    if (close(sock))
		msg_warn("%s: close socket: %m", myname);

	    inet_addr_list_append(addr_list, res->ai_addr);
	}
	freeaddrinfo(res0);
    }
    if (hname && hname != hostname)
	myfree((void *) hname);

    return (addr_list->used - initial_count);
}
Ejemplo n.º 15
0
Bool load_font (const char *name_in, MyFont * font)
#endif
{
	char *name;
	char *clean_name;
	int font_size = asxml_var_get ("font.size");

	if (font == NULL)
		return False;

	if (font_size <= 0)
		font_size = 14;

#if defined(LOG_FONT_CALLS) && defined(DEBUG_ALLOCS)
	log_call (file, line, "load_font", name);
#endif
	if (ASDefaultScr->font_manager == NULL) {
		char *path = getenv ("FONT_PATH");

		if (path == NULL)
			path = getenv ("PATH");
		ASDefaultScr->font_manager = create_font_manager (dpy, path, NULL);
	}

	name = name_in ? (char *)name_in : font->name;

	clean_name = name;
	if (clean_name != NULL) {
		int i = 0;
		register char *ptr = clean_name;

		while (ptr[i])
			++i;
		while (--i >= 0)
			if (!isdigit (ptr[i]))
				break;
		if ((isspace (ptr[i]) || ptr[i] == '-') && ptr[i + 1]) {
			font_size = atoi (&(ptr[i + 1]));
			while (i > 0 && isspace (ptr[i - 1]))
				--i;
			clean_name = mystrndup (name, i);
		}
	}
	if (clean_name != NULL) {
		if ((font->as_font =
				 get_asfont (ASDefaultScr->font_manager, clean_name, 0, font_size,
										 ASF_Freetype)) != NULL)
			show_progress ("Successfully loaded freetype font \"%s\"",
										 clean_name);
	}
	if (font->as_font == NULL && name != NULL) {
		if ((font->as_font =
				 get_asfont (ASDefaultScr->font_manager, name, 0, font_size,
										 ASF_GuessWho)) != NULL)
			show_progress ("Successfully loaded font \"%s\"", name);
	}
	if (font->as_font == NULL) {
		font->as_font =
				get_asfont (ASDefaultScr->font_manager, default_font, 0, font_size,
										ASF_GuessWho);
		show_warning ("failed to load font \"%s\" - using default instead",
									name);
	}

	if (clean_name && clean_name != name)
		free (clean_name);

	if (font->as_font != NULL && name != font->name)
		set_string (&(font->name), mystrdup (name));

	return (font->as_font != NULL);
}
Ejemplo n.º 16
0
xml_elem_t* load_KDE_config(const char* realfilename) 
{
	xml_elem_t* config = create_CONTAINER_tag();
	FILE *fp = fopen( realfilename, "r" );
	
	if( fp != NULL ) 
	{	
		char buffer[8192];
		xml_elem_t* group = NULL ; 
		
		while(fgets(&buffer[0], sizeof(buffer), fp) != NULL)
		{
			xml_elem_t* tag ; 
			int i = 0; 

			while( isspace(buffer[i]) ) ++i ;
			if( buffer[i] == '#' )
			{
				++i;
				if( (tag = make_kde_config_comment_tag()) != NULL )
				{	
					int len = strlen( &buffer[i] ) ;
					while( len > 0 && isspace( buffer[i+len-1] ) ) --len ;
					if( len > 0 ) 
					{
						tag->child = create_CDATA_tag();	  
						tag->child->parm = mystrndup( &buffer[i], len );
					}
					if( group == NULL ) 
					{
						group = make_kde_config_group_tag(NULL);		   
						config->child = group;
					}
					xml_insert( group, tag );
				}
			}else if( buffer[i] == '[' ) 
			{
				++i;
				if( (tag = make_kde_config_group_tag(&buffer[i])) != NULL )
				{	
					if( group ) 
						group->next = tag ; 
					else
						config->child = tag ;						
					group = tag ;
				}
			}else if( buffer[i] != '\0' )
			{
				int name_len ; 
				tag = make_kde_config_item_tag(&buffer[i], &name_len);
				if( tag ) 
				{              /* now we need to parse value and then possibly a comment : */
					char *val = stripcpy(&buffer[i+name_len+1] );
					if( group == NULL ) 
					{
						group = make_kde_config_group_tag(NULL);		   
						config->child = group;
					}

					xml_insert( group, tag );
					
					if( val ) 
					{
						if( val[0] != '\0' ) 
						{	
							tag->child = create_CDATA_tag();
							tag->child->parm = val ; 
						}else
							free( val );
					}	 
				}	 
			}			 
		}	 

		fclose( fp );
	}
	return config;
}
Ejemplo n.º 17
0
int main(int argc, char* argv[])
{
	Display *dpy = NULL;
	ASVisual *asv ;
	int screen = 0, depth = 0;
	int to_width = 1, to_height = 1;
	ASImageLayer *layers ;
	int layers_num = 0, i;
	ASImage *merged_im ;

	/* see ASView.1 : */
	set_application_name( argv[0] );
#if (HAVE_AFTERBASE_FLAG==1)
	set_output_threshold(OUTPUT_LEVEL_DEBUG);
#endif
	if( argc == 2 && strncmp(argv[1],"-h", 2) == 0 )
	{
		usage();
		return 0;
	}
	if( argc <= 3 )
	{
		show_error( "not enough arguments, please see usage:%s", " ");
		usage() ;
		printf( "Using the default, \"The Burning Rose\", composition :\n");
		printf( "\n\trose512.jpg add back.xpm:512x386 hue "
				"fore.xpm:512x386\n");
		argv = &(burning_rose[0]) ;
		argc = 6;
	}

#ifndef X_DISPLAY_MISSING
	dpy = XOpenDisplay(NULL);
	_XA_WM_DELETE_WINDOW = XInternAtom( dpy, "WM_DELETE_WINDOW", False);
	screen = DefaultScreen(dpy);
	depth = DefaultDepth( dpy, screen );
#endif
	/* see ASView.3 : */
	asv = create_asvisual( dpy, screen, depth, NULL );

	/* see ASMerge.1 : */
	layers = safecalloc( argc/2, sizeof(ASImageLayer) );

	for( i = 1 ; i < argc ; i++ )
	{
		int x = 0, y = 0;
		unsigned int width, height ;
		int geom_flags = 0 ;
		char *separator;
		char *filename ;
		/* see ASMerge.2 */
		if( i > 1 )
		{
			/* see blend_scanlines_name2func() : */
			if((layers[layers_num].merge_scanlines =
				 blend_scanlines_name2func( argv[i] )) == NULL )
				continue ;
			if( ++i >= argc )
				break;
		}
		if( (separator = strchr( argv[i], ':' )) != NULL )
		{   /* see ASTile.1 : */
			geom_flags = XParseGeometry( separator+1, 
										 &x, &y, &width, &height);
			filename = mystrndup( argv[i], separator-argv[i] );
		}else
			filename = argv[i] ;
		layers[layers_num].im = file2ASImage( filename, 0xFFFFFFFF,
			                                  SCREEN_GAMMA, 100, getenv("IMAGE_PATH"), NULL );
		if( filename != argv[i] )
			free( filename );
		if( layers[layers_num].im != NULL )
		{
		 	if( !get_flags(geom_flags, WidthValue) )
		 		width = layers[layers_num].im->width  ;
		 	if( !get_flags(geom_flags, HeightValue) )
		 		height = layers[layers_num].im->height ;
			/* see ASMerge.3 : */
			if( layers[layers_num].merge_scanlines == NULL )
				layers[layers_num].merge_scanlines =
					alphablend_scanlines ;
			layers[layers_num].clip_width = width ;
			layers[layers_num].clip_height = height ;
			if( layers_num > 0 )
			{
				layers[layers_num].dst_x = x ;
				layers[layers_num].dst_y = y ;
			}else
			{
				to_width = width ;
				to_height = height ;
				if( width != layers[layers_num].im->width ||
				    height != layers[layers_num].im->height )
				{
					ASImage *scaled_bottom ;
					/* see ASScale.2 : */
					scaled_bottom = scale_asimage( asv, 
												   layers[layers_num].im,
											  	   width, height, 
												   False, 100,
											  	ASIMAGE_QUALITY_DEFAULT );
					destroy_asimage( &(layers[layers_num].im) );
					layers[layers_num].im = scaled_bottom ;
				}
			}
			++layers_num ;
		}
	}

	if( layers_num <= 0 )
	{
		show_error( "there is no images to merge. Aborting");
		return 2;
	}

	/* see ASMerge.4 */
	merged_im = merge_layers( asv, layers, layers_num,
		                      to_width, to_height,
#ifndef X_DISPLAY_MISSING
							  ASA_XImage,
#else
							  ASA_ASImage,
#endif
							  0, ASIMAGE_QUALITY_DEFAULT );
	while( --layers_num >= 0 )
		destroy_asimage( &(layers[layers_num].im) );
	free( layers );

	if( merged_im )
	{
#ifndef X_DISPLAY_MISSING
	/* see ASView.4 : */
  		Window w = create_top_level_window( asv, DefaultRootWindow(dpy), 
											32, 32,
					                        to_width, to_height, 
											1, 0, NULL,
											"ASMerge", NULL );
		if( w != None )
		{
			Pixmap p ;

		  	XMapRaised   (dpy, w);
			/* see ASView.5 : */
			p = asimage2pixmap( asv, DefaultRootWindow(dpy), merged_im,
			                NULL, True );

			destroy_asimage( &merged_im );
			/* see common.c: set_window_background_and_free() : */
			p = set_window_background_and_free( w, p );
			/* see common.c: wait_closedown() : */
		}
		wait_closedown(w);
		dpy = NULL;
#else
		/* writing result into the file */
		ASImage2file( merged_im, NULL, "asmerge.jpg", ASIT_Jpeg, NULL );
		destroy_asimage( &merged_im );
#endif
	}
#ifdef DEBUG_ALLOCS
	build_xpm_colormap(NULL);
	print_unfreed_mem();
#endif
	return 0 ;
}
Ejemplo n.º 18
0
int     db_common_expand(void *ctxArg, const char *format, const char *value,
			         const char *key, VSTRING *result,
			         db_quote_callback_t quote_func)
{
    const char *myname = "db_common_expand";
    DB_COMMON_CTX *ctx = (DB_COMMON_CTX *) ctxArg;
    const char *vdomain = 0;
    const char *kdomain = 0;
    const char *domain = 0;
    int     dflag = key ? DB_COMMON_VALUE_DOMAIN : DB_COMMON_KEY_DOMAIN;
    char   *vuser = 0;
    char   *kuser = 0;
    ARGV   *parts = 0;
    int     i;
    const char *cp;

    /* Skip NULL values, silently. */
    if (value == 0)
	return (0);

    /* Don't silenty skip empty query string or empty lookup results. */
    if (*value == 0) {
	if (key)
	    msg_warn("table \"%s:%s\": empty lookup result for: \"%s\""
		     " -- ignored", ctx->dict->type, ctx->dict->name, key);
	else
	    msg_warn("table \"%s:%s\": empty query string"
		     " -- ignored", ctx->dict->type, ctx->dict->name);
	return (0);
    }
    if (key) {
	/* This is a result template and the input value is the result */
	if (ctx->flags & (DB_COMMON_VALUE_DOMAIN | DB_COMMON_VALUE_USER))
	    if ((vdomain = strrchr(value, '@')) != 0)
		++vdomain;

	if (((!vdomain || !*vdomain) && (ctx->flags & DB_COMMON_VALUE_DOMAIN) != 0)
	    || (vdomain == value + 1 && (ctx->flags & DB_COMMON_VALUE_USER) != 0))
	    return (0);

	/* The result format may use the local or domain part of the key */
	if (ctx->flags & (DB_COMMON_KEY_DOMAIN | DB_COMMON_KEY_USER))
	    if ((kdomain = strrchr(key, '@')) != 0)
		++kdomain;

	/*
	 * The key should already be checked before the query. No harm if the
	 * query did not get optimized out, so we just issue a warning.
	 */
	if (((!kdomain || !*kdomain) && (ctx->flags & DB_COMMON_KEY_DOMAIN) != 0)
	|| (kdomain == key + 1 && (ctx->flags & DB_COMMON_KEY_USER) != 0)) {
	    msg_warn("%s: %s: lookup key '%s' skipped after query", myname,
		     ctx->dict->name, value);
	    return (0);
	}
    } else {
	/* This is a query template and the input value is the lookup key */
	if (ctx->flags & (DB_COMMON_KEY_DOMAIN | DB_COMMON_KEY_USER))
	    if ((vdomain = strrchr(value, '@')) != 0)
		++vdomain;

	if (((!vdomain || !*vdomain) && (ctx->flags & DB_COMMON_KEY_DOMAIN) != 0)
	|| (vdomain == value + 1 && (ctx->flags & DB_COMMON_KEY_USER) != 0))
	    return (0);
    }

    if (ctx->nparts > 0) {
	parts = argv_split(key ? kdomain : vdomain, ".");

	/*
	 * Filter out input keys whose domains lack enough labels to fill-in
	 * the query template. See below and also db_common_parse() which
	 * initializes ctx->nparts.
	 */
	if (parts->argc < ctx->nparts) {
	    argv_free(parts);
	    return (0);
	}

	/*
	 * Skip domains with leading, consecutive or trailing '.' separators
	 * among the required labels.
	 */
	for (i = 0; i < ctx->nparts; i++)
	    if (*parts->argv[parts->argc - i - 1] == 0) {
		argv_free(parts);
		return (0);
	    }
    }
    if (VSTRING_LEN(result) > 0)
	VSTRING_ADDCH(result, ',');

#define QUOTE_VAL(d, q, v, buf) do { \
	if (q) \
	    q(d, v, buf); \
	else \
	    vstring_strcat(buf, v); \
    } while (0)

    /*
     * Replace all instances of %s with the address to look up. Replace %u
     * with the user portion, and %d with the domain portion. "%%" expands to
     * "%".  lowercase -> addr, uppercase -> key
     */
    for (cp = format; *cp; cp++) {
	if (*cp == '%') {
	    switch (*++cp) {

	    case '%':
		VSTRING_ADDCH(result, '%');
		break;

	    case 's':
		QUOTE_VAL(ctx->dict, quote_func, value, result);
		break;

	    case 'u':
		if (vdomain) {
		    if (vuser == 0)
			vuser = mystrndup(value, vdomain - value - 1);
		    QUOTE_VAL(ctx->dict, quote_func, vuser, result);
		} else
		    QUOTE_VAL(ctx->dict, quote_func, value, result);
		break;

	    case 'd':
		if (!(ctx->flags & dflag))
		    msg_panic("%s: %s: %s: bad query/result template context",
			      myname, ctx->dict->name, format);
		if (!vdomain)
		    msg_panic("%s: %s: %s: expanding domain-less key or value",
			      myname, ctx->dict->name, format);
		QUOTE_VAL(ctx->dict, quote_func, vdomain, result);
		break;

	    case 'S':
		if (key)
		    QUOTE_VAL(ctx->dict, quote_func, key, result);
		else
		    QUOTE_VAL(ctx->dict, quote_func, value, result);
		break;

	    case 'U':
		if (key) {
		    if (kdomain) {
			if (kuser == 0)
			    kuser = mystrndup(key, kdomain - key - 1);
			QUOTE_VAL(ctx->dict, quote_func, kuser, result);
		    } else
			QUOTE_VAL(ctx->dict, quote_func, key, result);
		} else {
		    if (vdomain) {
			if (vuser == 0)
			    vuser = mystrndup(value, vdomain - value - 1);
			QUOTE_VAL(ctx->dict, quote_func, vuser, result);
		    } else
			QUOTE_VAL(ctx->dict, quote_func, value, result);
		}
		break;

	    case 'D':
		if (!(ctx->flags & DB_COMMON_KEY_DOMAIN))
		    msg_panic("%s: %s: %s: bad query/result template context",
			      myname, ctx->dict->name, format);
		if ((domain = key ? kdomain : vdomain) == 0)
		    msg_panic("%s: %s: %s: expanding domain-less key or value",
			      myname, ctx->dict->name, format);
		QUOTE_VAL(ctx->dict, quote_func, domain, result);
		break;

	    case '1':
	    case '2':
	    case '3':
	    case '4':
	    case '5':
	    case '6':
	    case '7':
	    case '8':
	    case '9':

		/*
		 * Interpolate %[1-9] components into the query string. By
		 * this point db_common_parse() has identified the highest
		 * component index, and (see above) keys with fewer
		 * components have been filtered out. The "parts" ARGV is
		 * guaranteed to be initialized and hold enough elements to
		 * satisfy the query template.
		 */
		if (!(ctx->flags & DB_COMMON_KEY_DOMAIN)
		    || ctx->nparts < *cp - '0')
		    msg_panic("%s: %s: %s: bad query/result template context",
			      myname, ctx->dict->name, format);
		if (!parts || parts->argc < ctx->nparts)
		    msg_panic("%s: %s: %s: key has too few domain labels",
			      myname, ctx->dict->name, format);
		QUOTE_VAL(ctx->dict, quote_func,
			  parts->argv[parts->argc - (*cp - '0')], result);
		break;

	    default:
		msg_fatal("%s: %s: invalid %s template '%s'", myname,
			  ctx->dict->name, key ? "result" : "query",
			  format);
	    }
	} else
	    VSTRING_ADDCH(result, *cp);
    }
    VSTRING_TERMINATE(result);

    if (vuser)
	myfree(vuser);
    if (kuser)
	myfree(kuser);
    if (parts)
	argv_free(parts);

    return (1);
}
Ejemplo n.º 19
0
DICT   *dict_union_open(const char *name, int open_flags, int dict_flags)
{
    static const char myname[] = "dict_union_open";
    DICT_UNION *dict_union;
    char   *saved_name = 0;
    char   *dict_type_name;
    ARGV   *argv = 0;
    char  **cpp;
    DICT   *dict;
    int     match_flags = 0;
    struct DICT_OWNER aggr_owner;
    size_t  len;

    /*
     * Clarity first. Let the optimizer worry about redundant code.
     */
#define DICT_UNION_RETURN(x) do { \
	      if (saved_name != 0) \
	          myfree(saved_name); \
	      if (argv != 0) \
	          argv_free(argv); \
	      return (x); \
	  } while (0)

    /*
     * Sanity checks.
     */
    if (open_flags != O_RDONLY)
	DICT_UNION_RETURN(dict_surrogate(DICT_TYPE_UNION, name,
					 open_flags, dict_flags,
				  "%s:%s map requires O_RDONLY access mode",
					 DICT_TYPE_UNION, name));

    /*
     * Split the table name into its constituent parts.
     */
    if ((len = balpar(name, CHARS_BRACE)) == 0 || name[len] != 0
	|| *(saved_name = mystrndup(name + 1, len - 2)) == 0
	|| ((argv = argv_splitq(saved_name, CHARS_COMMA_SP, CHARS_BRACE)),
	    (argv->argc == 0)))
	DICT_UNION_RETURN(dict_surrogate(DICT_TYPE_UNION, name,
					 open_flags, dict_flags,
					 "bad syntax: \"%s:%s\"; "
					 "need \"%s:{type:name...}\"",
					 DICT_TYPE_UNION, name,
					 DICT_TYPE_UNION));

    /*
     * The least-trusted table in the set determines the over-all trust
     * level. The first table determines the pattern-matching flags.
     */
    DICT_OWNER_AGGREGATE_INIT(aggr_owner);
    for (cpp = argv->argv; (dict_type_name = *cpp) != 0; cpp++) {
	if (msg_verbose)
	    msg_info("%s: %s", myname, dict_type_name);
	if (strchr(dict_type_name, ':') == 0)
	    DICT_UNION_RETURN(dict_surrogate(DICT_TYPE_UNION, name,
					     open_flags, dict_flags,
					     "bad syntax: \"%s:%s\"; "
					     "need \"%s:{type:name...}\"",
					     DICT_TYPE_UNION, name,
					     DICT_TYPE_UNION));
	if ((dict = dict_handle(dict_type_name)) == 0)
	    dict = dict_open(dict_type_name, open_flags, dict_flags);
	dict_register(dict_type_name, dict);
	DICT_OWNER_AGGREGATE_UPDATE(aggr_owner, dict->owner);
	if (cpp == argv->argv)
	    match_flags = dict->flags & (DICT_FLAG_FIXED | DICT_FLAG_PATTERN);
    }

    /*
     * Bundle up the result.
     */
    dict_union =
	(DICT_UNION *) dict_alloc(DICT_TYPE_UNION, name, sizeof(*dict_union));
    dict_union->dict.lookup = dict_union_lookup;
    dict_union->dict.close = dict_union_close;
    dict_union->dict.flags = dict_flags | match_flags;
    dict_union->dict.owner = aggr_owner;
    dict_union->re_buf = vstring_alloc(100);
    dict_union->map_union = argv;
    argv = 0;
    DICT_UNION_RETURN(DICT_DEBUG (&dict_union->dict));
}
Ejemplo n.º 20
0
void
write_doc_cdata( const char *cdata, int len, ASXMLInterpreterState *state )
{
	int i ;
	if( state->doc_type == DocType_XML || 
		state->doc_type == DocType_HTML || 
		state->doc_type == DocType_PHP )	  
	{
		int token_start = 0;
		Bool special = False ;
		for( i = 0 ; i < len ; ++i ) 
		{
			if( (!isalnum(cdata[i]) && cdata[i] != '_'  && cdata[i] != '(' && cdata[i] != ')') || special )
			{
				if( token_start < i )
				{	
					if( get_flags( state->flags, ASXMLI_InsideLink) )
					{	
						fwrite( &(cdata[token_start]), 1, i-token_start, state->dest_fp );	 
					}else
					{
						/* need to try and insert an URL here if token is a keyword */
						char *token = mystrndup( &(cdata[token_start]), i - token_start );
						ASHashData hdata ;
						if( !special && get_hash_item(Links, AS_HASHABLE(token), &(hdata.vptr)) == ASH_Success ) 
						{
							if( state->doc_type == DocType_HTML	)
								fprintf( state->dest_fp, "<A href=\"%s\">%s</A>", hdata.cptr, token );
							else if( state->doc_type == DocType_PHP ) 
								fprintf( state->dest_fp, PHPXrefFormat, "visualdoc",token, hdata.cptr, "" );
						}else
					 		fwrite( token, 1, i-token_start, state->dest_fp );	
						free( token ); 
					}
				}	 
				token_start = i+1 ;
				
				if( cdata[i] == '&' )
					special = ( translate_special_sequence( &(cdata[i]), len-i,  NULL ) != '\0' );
				else if( cdata[i] == ';' && special ) 		   
					special = False ;
				switch( cdata[i] )
				{
					case '<' : fwrite( "&lt;", 1, 4, state->dest_fp );     break ;	
					case '>' : fwrite( "&gt;", 1, 4, state->dest_fp );     break ;	 
					case '"' : fwrite( "&quot;", 1, 6, state->dest_fp );     break ;	 
					case '&' : 	if( !special ) 
								{			
									fwrite( "&amp;", 1, 5, state->dest_fp );     
									break ;	 
								}
								/* otherwise falling through ! */
					default:
						fputc( cdata[i], state->dest_fp );
				}	 
			}
		}				
		if( i > token_start ) 
			fwrite( &(cdata[token_start]), 1, i-token_start, state->dest_fp );	 
	}else
	{
		for( i = 0 ; i < len ; ++i ) 
		{
			int c_len = 0 ;
			int c = '\0' ; 
			
			if( cdata[i] == '&' ) 
				c = translate_special_sequence( &(cdata[i]), len-i, &c_len ) ;
			if( c != '\0' )
				i += c_len-1 ;	
			else
				c = cdata[i];
			if( c == '\"' && get_flags( state->flags, ASXMLI_EscapeDQuotes) ) 
				fputc( '\"', state->dest_fp );	
			else if ( c == '-' && state->doc_type == DocType_NROFF ) 
				fputc( '\\', state->dest_fp );	
			else if ( c == '.' && state->doc_type == DocType_NROFF ) 
				fputs( "\\&", state->dest_fp );	
			else if ( c == '\\' && state->doc_type == DocType_NROFF ) 
				fputc( '\\', state->dest_fp );	
			else if ( c == '˜' && state->doc_type == DocType_NROFF ) 
				c = '~';
			fputc( c, state->dest_fp );
		}		   
	}	 
}
Ejemplo n.º 21
0
static int mac_exp_parse_relational(MAC_EXP_CONTEXT *mc, const char **lookup,
				            char **bp)
{
    char   *cp = *bp;
    VSTRING *left_op_buf;
    VSTRING *rite_op_buf;
    const char *left_op_strval;
    const char *rite_op_strval;
    char   *op_pos;
    char   *op_strval;
    size_t  op_len;
    int     op_tokval;
    int     op_result;
    size_t  tmp_len;

    /*
     * Left operand. The caller is expected to skip leading whitespace before
     * the {. See MAC_EXP_FIND_LEFT_CURLY().
     */
    if ((left_op_strval = mac_exp_extract_curly_payload(mc, &cp)) == 0)
	return (mc->status);

    /*
     * Operator. Todo: regexp operator.
     */
    op_pos = cp;
    op_len = strspn(cp, "<>!=?+-*/~&|%");	/* for better diagnostics. */
    op_strval = mystrndup(cp, op_len);
    op_tokval = name_code(mac_exp_op_table, NAME_CODE_FLAG_NONE, op_strval);
    myfree(op_strval);
    if (op_tokval == MAC_EXP_OP_TOK_NONE)
	MAC_EXP_ERR_RETURN(mc, "%s expected at: \"...%s}>>>%.20s\"",
			   MAC_EXP_OP_STR_ANY, left_op_strval, cp);
    cp += op_len;

    /*
     * Right operand. Todo: syntax may depend on operator.
     */
    if (MAC_EXP_FIND_LEFT_CURLY(tmp_len, cp) == 0)
	MAC_EXP_ERR_RETURN(mc, "\"{expression}\" expected at: "
			   "\"...{%s} %.*s>>>%.20s\"",
			   left_op_strval, (int) op_len, op_pos, cp);
    if ((rite_op_strval = mac_exp_extract_curly_payload(mc, &cp)) == 0)
	return (mc->status);

    /*
     * Evaluate the relational expression. Todo: regexp support.
     */
    mc->status |=
	mac_expand(left_op_buf = vstring_alloc(100), left_op_strval,
		   mc->flags, mc->filter, mc->lookup, mc->context);
    mc->status |=
	mac_expand(rite_op_buf = vstring_alloc(100), rite_op_strval,
		   mc->flags, mc->filter, mc->lookup, mc->context);
    op_result = mac_exp_eval(vstring_str(left_op_buf), op_tokval,
			     vstring_str(rite_op_buf));
    vstring_free(left_op_buf);
    vstring_free(rite_op_buf);
    if (mc->status & MAC_PARSE_ERROR)
	return (mc->status);

    /*
     * Here, we fake up a non-empty or empty parameter value lookup result,
     * for compatibility with the historical code that looks named parameter
     * values.
     */
    *lookup = (op_result ? MAC_EXP_BVAL_TRUE : MAC_EXP_BVAL_FALSE);
    *bp = cp;
    return (0);
}
Ejemplo n.º 22
0
int
dirtree_parse (dirtree_t * tree, const char *file)
{
	FILE         *fp;
	char         *str;
	ASHashTable  *exclusions = NULL; 

	ASSERT_TREE_INT(tree,1);
	
	if( file == NULL ) 
		return 1 ;
	
	if ((fp = fopen (file, "r")) == NULL)
		return 1;
	
	
	str = safemalloc (8192);
	while (fgets (str, 8192, fp) != NULL)
	{
		char         *ptr;
		Bool 	      do_include = False ; 
		int 		  include_order = 0 ;

		ptr = strip_whitespace (str);
		/* ignore comments and blank lines */
		if (*ptr == '#' || *ptr == '\0')
			continue;
		if( !mystrncasecmp (ptr, "exclude", 7) )
		{
			char *excl_name ; 
			if( exclusions == NULL ) 
				exclusions = create_ashash( 0, casestring_hash_value, casestring_compare, string_destroy );
			if( exclusions ) 
			{	
				excl_name = stripcpy2 (ptr +7, 0);
				add_hash_item( exclusions, AS_HASHABLE(excl_name), NULL );
			}
			continue;
		}		
		
		if( !mystrncasecmp (ptr, "category", 8) )
		{
			char *cat_name;
			Bool include_children = False;
			ptr+= 8 ;
			if( *ptr == '_' ) ++ptr ;
			if( !mystrncasecmp (ptr, "tree", 4))
			{
				include_children = True ;
				ptr += 4 ;	  
			}
			cat_name = stripcpy2 (ptr, 0);
			dirtree_add_category_by_name (tree, cat_name, include_children, exclusions);
			free( cat_name );
			continue;
		}
		   
		if( !mystrncasecmp (ptr, "include", 7) )
		{
			do_include = True ;
			ptr += 7 ; 
			if( *ptr == '_' ) ++ptr ;
			if( !mystrncasecmp (ptr, "ordered", 7) ) 	  
			{
				for (ptr += 7; isspace (*ptr); ptr++);				
				if ( isdigit(*ptr) )
				{
					include_order = atoi( ptr );	
					while( isdigit( *ptr ) ) ++ptr;
				}	 
			}	 
		}
			
		if( do_include )   
		{
			char         *path;
			dirtree_t    *t;

			while(isspace (*ptr))	ptr++;
			if (*ptr != '"')
				continue;
			path = ++ptr;
			for (; *ptr != '\0' && *ptr != '"'; ptr++);
			if (*ptr == '"')
				for (*ptr++ = '\0'; isspace (*ptr); ptr++);
			path = make_absolute (tree->path, path);
			t = dirtree_new_from_dir (path);
			free (path);
			if (t != NULL)
			{
				if (*ptr != '\0')
				{
					txt2func (ptr, &t->command, False);
					dirtree_set_command (t, &t->command, 1);
				}

				/* included dir might have a .include */
				dirtree_parse_include (t);
				if( include_order != 0 ) 
					dirtree_set_base_order ( t, include_order);

				dirtree_move_children (tree, t);
				dirtree_delete (t);
			}
		} else if (!mystrncasecmp (ptr, "keepname", 8))
			tree->flags |= DIRTREE_KEEPNAME;
		else   if (!mystrncasecmp (ptr, "ShowUnavailable", 15))
			tree->flags |= DIRTREE_SHOW_UNAVAILABLE;
		   else if (!mystrncasecmp (ptr, "extension", 9))
		{
			char         *tmp;

			for (ptr += 9; isspace (*ptr); ptr++);
			for (tmp = ptr + strlen (ptr); tmp > ptr && isspace (*(tmp - 1)); tmp--);
			if (tmp != ptr)
			{
				if( tree->extension ) free( tree->extension );
				tree->extension = mystrndup (ptr, tmp - ptr);
			}
		}else if (!mystrncasecmp (ptr, "miniextension", 13))
		{
			char         *tmp;

			for (ptr += 13; isspace (*ptr); ptr++);
			for (tmp = ptr + strlen (ptr); tmp > ptr && isspace (*(tmp - 1)); tmp--);
			if (tmp != ptr)
				tree->minipixmap_extension = mystrndup (ptr, tmp - ptr);
		} else if (!mystrncasecmp (ptr, "minipixmap", 10) || !mystrncasecmp (ptr, "smallminipixmap", 15))
		{
			if( ptr[0] == 's' || ptr[0] == 'S' )
			{	
				set_flags(tree->flags, DIRTREE_ICON_IS_SMALL);
				ptr += 5 ;
			}else
				clear_flags(tree->flags, DIRTREE_ICON_IS_SMALL);
			set_string(&(tree->icon), stripcpy2(ptr+10,False));

		} else if (!mystrncasecmp (ptr, "command", 7))
		{
			for (ptr += 7; isspace (*ptr); ptr++);
			txt2func (ptr, &tree->command, False);
			dirtree_set_command (tree, &tree->command, 0);
		} else if (!mystrncasecmp (ptr, "order", 5))
		{	
			tree->order = strtol (ptr + 5, NULL, 10);
		} else if (!mystrncasecmp (ptr, "RecentSubmenuItems", 18))
		{	
			tree->recent_items = strtol (ptr + 18, NULL, 10);
			tree->flags |= DIRTREE_RECENT_ITEMS_SET;
		} else if (!mystrncasecmp (ptr, "name", 4))
		{
			set_string(&(tree->name), stripcpy2(ptr+4,False));
			clear_flags( tree->flags, DIRTREE_NAME_IS_UTF8 );
		}else if (!mystrncasecmp (ptr, "Comment", 7))
		{
			set_string(&(tree->Comment), stripcpy2(ptr+7,False));
			clear_flags( tree->flags, DIRTREE_COMMENT_IS_UTF8 );
		}else if (!mystrncasecmp (ptr, "FolderReference", 15))
		{
			set_string(&(tree->FolderReference), stripcpy2(ptr+15,False));
			dirtree_fill_from_reference( tree, tree->FolderReference );
		}
	}
	free (str);
	fclose (fp);
	return 0;
}