Exemplo n.º 1
0
/*
 * list_intersection
 *
 * return:
 *   1 if there is an overlap, 0 otherwise.
 */
EXPORT int list_intersection(const char *pcL1, const char *pcL2)
{
    int i1 = 0, i2 = 0;
    char *pcS1, *pcS2;
    char c;
    
    if (!pcL1 || !pcL2) 
    {
        SLPLOG(SLP_LOG_ERR,"list_intersection: got NULL value as a parameter!");
        return 0;
    }
    
    if (*pcL1 == '\0' && *pcL2 == '\0') 
        return 1;
    
    for ( pcS1=get_next_string(",",pcL1,&i1,&c); pcS1; pcS1=get_next_string(",",pcL1,&i1,&c) ) 
    {
        i2 = 0;
        for (pcS2=get_next_string(",",pcL2,&i2,&c); pcS2;pcS2=get_next_string(",",pcL2,&i2,&c))
        {
            // The SLPv2 RFC2608 explicitly states in SECTION 6.4 that scope lists MUST be handled case-insensitive.
			int result = SDstrcasecmp(pcS1,pcS2);	
            SLPFree(pcS2);
            if (result==0)
            {
                SLPFree(pcS1);
                return 1;
            }
        }
        
        SLPFree(pcS1);
    }
    
    return 0;
}
Exemplo n.º 2
0
static void service_state(s_event * event)
{
	active_db_h *service;
	active_db_h *current = NULL;

	assert(event->event_type == &EVENT_IS_CHANGE);

	service = event->data;

	assert(service);
	assert(service->name);

	const char *tmp = NULL;
	s_data *itt = NULL;

	switch (GET_STATE(service)) {
	/* if service is loading, start all in ALSO_START */
	case IS_STARTING:
		while ((tmp = get_next_string(&ALSO_START, service, &itt))) {
			current = initng_active_db_find_by_name(tmp);
			if (current) {
				if (!initng_handler_start_service(current)) {
					F_("Failed to also_start %s.\n", tmp);
				} else {
					D_("Service also_start %s already "
					   "running.\n", tmp);
				}
				continue;
			}

			if (!initng_handler_start_new_service_named(tmp)) {
				F_("%s also_start %s could not start!\n",
				   service->name, tmp);
				initng_handler_stop_service(service);
				break;
			}
		}
		break;

	/* if this service is stopping, stop all in ALSO_STOP */
	case IS_STOPPING:
		while ((tmp = get_next_string(&ALSO_STOP, service, &itt))) {
			current = initng_active_db_find_by_name(tmp);
			if (current) {
				/* Tell this verbose */
				D_("service %s also stops %s\n",
				   service->name, tmp);

				if (!initng_handler_stop_service(current)) {
					F_("Could not stop also_stop "
					   "service %s\n", current->name);
				}
			}
		}
		break;
	}
}
Exemplo n.º 3
0
/* main priority routine */
int prio_path_weight(struct path *pp, char *prio_args)
{
	char path[FILE_NAME_SIZE];
	char *arg;
	char *temp, *regex, *prio;
	char split_char[] = " \t";
	int priority = DEFAULT_PRIORITY, path_found = 0;
	regex_t pathe;

	/* Return default priority if there is no argument */
	if (!prio_args)
		return priority;

	arg = temp = STRDUP(prio_args);

	regex = get_next_string(&temp, split_char);

	/* Return default priority if the argument is not parseable */
	if (!regex) {
		FREE(arg);
		return priority;
	}

	if (!strcmp(regex, HBTL)) {
		sprintf(path, "%d:%d:%d:%d", pp->sg_id.host_no,
			pp->sg_id.channel, pp->sg_id.scsi_id, pp->sg_id.lun);
	} else if (!strcmp(regex, DEV_NAME)) {
		strcpy(path, pp->dev);
	} else {
		condlog(0, "%s: %s - Invalid arguments", pp->dev,
			pp->prio.name);
		FREE(arg);
		return priority;
	}

	while (!path_found) {
		if (!temp)
			break;
		if (!(regex = get_next_string(&temp, split_char)))
			break;
		if (!(prio = get_next_string(&temp, split_char)))
			break;

		if (!regcomp(&pathe, regex, REG_EXTENDED|REG_NOSUB)) {
			if (!regexec(&pathe, path, 0, NULL, 0)) {
				path_found = 1;
				priority = atoi(prio);
			}
			regfree(&pathe);
		}
	}

	FREE(arg);
	return priority;
}
Exemplo n.º 4
0
static int json_parse_key_value(char *start, struct JSON *node, int *offset, char **msg)
{
	int offs = 0;
	char *json = start;
	int ret = 0;

	json += skip_white_char(json);
	ret = get_next_string(json, &node->keyword, &offs, msg);
	json += offs;
	if(ret<0){
		goto end;
	}
	json += skip_white_char(json);

	if(*json!=':'){
		ret = -1;
		*msg = "need : after keyword.";
		goto end;
	}
	json ++;
	json += skip_white_char(json);

	ret = json_parse_all(json, node, &offs, msg);
	json += offs;

end:
	*offset = json - start;
	return ret;
}
Exemplo n.º 5
0
static void clear_pidfile(active_db_h * s)
{
	const char *pidfile = NULL;
	s_data *itt = NULL;

	/* ok, search for pidfiles */
	while ((pidfile = get_next_string(&PIDFILE, s, &itt))) {
		if (pidfile) {
			/* check it's an absolute path after variable substitution */
			if (pidfile[0] == '/') {
				if (unlink(pidfile) != 0 && errno != ENOENT) {
					F_("Could not remove stale pidfile "
					   "\"%s\"\n", pidfile);
				}
				break;
			} else {
				F_("%s has pid_file with relative path "
				   "\"%s\"\n", s->name, pidfile);
				/* check_valid_pidfile_path() can detect
				 * certain dangerous typos, but it can't
				 * prevent loading. Stop to be safe */
				return;
			}
		}
	}
}
Exemplo n.º 6
0
/* this will get the pid of PIDFILE entry of service */
static pid_t get_pidfile(active_db_h * s)
{
	pid_t pid;
	const char *pidfile = NULL;
	s_data *itt = NULL;

	/* get the pidfile */
	while ((pidfile = get_next_string(&PIDFILE, s, &itt))) {
		/* make sure the first char is a '/' so its a full path */
		if (pidfile[0] != '/') {
			F_("%s has pid_file with relative path \"%s\"\n",
			   s->name, pidfile);
			/* check_valid_pidfile_path() can detect certain
			 * dangerous typos, but it can't prevent loading.
			 * Stop to be safe */
			return -1;
		}

		/* get the pid from the file */
		pid = pid_from_file(pidfile);

		/* return the pid */
		if (pid > 1)
			return (pid);
	}

	return -1;
}
Exemplo n.º 7
0
char *find_spec(const char *format,char *str,int *form_pos){
 int i,k,ind,l;
 struct rparam *next;
 if(!cur_file)fatal_error("Param File is not initialized.\n");

/* i=0;
 while(format[i]==' ')i++;
 ind=format[i]&0x7f;*/
 ind=get_code(format);
 if(!ind)fatal_error("Incorrect format string %s!\n",format);
 if(ind<0)l=0; //asterik found, complete search
 else l=ind-1;

 ac_helppos=-1;
 ac_formpos=-1;
 do{
  next=Cashe[l];
  while(next!=NULL){
   fseek(cur_file,next->pos,SEEK_SET);
   get_next_string(str,1);
   k=0;
   i=0;
   do{
    while(str[k]==' ')k++;
    while(format[i]==' ')i++;

    if(format[i]==WC_char){
     while(str[k] && str[k]!=dc[0])k++;
     while(format[i] && format[i]!=dc[0])i++;
    }

    if(format[i]!=str[k])break;   /* bad spec */
    if(format[i]==dc[0] || format[i]== 0){
     /* reading */
     if(format[i]==0)fatal_error("Incorrect format specification. There must be %c.\n",dc[0]);
     *form_pos=i+1;
     strncpy(AcFormat,str,k);
     AcFormat[k]='\0';
     ac_helppos=next->helppos;
     ac_formpos=next->pos;
     return str+k+1;
    }

    k++;i++;

   }while(1);
   next=next->next;
  }
  l++;
 }while(ind<0 && l<CASHE_SIZE);
 AcFormat[0]='\0';
 if(stop_on_error>0){
  fatal_error("Can't find specification '%s' in file '%s' \n",format,cur_file_name);
 }
 if(stop_on_error<0){
  msg_error("Can't find specification '%s' in file '%s' \n",format,cur_file_name);
 }
 return NULL;
}
Exemplo n.º 8
0
int Open_param_file(const char *file){
 char str[1000];
 long pos, helppos;
 int ind,i/*,j*/;
 struct rparam *elem;

 if(cur_file)fatal_error("Parameter file is already initialized!\n");

 cur_file = fopen(file,"rb");
 if(!cur_file){
  if(stop_on_error==1)fatal_error("Cant open the file '%s'\n", file);
  else if(stop_on_error==-1)msg_error("Cant open the file '%s'\n", file);
  return 0;
 }

 strcpy(cur_file_name,file);
 init_Cashe();

 helppos=-1;
 do{
  i=0;
  pos=get_next_string(str,0);
  if(pos<0)return 1;
  while(str[i]==' ')i++;
  if(helppos<0 && str[i]==Help_char)helppos=pos;
  if(str[i]==Com_char)continue;

  /*
  j=0;
  while(str[i+j]!=':'){
   if(str[i+j]==0)break;
   j++;
  }
  if(!str[i+j])continue;

  ind=str[i]&0x07f;*/
  ind=get_code(str+i);
  //printf("%lx, %s, %d\n",pos,str,ind);
  if(ind==0){
    if(str[i]!=Help_char)helppos=-1;
    continue;
  }
  if(ind<0)ind=-ind;
  ind--;

  /*Err_malloc(elem,sizeof(struct rparam));*/
  elem=(struct rparam *)malloc(sizeof(struct rparam));
  if(!elem)fatal_error("Memory allocation error!\n");
  elem->next=Cashe[ind];
  Cashe[ind]=elem;
  elem->pos=pos;
  elem->helppos=helppos;
  helppos=-1;
 }while(1);
}
Exemplo n.º 9
0
int rprm(const char *format,va_list ap){
 int i/*,k,ind*/,res;
 //struct rparam *next;
 char arr[1000],*str1,*str;


 if(format[0]=='$'){ /* read in current position */
  do{
   ac_formpos=Get_cur_pos();
   str=arr;
   if(get_next_string(str,1)==-1){
    if(stop_on_error>0)fatal_error("End of file reached in file %s",cur_file_name);
    else if(stop_on_error<0)msg_error("End of file reached in file %s",cur_file_name);
    else return -1;
   }
   while(*str==' ' && *str)str++;
  }while(!*str);

  str1=strstr(format,dc);
  if(str1){
   format=str1+1;
   str1=strstr(str,dc);
   if(str1){
    *str1=0;
    strcpy(AcFormat,str);
    str=str1+1;
   }
   else AcFormat[0]='\0';
  }
  else format=format+1;
  i=0;
  ac_helppos=-1; /* no help assumed for current position */
 }
 else str=find_spec(format,arr,&i);

 if(str){
  if(format[i]=='>'){ /* It is very dangerous to use this option without any
                        args in ... !!! */
   //va_start(ap,format);
   str1=va_arg(ap,char *);
   strcpy(str1,str);
   return 1;
  }
  res=vsscanf(str,format+i,ap);
  if(res<0)
    return 0;
  return res;
 }
Exemplo n.º 10
0
/*
 * list_subset
 *
 *    Compares two lists.  All the elements in the first list must be
 *    in the second and neither may be empty lists.
 *
 *  pcSub    The list which must have all elements in pcSuper
 *  pcSuper  The list which must contain all or more elements than in pcSub
 *
 * Returns:
 *    0 if not a subset, 1 if it is a subset.
 *
 * Side effects:
 *    None.
 */
EXPORT int list_subset(const char *pcSub, const char *pcSuper) {

  int offset = 0;
  char c, *pcScope;

  if (!pcSub || !pcSuper ||                          /* either are NULL */
      (pcSub[0] == '\0' && pcSuper[0] != '\0')) {    /* sub empty, super not */
    return 0;
  }
     
  while((pcScope = get_next_string(",",pcSub,&offset,&c))) {
    if (!list_intersection(pcScope,pcSuper)) {
      SLPFree(pcScope);
      return 0;
    }
    SLPFree(pcScope);
  }

  return 1;
}
Exemplo n.º 11
0
char *infix2postfix(const char *expr, const size_t esize, const hefesto_int_t main_call) {

    const char *efinis = expr + esize, *e;
    char *t, *term, *tt;
    hefesto_common_stack_ctx *sp = NULL, *dp = NULL;
    hefesto_common_list_ctx *lp = NULL, *l;
    hefesto_int_t p, tp;
    size_t sz;
    hefesto_int_t bracket = 0;
    char *indexing;
    char *iexpr;
    char *args;
    size_t offset, count;
    hefesto_int_t state = 0;

    term = (char *) hefesto_mloc(HEFESTO_MAX_BUFFER_SIZE);
    memset(term, 0, HEFESTO_MAX_BUFFER_SIZE);

    t = term;
    *t = 0;

    for (e = expr; e != efinis; e++) {

        if (*e == 0) break;

        if (*e == '\n' || *e == '\r' || *e == '\t' || *e == ' ') continue;

        if (*e != 0 && *e != ' ' && *e != '\n' && *e != '\r' && *e != '\t' &&
            *e != '(' && *e != ')' && !is_op(*e) && *e != '[' &&
            !is_hefesto_string_tok(*e)) {
            *t = *e;
            t++;
            *t = 0;
            continue;
        } else if (is_hefesto_string_tok(*e)) {
            offset = 0;
            iexpr = get_next_string(e, &offset);
            e += offset;
            for (indexing = iexpr; *indexing != 0; indexing++, t++)
            *t = *indexing;
            free(iexpr);
            *t = 0;
        } else if (*e == '(' && !is_hefesto_numeric_constant(term) &&
               !is_hefesto_string(term) && *term && *term != '(' &&
               !is_op(*term)) {
            bracket++;
            offset = 0;
            args = get_next_call_args(e, &offset);

            if (*args) {
                iexpr = infix2postfix_function_args(args, strlen(args));
                tt = t;
                for (indexing = iexpr; *indexing != 0; indexing++, t++)
                    *t = *indexing;
                *t = 0;
                free(iexpr);
                count = 0;
                for (t = tt; *t != 0; t++) {
                    if (*t == '(') {
                        count++;
                    } else if (*t == ')') {
                        count--;
                    } else if (*t == '"') {
                        t++;
                        while (*t != '"' && *t != 0) {
                            t++;
                            if (*t == '\\') t += 2;
                        }
                    }
                }
                //  WARN(Santiago): null buffer position skipping avoidance.
                while (*t == 0 && t != term) {
                    t--;
                }
                t++;
                tt = ((char *)e + offset);
                while (is_hefesto_blank(*tt)) tt++;
                // can't add one more ')' because this is a function that is an
                // argument of another function
                if (*tt == ',') count--;
                while (count > 0) {
                    *t = ')';
                    t++;
                    count--;
                }
                *t = 0;
            }
            e += offset;
            free(args);
            if (*e == ')') e++;
        } else if ((*e == '-' || *e == '+') && t == term && isdigit(*(e+1)) &&
                   state == 0) {
            *t = *e;
            t++;
            continue;
        }

        if ((is_op(*e) || *e == '(' || *e == ')') && t == term) {
            *t = *e;
            t++;
            *t = 0;
            if (is_op(*(e+1)) && *e != '(' && *e != ')') { // composed operands
                *t = *(e+1);
                e++;
                t++;
                *t = 0;
            }
            state = 0;
        } else if ((e + 1) != efinis) e--;

        if (strcmp(term,"(") == 0) {
            sp = hefesto_common_stack_ctx_push(sp, (void *) term, t - term,
                                               HEFESTO_VAR_TYPE_UNTYPED);
        } else if(strcmp(term, ")") == 0) {
            t = (char *)hefesto_common_stack_ctx_data_on_top(sp);
            if (t && strcmp(t, "(") != 0) {
                while (sp && sp->data != NULL && strcmp(sp->data, "(") != 0) {
                    lp = add_data_to_hefesto_common_list_ctx(lp,
                                    hefesto_common_stack_ctx_data_on_top(sp),
                                    hefesto_common_stack_ctx_dsize_on_top(sp));
                    dp = hefesto_common_stack_ctx_on_top(sp);
                    sp = hefesto_common_stack_ctx_pop(sp);
                    del_hefesto_common_stack_ctx(dp);
                }
            }
            dp = hefesto_common_stack_ctx_on_top(sp);
            sp = hefesto_common_stack_ctx_pop(sp);
            del_hefesto_common_stack_ctx(dp);
        } else if ((p = get_op_precedence(term)) != -1) {

            tp = get_op_precedence(hefesto_common_stack_ctx_data_on_top(sp)); 

            while (tp != -1 && tp >= p) {
                lp = add_data_to_hefesto_common_list_ctx(lp,
                                    hefesto_common_stack_ctx_data_on_top(sp),
                                    hefesto_common_stack_ctx_dsize_on_top(sp));
                dp = hefesto_common_stack_ctx_on_top(sp);
                sp = hefesto_common_stack_ctx_pop(sp);
                del_hefesto_common_stack_ctx(dp);
                tp = get_op_precedence(hefesto_common_stack_ctx_data_on_top(sp)); 
            }

            sp = hefesto_common_stack_ctx_push(sp, (void *) term, t - term,
                                                   HEFESTO_VAR_TYPE_UNTYPED);
        } else {
            lp = add_data_to_hefesto_common_list_ctx(lp, term, t - term);
            state = 1;
        }
        t = term;
        *t = 0;

    }

    if (*term) {
        sp = hefesto_common_stack_ctx_push(sp, (void *) term, t - term,
                                           HEFESTO_VAR_TYPE_UNTYPED);
    }

    while (!hefesto_common_stack_ctx_empty(sp)) {
        lp = add_data_to_hefesto_common_list_ctx(lp,
                        hefesto_common_stack_ctx_data_on_top(sp),
                        hefesto_common_stack_ctx_dsize_on_top(sp));
        dp = hefesto_common_stack_ctx_on_top(sp);
        sp = hefesto_common_stack_ctx_pop(sp);
        del_hefesto_common_stack_ctx(dp);
    }

    free(term);

    for (p = 0, sz = 0, l = lp; l; l = l->next, p++) {
        sz += l->dsize;
    }

    sz += (size_t) p;

    term = (char *) hefesto_mloc(sz);
    *term = 0;

    for (l = lp; l; l = l->next) {
        if (*(char *)l->data == '(') continue;
        strncat(term, (char *) l->data, sz - 1);
        if (l->next && *(char *)l->next->data != '[')
        strncat(term, " ", sz - 1);
    }

    del_hefesto_common_list_ctx(lp);
    return term;

}
Exemplo n.º 12
0
bool ScanDataBuilder::parse_content(char*& buffer, size_t& size, ScanData& data) {
    return get_next_string(buffer, size, data.content, sizeof(data.content));
}
Exemplo n.º 13
0
bool ScanDataBuilder::parse_command_type(char*& buffer, size_t& size,
        ScanData& data) {
    return get_next_string(buffer, size, data.command_type,
            sizeof(data.command_type));
}
Exemplo n.º 14
0
/*
 * list_merge
 *
 *   This function will build a list of unique elements.  It assumes
 *   that the items arriving with pcNewList are packed, for efficiency.
 *   If the list grows too large, it will be grown to take in the new
 *   string and 'breathing room' for further expansion.
 *
 *     pcNewList    The new list to merge in with the old one.
 *     ppcList      A pointer to the buffer with the list to be built onto.
 *     piListLen    The max size of the list list to be build onto.
 *     iCheck       If this is 0, don't check for duplicates.
 *
 * Returns:  None.
 * 
 * Side Effects:
 *
 *   A call to this function can result in *ppcList (the buffer) being
 *   reallocated and *piListLen (the max buffer size) being expanded.)
 */
EXPORT void list_merge(const char *pcNewList, char **ppcList, int *piListLen, int iCheck)
{
    int offset = 0;
    char c, *pcScope;
    int initial = 0;
    
    if (!pcNewList) 
        return;
    
    if (!ppcList)
        return;
    
    if (!*ppcList)
    {
        *ppcList = safe_malloc(strlen(pcNewList)+1,pcNewList,strlen(pcNewList));
        *piListLen = strlen(*ppcList);
        return;
    }
    
    if (*piListLen == 0) 
        initial = 1; /* suppresses initial comma in new lists */
    
    if (!iCheck) 
    {
        int iSLen = strlen(pcNewList);
        if ((iSLen + (int) strlen(*ppcList)+1) >= *piListLen) 
        { /* too big? */
            char *pcOld = *ppcList;
            *piListLen += iSLen + LISTINCR;
            *ppcList = safe_malloc(*piListLen,*ppcList,strlen(*ppcList));
            SLPFree(pcOld);
        }
        
        if (!initial) 
            slp_strcat(*ppcList,",");
            
        slp_strcat(*ppcList,pcNewList);
        return;
    }
    
    while((pcScope = get_next_string(",",pcNewList,&offset,&c))) 
    {
        if (!list_intersection(pcScope,*ppcList)) 
        {
            int iSLen = strlen(pcScope);
        
            if ((iSLen + (int) strlen(*ppcList)+1) >= *piListLen) 
            { /* too big? */
                char *pcOld = *ppcList;
                *piListLen += iSLen + LISTINCR;
                *ppcList = safe_malloc(*piListLen,*ppcList,strlen(*ppcList));
                SLPFree(pcOld);
            }
    
            if (initial != 1) 
                slp_strcat(*ppcList,","); /* supress initial comma */
        
            slp_strcat(*ppcList,pcScope); /* append the scope not already on list */
        }
        
        SLPFree(pcScope);
    }   
}
Exemplo n.º 15
0
static int json_parse_string(char *start, struct JSON *node, int *offset, char **msg)
{
	return get_next_string(start, &node->data.string, offset, msg);
}