char* rrdgetenv(long argc, const char **args) {
	char buf[128];
	const char* envvar;
	if (argc != 1) {
		return stralloc("[ERROR: getenv failed because it did not "
						"get 1 argument only]");
	};
	envvar = getenv(args[0]);
	if (envvar) {
		return stralloc(envvar);
	} else {
                snprintf(buf, sizeof(buf), "[ERROR:_getenv_'%s'_failed", args[0]);
                return stralloc(buf);
	}
}
/* rrd interface to the variable function putvar() */
char*
rrdsetvarconst(long argc, const char **args)
{
	if (argc >= 2)
	{
		const char* result = putvar(args[0], args[1], 1 /* const */);
		if (result) {
			/* setvar does not return the value set */
			return stralloc("");
		}
		return stralloc("[ERROR: putvar failed]");
	}
	return stralloc("[ERROR: putvar failed because not enough arguments "
					"were defined]");
}
/* Put a variable into the variable store. If a variable by that
   name exists, it's value is overwritten with the new value unless it was
   marked as 'const' (initialized by RRD::SETCONSTVAR).
   Returns a copy the newly allocated value on success, NULL on error. */
static const char*
putvar(const char* name, const char* value, int is_const)
{
	int i;
	for (i=0; i < (int)varheap_size && varheap[i].name; i++) {
		if (0 == strcmp(name, varheap[i].name)) {
			/* overwrite existing entry */
			if (varheap[i].is_const) {
#ifdef			DEBUG_VARS
				printf("<!-- setver(%s, %s): not assigning: "
						"const variable -->\n", name, value);
#				endif
				return varheap[i].value;
			}
#ifdef		DEBUG_VARS
			printf("<!-- setvar(%s, %s): overwriting old value (%s) -->\n",
					name, value, varheap[i].value);
#endif
			/* make it possible to promote a variable to readonly */
			varheap[i].is_const = is_const;
			free((char*)varheap[i].value);
			varheap[i].value = stralloc(value);
			return varheap[i].value;
		}
	}

	/* no existing variable found by that name, add it */
	if (i == (int)varheap_size) {
		/* ran out of heap: resize heap to double size */
		size_t new_size = varheap_size * 2;
		varheap = (vardata*)(realloc(varheap, sizeof(vardata) * new_size));
		if (!varheap) {
			fprintf(stderr, "ERROR: Unable to realloc variable heap\n");
			return NULL;
		}
		/* initialize newly allocated memory */;
		memset(&varheap[varheap_size], 0, sizeof(vardata) * varheap_size);
		varheap_size = new_size;
	}
	varheap[i].is_const = is_const;
	varheap[i].name  = stralloc(name);
	varheap[i].value = stralloc(value);

#ifdef		DEBUG_VARS
	printf("<!-- setvar(%s, %s): adding new variable -->\n", name, value);
#endif
	return varheap[i].value;
}
示例#4
0
char *xstralloccat(char *base,char *add,int line,char *file)
{
	if(diagmisc && !diagallocx)
	{
		prterr("DIAG xstralloccat String Allocated at line [%d] program [%s].",line,file);	
	}
	if(base!=NULL)
	{
		if(diagallocx && diagmisc)
		{		
			base=(char *)xRrealloc(base,RDAstrlen(base)+RDAstrlen(add)+1,line,file);
		} else {
			base=(char *)Rrealloc(base,RDAstrlen(base)+RDAstrlen(add)+1);
		}
		if(base!=NULL) strcat(base,add);
	} else {
		if(diagallocx && diagmisc)
		{		
			base=xstralloc(add,line,file);
		} else {
			base=stralloc(add);
		}
	}
	return(base);
}
示例#5
0
Wt::Auth::User RDAUserDatabase::findWithAuthToken (const std::string &hash)
  const
{
	char *ud=NULL,delflag=FALSE;
  /*
   * David: find a user associated with a token with given hash value, taking
   * into account that it should not be expired
   */

	if(SEC_TOKEN_FILENO==(-1))
	{
    		return;
	}
	ZERNRD(SEC_TOKEN_FILENO);
	FINDFLDSETSTRING(SEC_TOKEN_FILENO,"TOKEN",hash.c_str());
	if(!EQLNRD(SEC_TOKEN_FILENO,1))
	{
		FINDFLDGETCHAR(SEC_TOKEN_FILENO,"DELETEFLAG",&delflag);
		if(!delflag)
		{
			FINDFLDGETSTRING(SEC_TOKEN_FILENO,"USER IDENTIFICATION",&ud);
			USERLOGIN=stralloc(ud);
			const std::string u(ud);
/*
			std::cerr << "User Identification [" << ud << "]" << std::endl;
*/
  			return Wt::Auth::User(u, *this);
		} else {
    			return Wt::Auth::User();
		}
	} else {
    		return Wt::Auth::User();
	}
}
示例#6
0
Wt::Auth::User RDAUserDatabase::findWithIdentity (const std::string &provider,
						  const Wt::WString &identity)
  const
{
	std::string i;
  /*
   * David: find the 'id' for a user with name _identity_, leave it
   * empty if no user with this name exists
   */

	if(SEC_USERS_FILENO==(-1))
	{
    		return Wt::Auth::User();
	}
	ZERNRD(SEC_USERS_FILENO);
	i=identity.toUTF8();
	USERLOGIN=stralloc(i.c_str());
	FINDFLDSETSTRING(SEC_USERS_FILENO,"USER IDENTIFICATION",USERLOGIN);
	if(EQLNRD(SEC_USERS_FILENO,1)) 
	{
		KEYNRD(SEC_USERS_FILENO,1);
    		return Wt::Auth::User();
	} else {
    		return Wt::Auth::User(i, *this);
	}
}
示例#7
0
ipp_attribute_t *			
ippAddResolutions(ipp_t      *ipp,	
        	  ipp_tag_t  group,	
		  const char *name,	
		  int        num_values,
		  ipp_res_t  units,	
		  const int  *xres,	
		  const int  *yres)	
{
  int			i;		
  ipp_attribute_t	*attr;		
  ipp_value_t		*value;		

  if (!ipp || !name || num_values < 1)
    return (NULL);

  if ((attr = _ippAddAttr(ipp, num_values)) == NULL)
    return (NULL);

  attr->name      = stralloc(name);
  attr->group_tag = group;
  attr->value_tag = IPP_TAG_RESOLUTION;

  if (xres != NULL && yres != NULL)
    for (i = 0, value = attr->values;
	 i < num_values;
	 i ++, value ++)
    {
      value->resolution.xres  = xres[i];
      value->resolution.yres  = yres[i];
      value->resolution.units = units;
    }

  return (attr);
}
示例#8
0
ipp_attribute_t *			
ippAddRanges(ipp_t      *ipp,		
             ipp_tag_t  group,		
	     const char *name,		
	     int        num_values,	
	     const int  *lower,		
	     const int  *upper)		
{
  int			i;		
  ipp_attribute_t	*attr;		
  ipp_value_t		*value;		

  if (!ipp || !name || num_values < 1)
    return (NULL);

  if ((attr = _ippAddAttr(ipp, num_values)) == NULL)
    return (NULL);

  attr->name      = stralloc(name);
  attr->group_tag = group;
  attr->value_tag = IPP_TAG_RANGE;

  if (lower != NULL && upper != NULL)
    for (i = 0, value = attr->values;
	 i < num_values;
	 i ++, value ++)
    {
      value->range.lower = lower[i];
      value->range.upper = upper[i];
    }

  return (attr);
}
示例#9
0
char     *rrdgetinternal(
    long argc,
    const char **args)
{
    if (argc == 1) {
        if (strcasecmp(args[0], "VERSION") == 0) {
            return stralloc(PACKAGE_VERSION);
        } else if (strcasecmp(args[0], "COMPILETIME") == 0) {
            return stralloc(__DATE__ " " __TIME__);
        } else {
            return stralloc("[ERROR: internal unknown argument]");
        }
    } else {
        return stralloc("[ERROR: internal expected 1 argument]");
    }
}
示例#10
0
char     *rrdgoodfor(
    long argc,
    const char **args)
{
    if (argc == 1) {
        goodfor = atol(args[0]);
    } else {
        return stralloc("[ERROR: goodfor expected 1 argument]");
    }

    if (goodfor == 0) {
        return stralloc("[ERROR: goodfor value must not be 0]");
    }

    return stralloc("");
}
示例#11
0
static void DEF_MANAGE_SCANS()
{
	RDAdefault *def=NULL;
	char *defdir=NULL;
	char *temp1=NULL;

	def=RDAdefaultNEW("ARCHIVE","MANAGE SCANS");
	if(def!=NULL)
	{
		def->input_focus=stralloc("ADD SCAN DIRECTORIES");

		defdir=Rmalloc(RDAstrlen(CURRENTDIRECTORY)+RDAstrlen(module)+12);
#ifndef WIN32
		sprintf(defdir,"%s/rda/%s.DEF",CURRENTDIRECTORY,module);
#endif
#ifdef WIN32
		sprintf(defdir,"%s\\rda\\%s.DEF",CURRENTDIRECTORY,module);
#endif
		if(writedefaultbin(defdir,def))
		{
			if(temp1!=NULL) Rfree(temp1);
			temp1=Rmalloc(12+7+100+1);
			sprintf(temp1,"SCREEN DEFAULT WRITE ERROR: Module [ARCHIVE] Screen [MANAGE SCANS], Can Not Save Screen Defaults!");
			prterr(temp1);
			if(errorlist!=NULL)
			{
				addERRlist(&errorlist,temp1);
			}
			if(temp1!=NULL) Rfree(temp1);
		}
		if(defdir!=NULL) Rfree(defdir);
		if(def!=NULL) FreeRDAdefault(def);
	}
}
示例#12
0
文件: cfg.c 项目: a2o/lilo
static int cfg_do_set(CONFIG *table,char *item,char *value,int copy,
    void *context)
{
    CONFIG *walk;

    for (walk = table; walk->type != cft_end; walk++) {
	if (walk->name && !strcasecmp(walk->name,item)) {
	    if (value && walk->type != cft_strg)
		cfg_error("'%s' doesn't have a value",walk->name);
	    if (!value && walk->type == cft_strg)
		cfg_error("Value expected for '%s'",walk->name);
	    if (walk->data) {
		if (walk->context == context)
		    cfg_error("Duplicate entry '%s'",walk->name);
		else {
		    warn("Ignoring entry '%s'",walk->name);
		    if (!copy) free(value);
		    return 1;
		}
	    }
	    if (walk->type == cft_flag) walk->data = &flag_set;
	    else if (walk->type == cft_strg)
		    walk->data = copy ? stralloc(value) : value; 
	    walk->context = context;
	    if (walk->action) ((void (*)(void)) walk->action)();
	    break;
	}
	if (walk->type == cft_link) walk = ((CONFIG *) walk->action)-1;
    }
    if (walk->type != cft_end) return 1;
    cfg_return(item,value);
    return 0;
}
示例#13
0
int main(int argc,char **argv)
#endif
{
	if(InitializeSubsystems(argc,argv,module,"ITRON IMPORT FILE")) 
	{
		RDAAPPMAINLOOP();
		return;
	}
	if((utbcus=APPOPNNRD(module,"UTBCUS",TRUE,FALSE))==(-1)) return;
	if((utbsvc=APPOPNNRD(module,"UTBSVC",TRUE,TRUE))==(-1)) return;
	if((utbmtr=APPOPNNRD(module,"UTBMTR",TRUE,FALSE))==(-1)) return;
	if((utbrte=APPOPNNRD(module,"UTBRTE",TRUE,TRUE))==(-1)) return;
	MAINrsrc=RDArsrcNEW(module,"ITRON IMPORT FILE");
	addDFincvir(MAINrsrc,module,"UTBCUS",NULL,utbcus);
	addDFincvir(MAINrsrc,module,"UTBSVC",NULL,utbsvc);
	addDFincvir(MAINrsrc,module,"UTBMTR",NULL,utbmtr);
	addDFincvir(MAINrsrc,module,"UTBRTE",NULL,utbrte);
	ITRON_FILENAME=stralloc("UPLOAD.DAT");
	addstdrsrc(MAINrsrc,"FILENAME",VARIABLETEXT,0,ITRON_FILENAME,TRUE);
	DefaultScreens(MAINrsrc);
	addbtnrsrc(MAINrsrc,"DEFAULTS",TRUE,SaveDefaults,NULL);
	addrfcbrsrc(MAINrsrc,"SELECT",TRUE,ReadItron,NULL);
	addrfexrsrc(MAINrsrc,"QUIT",TRUE,quitfunc,NULL);
	addrfcbrsrc(MAINrsrc,"HELP",TRUE,screenhelp,NULL);
	addrfcbrsrc(MAINrsrc,"PRINT RESOURCES",TRUE,printrsrcs,NULL);
	computeallSCRNvirtuals(MAINrsrc);
	APPmakescrn(MAINrsrc,TRUE,quitfunc,NULL,TRUE);
	RDAAPPMAINLOOP();
}
示例#14
0
int
cd_dir(
    char *	path_on_disk,
    char *	default_dir,
    int		verbose)
{
    char *dir = NULL;
    char *s;
    int nb_found;
    int result;
    size_t i;

    DIR_ITEM *ditem;

    if ((s = validate_regexp(path_on_disk)) != NULL) {
	result = set_directory(default_dir, verbose);
	return result;
    }

    nb_found = 0;

    for (ditem=get_dir_list(); ditem!=NULL && nb_found <= 1; 
			       ditem=get_next_dir_item(ditem))
    {
	if (match(path_on_disk, ditem->path))
	{
	    i = strlen(ditem->path);
	    if((i > 0 && ditem->path[i-1] == '/')
               || (i > 1 && ditem->path[i-2] == '/' && ditem->path[i-1] == '.'))
            {   /* It is a directory */
		char *dir1, *dir2;
		nb_found++;
		dir = newstralloc(dir,ditem->path);
		if(dir[strlen(dir)-1] == '/')
		    dir[strlen(dir)-1] = '\0'; /* remove last / */
		/* remove everything before the last / */
		dir1 = strrchr(dir,'/');
		if (dir1) {
		    dir1++;
		    dir2 = stralloc(dir1);
		    amfree(dir);
		    dir = dir2;
		}
	    }
	}
    }

    if(nb_found==0) {
	result = set_directory(default_dir, verbose);
    }
    else if(nb_found==1) {
	result = set_directory(dir, verbose);
    }
    else {
	g_printf(_("Too many directories matching '%s'\n"), default_dir);
	result = 0;
    }
    amfree(dir);
    return result;
}
示例#15
0
void setCFI_IDENT(Connection *Conn,int cid[2],int sv){
	CStr(env,1024);

	IGNRETZ pipe(cid);
	sprintf(env,"CFI_IDENT=%d",cid[1]);
	putenv(stralloc(env));
}
示例#16
0
ipp_attribute_t	*			
ippAddOctetString(ipp_t      *ipp,	
                  ipp_tag_t  group,	
                  const char *name,	
                  const void *data,	
		  int        datalen)	
{
  ipp_attribute_t	*attr;		


  if (ipp == NULL || name == NULL)
    return (NULL);

  if ((attr = _ippAddAttr(ipp, 1)) == NULL)
    return (NULL);

  attr->name                     = stralloc(name);
  attr->group_tag                = group;
  attr->value_tag                = IPP_TAG_STRING;
  attr->values[0].unknown.length = datalen;

  if (data)
  {
    if ((attr->values[0].unknown.data = malloc(datalen)) == NULL)
    {
      ippDeleteAttribute(ipp, attr);
      return (NULL);
    }

    memcpy(attr->values[0].unknown.data, data, datalen);
  }

  return (attr);
}
示例#17
0
ipp_attribute_t *			
ippAddBooleans(ipp_t      *ipp,		
               ipp_tag_t  group,	
	       const char *name,	
	       int        num_values,	
	       const char *values)	
{
  int			i;		
  ipp_attribute_t	*attr;		
  ipp_value_t		*value;		

  if (!ipp || !name || num_values < 1)
    return (NULL);

  if ((attr = _ippAddAttr(ipp, num_values)) == NULL)
    return (NULL);

  attr->name      = stralloc(name);
  attr->group_tag = group;
  attr->value_tag = IPP_TAG_BOOLEAN;

  if (values != NULL)
    for (i = 0, value = attr->values;
	 i < num_values;
	 i ++, value ++)
      value->boolean = values[i];

  return (attr);
}
示例#18
0
char     *drawgraph(
    long argc,
    const char **args)
{
    int       i, xsize, ysize;
    double    ymin, ymax;

    for (i = 0; i < argc; i++)
        if (strcmp(args[i], "--imginfo") == 0 || strcmp(args[i], "-g") == 0)
            break;
    if (i == argc) {
        args[argc++] = "--imginfo";
        args[argc++] = "<IMG SRC=\"./%s\" WIDTH=\"%lu\" HEIGHT=\"%lu\">";
    }
    calfree();
    if (rrd_graph
        (argc + 1, (char **) args - 1, &calcpr, &xsize, &ysize, NULL, &ymin,
         &ymax) != -1) {
        return stralloc(calcpr[0]);
    } else {
        if (rrd_test_error()) {
            const size_t len = strlen(rrd_get_error()) + DS_NAM_SIZE;
            char *err = malloc(len);
            snprintf(err, len, "[ERROR: %s]", rrd_get_error());
            rrd_clear_error();
            return err;
        }
    }
    return NULL;
}
示例#19
0
ipp_attribute_t *			
ippAddResolution(ipp_t      *ipp,	
        	 ipp_tag_t  group,	
		 const char *name,	
		 ipp_res_t  units,	
		 int        xres,	
		 int        yres)	
{
  ipp_attribute_t	*attr;		

  if (!ipp || !name)
    return (NULL);

  if ((attr = _ippAddAttr(ipp, 1)) == NULL)
    return (NULL);

  attr->name                       = stralloc(name);
  attr->group_tag                  = group;
  attr->value_tag                  = IPP_TAG_RESOLUTION;
  attr->values[0].resolution.xres  = xres;
  attr->values[0].resolution.yres  = yres;
  attr->values[0].resolution.units = units;

  return (attr);
}
示例#20
0
文件: io.c 项目: bhache/pkg-neuron
char           *
inputline()
{
	/* and removes comment, newline, beginning and trailing blanks */
	/* used to get the TITLE line */
#if __TURBOC__ || SYSV || VMS
#define index strchr
#endif
	char            *cp;
	int             i;

	buf[0] = '\0';
	cp = Gets(buf);
	i = strlen(buf);
	if (i)
		buf[i - 1] = '\0';
	if ((cp = index(buf, '!')) != (char *) 0) {
		*cp-- = '\0';
	}
	while (cp >= buf && isspace(*cp)) {
		*cp-- = '\0';
	}
	/*EMPTY*/
	for (cp = buf; *cp != '\0' && isspace(*cp); cp++){
		;
	}
	return stralloc(cp, (char *) 0);
}
示例#21
0
ipp_attribute_t *			
ippAddCollections(
    ipp_t       *ipp,			
    ipp_tag_t   group,			
    const char  *name,			
    int         num_values,		
    const ipp_t **values)		
{
  int			i;		
  ipp_attribute_t	*attr;		
  ipp_value_t		*value;		

  if (!ipp || !name || num_values < 1)
    return (NULL);

  if ((attr = _ippAddAttr(ipp, num_values)) == NULL)
    return (NULL);

  attr->name      = stralloc(name);
  attr->group_tag = group;
  attr->value_tag = IPP_TAG_BEGIN_COLLECTION;

  if (values != NULL)
  {
    for (i = 0, value = attr->values;
	 i < num_values;
	 i ++, value ++)
    {
      value->collection = (ipp_t *)values[i];
      value->collection->use ++;
    }
  }

  return (attr);
}
示例#22
0
文件: taper.c 项目: regina/amanda
/* In running mode (not startup mode), get a command from driver and
   deal with it. */
static gboolean process_driver_command(taper_state_t * state) {
    struct cmdargs *cmdargs;
    char * q;

    /* This will return QUIT if driver has died. */
    cmdargs = getcmd();
    switch (cmdargs->cmd) {
    case PORT_WRITE:
        /*
         * PORT-WRITE
         *   handle
         *   hostname
         *   features
         *   diskname
         *   level
         *   datestamp
         *   splitsize
         *   split_diskbuffer
         */
        process_port_write(state, cmdargs);
        break;
        
    case FILE_WRITE:
        /*
         * FILE-WRITE
         *   handle
         *   filename
         *   hostname
         *   features
         *   diskname
         *   level
         *   datestamp
         *   splitsize
         */
        process_file_write(state, cmdargs);
        break;
        
    case QUIT:
	free_cmdargs(cmdargs);
	if (state->device && state->device->volume_label) {
	    log_add(L_INFO, "tape %s kb %lld fm %d [OK]\n",
		    state->device->volume_label,
		    (long long)((state->total_bytes+(off_t)1023) / (off_t)1024),
		    state->device->file);
	}
        return send_quitting(state);
    default:
        if (cmdargs->argc >= 1) {
            q = quote_string(cmdargs->argv[0]);
        } else {
            q = stralloc("(no input?)");
        }
        putresult(BAD_COMMAND, "%s\n", q);
        amfree(q);
        break;
    }
    free_cmdargs(cmdargs);

    return TRUE;
}
示例#23
0
char* rrdsetenv(long argc, const char **args) {
	if (argc >= 2) {
		char *xyz = malloc((strlen(args[0]) + strlen(args[1]) + 2));
		if (xyz == NULL) {
			return stralloc("[ERROR: allocating setenv buffer]");
		};
		sprintf(xyz, "%s=%s", args[0], args[1]);
		if(putenv(xyz) == -1) {
			free(xyz);
			return stralloc("[ERROR: failed to do putenv]");
		};
 	        return stralloc("");
	}
	return stralloc("[ERROR: setenv failed because not enough "
		  			"arguments were defined]");
}
示例#24
0
ipp_attribute_t *			
ippAddIntegers(ipp_t      *ipp,		
               ipp_tag_t  group,	
	       ipp_tag_t  type,		
	       const char *name,	
	       int        num_values,	
	       const int  *values)	
{
  int			i;		
  ipp_attribute_t	*attr;		
  ipp_value_t		*value;		

  if (!ipp || !name || num_values < 1)
    return (NULL);

  if ((attr = _ippAddAttr(ipp, num_values)) == NULL)
    return (NULL);

  attr->name      = stralloc(name);
  attr->group_tag = group;
  attr->value_tag = type;

  if (values != NULL)
    for (i = 0, value = attr->values;
	 i < num_values;
	 i ++, value ++)
      value->integer = values[i];

  return (attr);
}
示例#25
0
文件: amxml.c 项目: TonyChiang/amanda
dle_t *
amxml_parse_node_FILE(
    FILE *file,
    char **errmsg)
{
    amgxml_t             amgxml = {NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
    GMarkupParser        parser = {&amstart_element, &amend_element, &amtext,
				   NULL, NULL};
    GMarkupParseFlags    flags = 0;
    GMarkupParseContext *context;
    GError		*gerror = NULL;
    char                *line;

    (void)errmsg;

    context = g_markup_parse_context_new(&parser, flags, &amgxml, NULL);

    while ((line = agets(file)) != NULL && !gerror) {
	g_markup_parse_context_parse(context, line, strlen(line), &gerror);
	amfree(line);
    }
    if (!gerror)
	g_markup_parse_context_end_parse(context, &gerror);
    g_markup_parse_context_free(context);
    if (gerror) {
	if (errmsg)
	    *errmsg = stralloc(gerror->message);
	g_error_free(gerror);
    }
    return amgxml.dles;
}
示例#26
0
const char *paramAbsPath(PCStr(param)){
	int plen;
	int pi;
	CStr(px,1024);
	const char **apath;

	if( strncmp(param,"DGROOT=",plen=7) == 0 ){
		pi = PX_DGROOT;
		apath = &DELEGATE_DGROOT;
	}else{
		return 0;
	}
	if( isFullpath(param+plen) ){
		return 0;
	}
	if( absPARAMS[pi] ){
		return absPARAMS[pi];
	}
	if( !isFullpath(*apath) ){
		return 0;
	}
	strcpy(px,param);
	Xstrcpy(DVStr(px,plen),*apath);
	absPARAMS[pi] = stralloc(px);
	return absPARAMS[pi];
}
示例#27
0
文件: amxml.c 项目: TonyChiang/amanda
dle_t *
amxml_parse_node_CHAR(
    char *txt,
    char **errmsg)
{
    amgxml_t             amgxml = {NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
    GMarkupParser        parser = {&amstart_element, &amend_element, &amtext,
				   NULL, NULL};
    GMarkupParseFlags    flags = 0;
    GMarkupParseContext *context;
    GError		*gerror = NULL;

    (void)errmsg;

    context = g_markup_parse_context_new(&parser, flags, &amgxml, NULL);

    g_markup_parse_context_parse(context, txt, strlen(txt), &gerror);
    if (!gerror)
	g_markup_parse_context_end_parse(context, &gerror);
    g_markup_parse_context_free(context);
    if (gerror) {
	if (errmsg)
	    *errmsg = stralloc(gerror->message);
	g_error_free(gerror);
    }
    return amgxml.dles;
	
}
示例#28
0
char* cgigetq(long argc, const char **args){
  if (argc>= 1){
    char *buf = rrdstrip(rrdcgiGetValue(rrdcgiArg,args[0]));
    char *buf2;
    char *c,*d;
    int  qc=0;
    if (buf==NULL) return NULL;

    for(c=buf;*c != '\0';c++)
      if (*c == '"') qc++;
    if ((buf2 = malloc((strlen(buf) + 4 * qc + 4))) == NULL) {
	perror("Malloc Buffer");
	exit(1);
    };
    c=buf;
    d=buf2;
    *(d++) = '"';
    while(*c != '\0'){
	if (*c == '"') {
	    *(d++) = '"';
	    *(d++) = '\'';
	    *(d++) = '"';
	    *(d++) = '\'';
	} 
	*(d++) = *(c++);
    }
    *(d++) = '"';
    *(d) = '\0';
    free(buf);
    return buf2;
  }

  return stralloc("[ERROR: not enough argument for RRD::CV::QUOTE]");
}
示例#29
0
文件: cmdline.c 项目: regina/amanda
/* Quote str for shell interpretation, being conservative.
 * Any non-alphanumeric charcacters other than '.' and '/'
 * trigger surrounding single quotes, and single quotes and
 * backslashes within those single quotes are escaped.
 */
static char *
quote_dumpspec_string(char *str)
{
    char *rv;
    char *p, *q;
    int len = 0;
    int need_single_quotes = 0;

    if (!str[0])
	return stralloc("''"); /* special-case the empty string */

    for (p = str; *p; p++) {
        if (!isalnum((int)*p) && *p != '.' && *p != '/') need_single_quotes=1;
        if (*p == '\'' || *p == '\\') len++; /* extra byte for '\' */
        len++;
    }
    if (need_single_quotes) len += 2;

    q = rv = malloc(len+1);
    if (need_single_quotes) *(q++) = '\'';
    for (p = str; *p; p++) {
        if (*p == '\'' || *p == '\\') *(q++) = '\\';
        *(q++) = *p;
    }
    if (need_single_quotes) *(q++) = '\'';
    *(q++) = '\0';

    return rv;
}
示例#30
0
printf_arglist_function1(void log_add, logtype_t, typ, char *, format)
{
    va_list argp;
    char *leader = NULL;
    char *xlated_fmt = gettext(format);
    char linebuf[STR_SIZE];
    size_t n;
    static gboolean in_log_add = 0;

    /* avoid recursion */
    if (in_log_add)
	return;

    /* format error message */

    if((int)typ <= (int)L_BOGUS || (int)typ > (int)L_MARKER) typ = L_BOGUS;

    if(multiline > 0) {
	leader = stralloc("  ");		/* continuation line */
    } else {
	leader = vstralloc(logtype_str[(int)typ], " ", get_pname(), " ", NULL);
    }

    arglist_start(argp, format);
    /* use sizeof(linebuf)-2 to save space for a trailing newline */
    g_vsnprintf(linebuf, SIZEOF(linebuf)-2, xlated_fmt, argp);
						/* -1 to allow for '\n' */
    arglist_end(argp);

    /* avoid recursive call from error() */

    in_log_add = 1;

    /* append message to the log file */

    if(multiline == -1) open_log();

    if (full_write(logfd, leader, strlen(leader)) < strlen(leader)) {
	error(_("log file write error: %s"), strerror(errno));
	/*NOTREACHED*/
    }

    amfree(leader);

    /* add a newline if necessary */
    n = strlen(linebuf);
    if(n == 0 || linebuf[n-1] != '\n') linebuf[n++] = '\n';
    linebuf[n] = '\0';

    if (full_write(logfd, linebuf, n) < n) {
	error(_("log file write error: %s"), strerror(errno));
	/*NOTREACHED*/
    }

    if(multiline != -1) multiline++;
    else close_log();

    in_log_add = 0;
}