Exemplo n.º 1
0
static void test_purge_old_connections_purge_middle(void)
{
    const time_t time_now = 100000;

    Item *connections = NULL;
    char time_str[64];

    snprintf(time_str, sizeof(time_str), "%ld", time_now - CONNECTION_MAX_AGE_SECONDS);
    PrependItem(&connections, "123.123.123.3", time_str);

    snprintf(time_str, sizeof(time_str), "%ld", time_now - CONNECTION_MAX_AGE_SECONDS - 1);
    PrependItem(&connections, "123.123.123.2", time_str);

    snprintf(time_str, sizeof(time_str), "%ld", time_now - CONNECTION_MAX_AGE_SECONDS + 100);
    PrependItem(&connections, "123.123.123.1", time_str);

    assert_int_equal(ListLen(connections), 3);

    PurgeOldConnections(&connections, time_now);

    assert_int_equal(ListLen(connections), 2);

    assert_true(IsItemIn(connections, "123.123.123.1"));
    assert_false(IsItemIn(connections, "123.123.123.2"));
    assert_true(IsItemIn(connections, "123.123.123.3"));

    DeleteItemList(connections);
}
Exemplo n.º 2
0
void help_MatchFound(xmlNode *node, xmlNode **MatchNode, List *TopicWords, int *MatchTextPos, int *Nmatches, int *ambiguous, char **HelpPosition, char **HelpTexts)
 {
  int   abbreviation,i;
  List *PrevMatchPosition;

  if ((*Nmatches)==MAX_HELP_HITS) { ppl_error(ERR_INTERNAL, -1, -1, "Cannot parse ppl_help.xml. Need to increase MAX_HELP_HITS."); return; }
  help_TopicPrint(HelpTexts[*Nmatches], HelpPosition, ListLen(TopicWords));
  if (*ambiguous == 0)
   {
    if (*MatchNode == NULL)
     {
      *MatchTextPos = 0;
      *MatchNode    = node; // This is the first match we've found
     } else {
      PrevMatchPosition = StrSplit( HelpTexts[*MatchTextPos] );

      abbreviation = 1; // If previous match is an autocomplete shortening of current match, let it stand
      for (i=0; i<=ListLen(TopicWords); i++) if (StrAutocomplete( (char *)ListGetItem(PrevMatchPosition,i) , HelpPosition[i] , 1)==-1) {abbreviation=0; break;}
      if (abbreviation!=1)
       {
        abbreviation = 1; // If current match is an autocomplete shortening of previous match, the current match wins
        for (i=0; i<=ListLen(TopicWords); i++) if (StrAutocomplete( HelpPosition[i] , (char *)ListGetItem(PrevMatchPosition,i) , 1)==-1) {abbreviation=0; break;}
        if (abbreviation==1)
         {
          *MatchTextPos = *Nmatches;
          *MatchNode    = node;
         } else {
          *ambiguous = 1; // We have multiple ambiguous matches
         }
       }
     }
   }
  (*Nmatches)++;
  return;
 }
    ListNode *getIntersectionNode1(ListNode *headA, ListNode *headB){
        if(headA == NULL || headB == NULL) return NULL;
        int lenA= ListLen(headA);
        int lenB = ListLen(headB);
        int count = (lenA > lenB)? (lenA - lenB): (lenB - lenA);
        ListNode *longHead, *shortHead;
        if(lenA >= lenB){
            longHead = headA;
            shortHead = headB;
        }else{
            longHead = headB;
            shortHead = headA;
        }

        while(count){
            longHead = longHead->next;
            count--;
        }

        while(longHead != NULL){
            if(longHead == shortHead){
                return longHead;
            }
            longHead = longHead->next;
            shortHead = shortHead->next;
        }
        return NULL;
    };
Exemplo n.º 4
0
/* NB: does not escape entries in list ! */
char *ItemList2CSV(const Item *list)
{
    /* After each entry, we need space for either a ',' (before the
     * next entry) or a final '\0'. */
    int len = ItemListSize(list) + ListLen(list);
    char *s = xmalloc(len);
    *s = '\0';

    /* No point cycle-checking; done while computing len. */
    for (const Item *ip = list; ip != NULL; ip = ip->next)
    {
        if (ip->name)
        {
            strcat(s, ip->name);
        }

        if (ip->next)
        {
            strcat(s, ",");
        }
    }
    assert(strlen(s) + 1 == len);

    return s;
}
Exemplo n.º 5
0
/* Given the argument list, parse it into ArgList format. */
ArgList ParseArgList(VyObj list){
    int num = CountParams(list);
    Param* params = VyMalloc(sizeof(Param) * num);
    int i;

    /* Each element of the list is either a parameter or an argument mode setting symbol...
     * Check if it sets the argument type (?, ~, or ..), and if it doesn't, parse it as a parameter 
     */
    VyObj opt_arg_set = CreateSymbol("?");
    VyObj rest_arg_set = CreateSymbol("..");

    bool opt, rest;
    opt = rest = false;

    int param_num = 0;
    int arg_list_len = ListLen(list);
    for(i = 0; i < arg_list_len; i++){
        VyObj next = ListGet(UNWRAP(list, VyCons), i);

        if(ObjEq(next, opt_arg_set)){
            opt = true;
        }
        else if(ObjEq(next, rest_arg_set)){
            opt = rest = true;
        }
        else {
            params[param_num] = ParseParam(next, opt, rest);
            param_num++;
        }

    }

    ArgList args = {num_params: num, params: params};
    return args;
}
Exemplo n.º 6
0
void main()
{	
	struct node* head = AddAtTail();
	printf("List len = %d\n", ListLen(head));
	PrintList(head);
	DeleteList(head);
}
Exemplo n.º 7
0
bool ListsCompare(const Item *list1, const Item *list2)
{
    if (ListLen(list1) != ListLen(list2))
    {
        return false;
    }

    for (const Item *ptr = list1; ptr != NULL; ptr = ptr->next)
    {
        if (IsItemIn(list2, ptr->name) == false)
        {
            return false;
        }
    }

    return true;
}
Exemplo n.º 8
0
Arquivo: syntax.c Projeto: dnaeon/core
static void CheckParseReal(char *lval, char *s, const char *range)
{
    Item *split;
    double max = (double) CF_LOWINIT, min = (double) CF_HIGHINIT, val;
    int n;
    char output[CF_BUFSIZE];

    CfDebug("\nCheckParseReal(%s => %s/%s)\n", lval, s, range);

    if (s == NULL)
    {
        return;
    }

    if (strcmp(s, "inf") == 0)
    {
        ReportError("keyword \"inf\" has an integer value, cannot be used as real");
        return;
    }

    if (IsCf3VarString(s))
    {
        CfDebug("Validation: Unable to verify syntax of real %s due to variable expansion at this stage\n", s);
        return;
    }

/* Numeric types are registered by range separated by comma str "min,max" */

    split = SplitString(range, ',');

    if ((n = ListLen(split)) != 2)
    {
        FatalError("INTERN:format specifier for real rvalues is not ok for lval %s - %d items", lval, n);
    }

    sscanf(split->name, "%lf", &min);
    sscanf(split->next->name, "%lf", &max);
    DeleteItemList(split);

    if (min == CF_HIGHINIT || max == CF_LOWINIT)
    {
        FatalError("INTERN:could not parse format specifier for int rvalues for lval %s", lval);
    }

    val = Str2Double(s);

    if (val > max || val < min)
    {
        snprintf(output, CF_BUFSIZE,
                 "Real item on rhs of lval \'%s\' give as {%s => %.3lf} is out of bounds (should be in [%s])", lval, s,
                 val, range);
        ReportError(output);
    }

    CfDebug("CheckParseReal - syntax verified\n\n");
}
Exemplo n.º 9
0
static void test_list_len(void)
{
    Item *list = NULL;

    PrependItem(&list, "one", "classes");
    PrependItem(&list, "two", NULL);
    PrependItem(&list, "three", NULL);
    assert_int_equal(ListLen(list), 3);
    DeleteItemList(list);
}
Exemplo n.º 10
0
static SyntaxTypeMatch CheckParseInt(const char *lval, const char *s, const char *range)
{
    Item *split;
    int n;
    long max = CF_LOWINIT, min = CF_HIGHINIT, val;

/* Numeric types are registered by range separated by comma str "min,max" */
    CfDebug("\nCheckParseInt(%s => %s/%s)\n", lval, s, range);

    split = SplitString(range, ',');

    if ((n = ListLen(split)) != 2)
    {
        ProgrammingError("INTERN: format specifier for int rvalues is not ok for lval %s - got %d items", lval, n);
    }

    sscanf(split->name, "%ld", &min);

    if (strcmp(split->next->name, "inf") == 0)
    {
        max = CF_INFINITY;
    }
    else
    {
        sscanf(split->next->name, "%ld", &max);
    }

    DeleteItemList(split);

    if (min == CF_HIGHINIT || max == CF_LOWINIT)
    {
        ProgrammingError("INTERN: could not parse format specifier for int rvalues for lval %s", lval);
    }

    if (IsCf3VarString(s))
    {
        return SYNTAX_TYPE_MATCH_ERROR_UNEXPANDED;
    }

    val = IntFromString(s);

    if (val == CF_NOINT)
    {
        return SYNTAX_TYPE_MATCH_ERROR_INT_PARSE;
    }

    if (val > max || val < min)
    {
        return SYNTAX_TYPE_MATCH_ERROR_INT_OUT_OF_RANGE;
    }

    CfDebug("CheckParseInt - syntax verified\n\n");

    return SYNTAX_TYPE_MATCH_OK;
}
Exemplo n.º 11
0
bool ListsCompare(const Item *list1, const Item *list2)
{
    if (ListLen(list1) != ListLen(list2))
    {
        return false;
    }

    const Item *ptr = list1;
    CYCLE_DECLARE(ptr, slow, toggle);
    while (ptr != NULL)
    {
        if (IsItemIn(list2, ptr->name) == false)
        {
            return false;
        }
        ptr = ptr->next;
        CYCLE_CHECK(ptr, slow, toggle);
    }

    return true;
}
Exemplo n.º 12
0
void help_explore(xmlNode *node, xmlNode **MatchNode, List *TopicWords, int *MatchTextPos, int *Nmatches, int *ambiguous, char **HelpPosition, char **HelpTexts, int depth)
 {
  xmlNode *cur_node = NULL;
  int match,i;

  if (depth>ListLen(TopicWords)) return;
  if (depth==MAX_HELP_DEPTH) { ppl_error(ERR_INTERNAL, -1, -1, "Cannot parse ppl_help.xml. Need to increase MAX_HELP_DEPTH."); return; }

  for (cur_node = node; cur_node; cur_node = cur_node->next) // Loop over siblings
   {
    match=1;
    if (cur_node->type == XML_ELEMENT_NODE)
     {
      sprintf(HelpPosition[depth], "%s", cur_node->name); // Converted signedness of chars
      for (i=1;i<=depth;i++) if (StrAutocomplete( (char *)ListGetItem(TopicWords,i-1) , HelpPosition[i], 1)==-1) {match=0; break;}
      if ((match==1) && (depth==ListLen(TopicWords))) help_MatchFound(cur_node,MatchNode,TopicWords,MatchTextPos,Nmatches,ambiguous,HelpPosition,HelpTexts);
     }
    if (match==1) help_explore(cur_node->children,MatchNode,TopicWords,MatchTextPos,Nmatches,ambiguous,HelpPosition,HelpTexts,depth+1);
   }
  return;
 }
Exemplo n.º 13
0
static PyObject *pattern_get_class(PyObject *self,      PyObject *args)
{
  int ok=true;
  int int1;
  PyObject *result = NULL;
  PyObject *O,*l1,*l2;
  CChamp *I;
  ListPat *pat;
  ListAtom *at;
  ListBond *bd;
  int a,b;
  int n_atom,n_bond;
  ok = PyArg_ParseTuple(args,"Oi",&O,&int1);
  ok = PyCObject_Check(O);
  if(ok) {
    I = PyCObject_AsVoidPtr(O);
    pat = I->Pat+int1;
    
    n_atom = ListLen(I->Atom,pat->atom);
    at = I->Atom + pat->atom;
    l1 = PyList_New(n_atom);
    for(a=0;a<n_atom;a++) {
      PyList_SetItem(l1,a,PyInt_FromLong(at->class));
      at = I->Atom + at->link;
    }

    n_bond = ListLen(I->Bond,pat->bond);
    l2 = PyList_New(n_bond);
    bd = I->Bond + pat->bond;
    for(b=0;b<n_bond;b++) {
      PyList_SetItem(l2,b,PyInt_FromLong(bd->class));
      bd = I->Bond + bd->link;
    }

    result = PyList_New(2);
    PyList_SetItem(result,0,l1);
    PyList_SetItem(result,1,l2);
  }
  return(RetObj(ok,result));
}
Exemplo n.º 14
0
int *IListVal(descriptor d)		/*: make int[] array from list */
   {
   int *a;
   int n = ListLen(d);
   descriptor slot[n];
   int i;

   cpslots(&d,&slot[0],1,n+1);
   a = (int *) calloc(n, sizeof(int));
   if (!a) return NULL;
   for (i=0; i<n; i++) a[i] = IntegerVal(slot[i]);
   return &a[0];
   }
Exemplo n.º 15
0
double *RListVal(descriptor d)		/*: make double[] array from list */
   {
   double *a;
   int n = ListLen(d);
   descriptor slot[n];
   int i;

   cpslots(&d,&slot[0],1,n+1);
   a = (double *) calloc(n, sizeof(double));
   if (!a) return NULL;
   for (i=0; i<n; i++) a[i] = RealVal(slot[i]);
   return &a[0];
   }
Exemplo n.º 16
0
struct BU_Unit *BU_DuplicateUnit(struct BU_Struct *str, struct BU_Unit *unit, int skip, struct BU_Unit *linkedFrom)
{
  struct BU_Unit *dup;
  int i;
  char name[NODE_NAME_LENGTH];

  if(str==0||unit==0)
    {
      return NULL;
    }

  sprintf(name,"%c",'a'+ListLen(&str->Units));

  dup=(struct BU_Unit *)ME_CreateNode(&UnitMethod, &(str->Units), name);
  if(!dup)
    {
      return NULL;
    }
  dup->Error=unit->Error;
  dup->HError=unit->HError;
  dup->CError=unit->CError;
  /*  dup->CHError=unit->CHError;
  dup->HHError=unit->HHError;
  */
  dup->Residue=unit->Residue;
  dup->Position=unit->Position;
  dup->Shifts.Type=unit->Shifts.Type;
  
  if(skip>=0)
    {
      dup->Subst[skip]=linkedFrom;
    }
      
  for(i=TY_MAX_BONDS-1;i>=0;i--)
    {
      if(i!=skip && i!=BU_ANOMER_POS(unit))
	{
	  dup->Subst[i]=unit->Subst[i];
	  if(dup->Subst[i])
	    {
	      dup->Subst[i]=BU_DuplicateUnit(str,unit->Subst[i],-1,0);
	      dup->Subst[i]->Position=i;
	      dup->Subst[i]->Subst[BU_ANOMER_POS(dup->Subst[i])]=dup;
	    }
	}
    }

  return dup;
}
Exemplo n.º 17
0
static SyntaxTypeMatch CheckParseReal(const char *lval, const char *s, const char *range)
{
    Item *split;
    double max = (double) CF_LOWINIT, min = (double) CF_HIGHINIT, val;
    int n;

    CfDebug("\nCheckParseReal(%s => %s/%s)\n", lval, s, range);

    if (strcmp(s, "inf") == 0)
    {
        return SYNTAX_TYPE_MATCH_ERROR_REAL_INF;
    }

    if (IsCf3VarString(s))
    {
        return SYNTAX_TYPE_MATCH_ERROR_UNEXPANDED;
    }

/* Numeric types are registered by range separated by comma str "min,max" */

    split = SplitString(range, ',');

    if ((n = ListLen(split)) != 2)
    {
        ProgrammingError("Format specifier for real rvalues is not ok for lval %s - %d items", lval, n);
    }

    sscanf(split->name, "%lf", &min);
    sscanf(split->next->name, "%lf", &max);
    DeleteItemList(split);

    if (min == CF_HIGHINIT || max == CF_LOWINIT)
    {
        ProgrammingError("Could not parse format specifier for int rvalues for lval %s", lval);
    }

    if (!DoubleFromString(s, &val))
    {
        return SYNTAX_TYPE_MATCH_ERROR_REAL_OUT_OF_RANGE;
    }

    if (val > max || val < min)
    {
        return SYNTAX_TYPE_MATCH_ERROR_REAL_OUT_OF_RANGE;
    }

    return SYNTAX_TYPE_MATCH_OK;
}
Exemplo n.º 18
0
static PyObject *pattern_get_codes(PyObject *self,      PyObject *args)
{
  int ok=true;
  int int1,ai,bi;
  PyObject *result = NULL;
  PyObject *O,*l1,*l2;
  CChamp *I;
  ListPat *pat;
  ListAtom *at;
  ListBond *bd;
  int a,b;
  int n_atom,n_bond;
  char code[255],atom[10];

  ok = PyArg_ParseTuple(args,"Oi",&O,&int1);
  ok = PyCObject_Check(O);
  if(ok) {
    I = PyCObject_AsVoidPtr(O);
    pat = I->Pat+int1;
    n_atom = ListLen(I->Atom,pat->atom);
    ai = pat->atom;
    l1 = PyList_New(n_atom);
    for(a=0;a<n_atom;a++) {
      at = I->Atom + ai;

      if(at->class&cH_Aliphatic)
        code[0]='A';
      else if(at->class&cH_Aromatic)
        code[0]='R';
      else
        code[0]='P';
      if(at->cycle&(cH_Ring3|cH_Ring4|cH_Ring5|cH_Ring6|cH_Ring7))
        code[1]='C';
      else 
        code[1]='X';
      code[2]=0;
      ChampAtomToString(I,ai,atom);
      if(atom[0]>96)
        atom[0]-=32;
      strcat(code,atom);
      PyList_SetItem(l1,a,PyString_FromString(code));
      ai = at->link;
    }
Exemplo n.º 19
0
Arquivo: syntax.c Projeto: dnaeon/core
static void CheckParseIntRange(char *lval, char *s, const char *range)
{
    Item *split, *ip, *rangep;
    int n;
    long max = CF_LOWINIT, min = CF_HIGHINIT, val;
    char output[CF_BUFSIZE];

    if (s == NULL)
    {
        return;
    }

/* Numeric types are registered by range separated by comma str "min,max" */
    CfDebug("\nCheckParseIntRange(%s => %s/%s)\n", lval, s, range);

    if (*s == '[' || *s == '(')
    {
        ReportError("Range specification should not be enclosed in brackets - just \"a,b\"");
        return;
    }

    split = SplitString(range, ',');

    if ((n = ListLen(split)) != 2)
    {
        FatalError("INTERN:format specifier %s for irange rvalues is not ok for lval %s - got %d items", range, lval,
                   n);
    }

    sscanf(split->name, "%ld", &min);

    if (strcmp(split->next->name, "inf") == 0)
    {
        max = CF_INFINITY;
    }
    else
    {
        sscanf(split->next->name, "%ld", &max);
    }

    DeleteItemList(split);

    if (min == CF_HIGHINIT || max == CF_LOWINIT)
    {
        FatalError("INTERN: could not parse irange format specifier for int rvalues for lval %s", lval);
    }

    if (IsCf3VarString(s))
    {
        CfDebug("Validation: Unable to verify syntax of int \'%s\' due to variable expansion at this stage\n", s);
        return;
    }

    rangep = SplitString(s, ',');

    if ((n = ListLen(rangep)) != 2)
    {
        snprintf(output, CF_BUFSIZE,
                 "Int range format specifier for lval %s should be of form \"a,b\" but got %d items", lval, n);
        ReportError(output);
        DeleteItemList(rangep);
        return;
    }

    for (ip = rangep; ip != NULL; ip = ip->next)
    {
        val = Str2Int(ip->name);

        if (val > max || val < min)
        {
            snprintf(output, CF_BUFSIZE,
                     "Int range item on rhs of lval \'%s\' given as {%s => %ld} is out of bounds (should be in [%s])",
                     lval, s, val, range);
            ReportError(output);
            DeleteItemList(rangep);
            return;
        }
    }

    DeleteItemList(rangep);

    CfDebug("CheckParseIntRange - syntax verified\n\n");
}
Exemplo n.º 20
0
static void ArmClasses(Averages av, char *timekey)
{
    double sigma;
    Item *ip,*classlist = NULL;
    int i, j, k;
    char buff[CF_BUFSIZE], ldt_buff[CF_BUFSIZE], name[CF_MAXVARSIZE];
    static int anomaly[CF_OBSERVABLES][LDT_BUFSIZE];
    extern Item *ALL_INCOMING;
    extern Item *MON_UDP4, *MON_UDP6, *MON_TCP4, *MON_TCP6;

    for (i = 0; i < CF_OBSERVABLES; i++)
    {
        char desc[CF_BUFSIZE];

        GetObservable(i, name, desc);
        sigma = SetClasses(name, CF_THIS[i], av.Q[i].expect, av.Q[i].var, LOCALAV.Q[i].expect, LOCALAV.Q[i].var, &classlist, timekey);
        SetVariable(name, CF_THIS[i], av.Q[i].expect, sigma, &classlist);

        /* LDT */

        ldt_buff[0] = '\0';

        anomaly[i][LDT_POS] = false;

        if (!LDT_FULL)
        {
            anomaly[i][LDT_POS] = false;
        }

        if (LDT_FULL && (CHI[i] > CHI_LIMIT[i]))
        {
            anomaly[i][LDT_POS] = true; /* Remember the last anomaly value */

            Log(LOG_LEVEL_VERBOSE, "LDT(%d) in %s chi = %.2f thresh %.2f ", LDT_POS, name, CHI[i], CHI_LIMIT[i]);

            /* Last printed element is now */

            for (j = LDT_POS + 1, k = 0; k < LDT_BUFSIZE; j++, k++)
            {
                if (j == LDT_BUFSIZE)   /* Wrap */
                {
                    j = 0;
                }

                if (anomaly[i][j])
                {
                    snprintf(buff, CF_BUFSIZE, " *%.2f*", LDT_BUF[i][j]);
                }
                else
                {
                    snprintf(buff, CF_BUFSIZE, " %.2f", LDT_BUF[i][j]);
                }

                strcat(ldt_buff, buff);
            }

            if (CF_THIS[i] > av.Q[i].expect)
            {
                snprintf(buff, CF_BUFSIZE, "%s_high_ldt", name);
            }
            else
            {
                snprintf(buff, CF_BUFSIZE, "%s_high_ldt", name);
            }

            AppendItem(&classlist, buff, "2");
            EvalContextHeapPersistentSave(buff, "measurements", CF_PERSISTENCE, CONTEXT_STATE_POLICY_PRESERVE);
        }
        else
        {
            for (j = LDT_POS + 1, k = 0; k < LDT_BUFSIZE; j++, k++)
            {
                if (j == LDT_BUFSIZE)   /* Wrap */
                {
                    j = 0;
                }

                if (anomaly[i][j])
                {
                    snprintf(buff, CF_BUFSIZE, " *%.2f*", LDT_BUF[i][j]);
                }
                else
                {
                    snprintf(buff, CF_BUFSIZE, " %.2f", LDT_BUF[i][j]);
                }
                strcat(ldt_buff, buff);
            }
        }
    }

    SetMeasurementPromises(&classlist);

    // Report on the open ports, in various ways

    AddOpenPortsClasses("listening_ports", ALL_INCOMING, &classlist);
    AddOpenPortsClasses("listening_udp6_ports", MON_UDP6, &classlist);
    AddOpenPortsClasses("listening_udp4_ports", MON_UDP4, &classlist);
    AddOpenPortsClasses("listening_tcp6_ports", MON_TCP6, &classlist);
    AddOpenPortsClasses("listening_tcp4_ports", MON_TCP4, &classlist);

    // Port addresses

    if (ListLen(MON_TCP6) + ListLen(MON_TCP4) > 512)
    {
        Log(LOG_LEVEL_INFO, "Disabling address information of TCP ports in LISTEN state: more than 512 listening ports are detected");
    }
    else
    {
        for (ip = MON_TCP6; ip != NULL; ip=ip->next)
        {
            snprintf(buff,CF_BUFSIZE,"tcp6_port_addr[%s]=%s",ip->name,ip->classes);
            AppendItem(&classlist,buff,NULL);       
        }

        for (ip = MON_TCP4; ip != NULL; ip=ip->next)
        {
            snprintf(buff,CF_BUFSIZE,"tcp4_port_addr[%s]=%s",ip->name,ip->classes);
            AppendItem(&classlist,buff,NULL);       
        }
    }

    for (ip = MON_UDP6; ip != NULL; ip=ip->next)
    {
        snprintf(buff,CF_BUFSIZE,"udp6_port_addr[%s]=%s",ip->name,ip->classes);
        AppendItem(&classlist,buff,NULL);       
    }
    
    for (ip = MON_UDP4; ip != NULL; ip=ip->next)
    {
        snprintf(buff,CF_BUFSIZE,"udp4_port_addr[%s]=%s",ip->name,ip->classes);
        AppendItem(&classlist,buff,NULL);       
    }
    
    PublishEnvironment(classlist);

    DeleteItemList(classlist);
}
Exemplo n.º 21
0
static SyntaxTypeMatch CheckParseRealRange(const char *lval, const char *s, const char *range)
{
 Item *split, *rangep, *ip;
 double max = (double) CF_LOWINIT, min = (double) CF_HIGHINIT, val;
 int n;

 if (*s == '[' || *s == '(')
    {
    return SYNTAX_TYPE_MATCH_ERROR_RANGE_BRACKETED;
    }

 if (strcmp(s, "inf") == 0)
    {
    return SYNTAX_TYPE_MATCH_ERROR_REAL_INF;
    }

 if (IsCf3VarString(s))
    {
    return SYNTAX_TYPE_MATCH_ERROR_UNEXPANDED;
    }

/* Numeric types are registered by range separated by comma str "min,max" */

 split = SplitString(range, ',');

 if ((n = ListLen(split)) != 2)
    {
    ProgrammingError("Format specifier for real rvalues is not ok for lval %s - %d items", lval, n);
    }

 sscanf(split->name, "%lf", &min);
 sscanf(split->next->name, "%lf", &max);
 DeleteItemList(split);

 if (min == CF_HIGHINIT || max == CF_LOWINIT)
    {
    ProgrammingError("Could not parse format specifier for int rvalues for lval %s", lval);
    }

 rangep = SplitString(s, ',');

 if ((n = ListLen(rangep)) != 2)
    {
    return SYNTAX_TYPE_MATCH_ERROR_RANGE_MULTIPLE_ITEMS;
    }

 for (ip = rangep; ip != NULL; ip = ip->next)
    {
    if (!DoubleFromString(ip->name, &val))
       {
       return SYNTAX_TYPE_MATCH_ERROR_REAL_OUT_OF_RANGE;
       }

    if (val > max || val < min)
       {
       return SYNTAX_TYPE_MATCH_ERROR_REAL_OUT_OF_RANGE;
       }
    }

 DeleteItemList(rangep);

 return SYNTAX_TYPE_MATCH_OK;
}
Exemplo n.º 22
0
static SyntaxTypeMatch CheckParseIntRange(const char *lval, const char *s, const char *range)
{
 Item *split, *ip, *rangep;
 int n;
 long long max = CF_LOWINIT, min = CF_HIGHINIT;

 // Numeric types are registered by range separated by comma str "min,max"
 if (*s == '[' || *s == '(')
    {
    return SYNTAX_TYPE_MATCH_ERROR_RANGE_BRACKETED;
    }

 split = SplitString(range, ',');

 if ((n = ListLen(split)) != 2)
    {
    ProgrammingError("Format specifier %s for irange rvalues is not ok for lval %s - got %d items", range, lval, n);
    }

 sscanf(split->name, "%lld", &min);

 if (strcmp(split->next->name, "inf") == 0)
    {
    max = CF_INFINITY;
    }
 else
    {
    sscanf(split->next->name, "%lld", &max);
    }

 DeleteItemList(split);

 if (min == CF_HIGHINIT || max == CF_LOWINIT)
    {
    ProgrammingError("Could not parse irange format specifier for int rvalues for lval %s", lval);
    }

 if (IsCf3VarString(s))
    {
    return SYNTAX_TYPE_MATCH_ERROR_UNEXPANDED;
    }

 rangep = SplitString(s, ',');

 if ((n = ListLen(rangep)) != 2)
    {
    return SYNTAX_TYPE_MATCH_ERROR_RANGE_MULTIPLE_ITEMS;
    }

 for (ip = rangep; ip != NULL; ip = ip->next)
    {
    long val = IntFromString(ip->name);

    if (val > max || val < min)
       {
       return SYNTAX_TYPE_MATCH_ERROR_INT_OUT_OF_RANGE;
       }
    }

 DeleteItemList(rangep);

 return SYNTAX_TYPE_MATCH_OK;
}
Exemplo n.º 23
0
    int Ardb::GetValueByPattern(Context& ctx, const Slice& pattern, Data& subst, Data& value,
            ValueObjectMap* meta_cache)
    {
        const char *p, *f;
        const char* spat;
        /* If the pattern is "#" return the substitution object itself in order
         * to implement the "SORT ... GET #" feature. */
        spat = pattern.data();
        if (spat[0] == '#' && spat[1] == '\0')
        {
            value = subst;
            return 0;
        }

        /* If we can't find '*' in the pattern we return NULL as to GET a
         * fixed key does not make sense. */
        p = strchr(spat, '*');
        if (!p)
        {
            return -1;
        }
        std::string vstr;
        subst.GetDecodeString(vstr);

        f = strstr(spat, "->");
        if (NULL != f && (uint32) (f - spat) == (pattern.size() - 2))
        {
            f = NULL;
        }
        std::string keystr(pattern.data(), pattern.size());
        string_replace(keystr, "*", vstr);

        if (f == NULL)
        {
            /*
             * keystr = "len(...)"
             */
            if (keystr.find("len(") == 0 && keystr.rfind(")") == keystr.size() - 1)
            {
                keystr = keystr.substr(4, keystr.size() - 5);

                KeyType keytype = KEY_END;
                GetType(ctx, keystr, keytype);
                switch (keytype)
                {
                    case SET_META:
                    {
                        SetLen(ctx, keystr);
                        break;
                    }
                    case LIST_META:
                    {
                        ListLen(ctx, keystr);
                        break;
                    }
                    case ZSET_META:
                    {
                        ZSetLen(ctx, keystr);
                        break;
                    }
                    default:
                    {
                        return -1;
                    }
                }
                value.SetInt64(ctx.reply.integer);
                value.ToString();
                return 0;
            }
            ValueObject vv;
            int ret = StringGet(ctx, keystr, vv);
            if (0 == ret)
            {
                value = vv.meta.str_value;
                //value.ToString();
            }
            return ret;
        }
        else
        {
            size_t pos = keystr.find("->");
            std::string field = keystr.substr(pos + 2);
            keystr = keystr.substr(0, pos);
            int ret = 0;
            if (NULL == meta_cache)
            {
                ret = HashGet(ctx, keystr, field, value);
            }
            else
            {
                ValueObjectMap::iterator fit = meta_cache->find(keystr);
                if (fit == meta_cache->end())
                {
                    ValueObject meta;
                    GetMetaValue(ctx, keystr, HASH_META, meta);
                    fit = meta_cache->insert(ValueObjectMap::value_type(keystr, meta)).first;
                }
                Data ff;
                ff.SetString(field, true);
                ret = HashGet(ctx, fit->second, ff, value);
            }
            //value.ToString();
            return ret;
        }
    }
Exemplo n.º 24
0
static bool GetLMSensors(double *cf_this)
{
    FILE *pp;
    Item *ip, *list = NULL;
    double temp = 0;
    char name[CF_BUFSIZE];
    int count;

    cf_this[ob_temp0] = 0.0;
    cf_this[ob_temp1] = 0.0;
    cf_this[ob_temp2] = 0.0;
    cf_this[ob_temp3] = 0.0;

    if ((pp = cf_popen("/usr/bin/sensors", "r", true)) == NULL)
    {
        LMSENSORS = false;      /* Broken */
        return false;
    }

    {
        size_t vbuff_size = CF_BUFSIZE;
        char *vbuff = xmalloc(vbuff_size);

        ssize_t res = CfReadLine(&vbuff, &vbuff_size, pp);
        if (res <= 0)
        {
            /* FIXME: do we need to log anything here? */
            cf_pclose(pp);
            free(vbuff);
            return false;
        }

        for (;;)
        {
            ssize_t res = CfReadLine(&vbuff, &vbuff_size, pp);
            if (res == -1)
            {
                if (!feof(pp))
                {
                    /* FIXME: Do we need to log anything here? */
                    cf_pclose(pp);
                    free(vbuff);
                    return false;
                }
                else
                {
                    break;
                }
            }

            if (strstr(vbuff, "Temp") || strstr(vbuff, "temp"))
            {
                PrependItem(&list, vbuff, NULL);
            }
        }

        cf_pclose(pp);
        free(vbuff);
    }

    if (ListLen(list) > 0)
    {
        Log(LOG_LEVEL_DEBUG, "LM Sensors seemed to return ok data");
    }
    else
    {
        return false;
    }

/* lmsensor names are hopelessly inconsistent - so try a few things */

    for (ip = list; ip != NULL; ip = ip->next)
    {
        for (count = 0; count < 4; count++)
        {
            snprintf(name, 16, "CPU%d Temp:", count);

            if (strncmp(ip->name, name, strlen(name)) == 0)
            {
                sscanf(ip->name, "%*[^:]: %lf", &temp);

                switch (count)
                {
                case 0:
                    cf_this[ob_temp0] = temp;
                    break;
                case 1:
                    cf_this[ob_temp1] = temp;
                    break;
                case 2:
                    cf_this[ob_temp2] = temp;
                    break;
                case 3:
                    cf_this[ob_temp3] = temp;
                    break;
                }

                Log(LOG_LEVEL_DEBUG, "Set temp%d to %lf from what looks like cpu temperature", count, temp);
            }
        }
    }

    if (cf_this[ob_temp0] != 0)
    {
        /* We got something plausible */
        return true;
    }

/* Alternative name Core x: */

    for (ip = list; ip != NULL; ip = ip->next)
    {
        for (count = 0; count < 4; count++)
        {
            snprintf(name, 16, "Core %d:", count);

            if (strncmp(ip->name, name, strlen(name)) == 0)
            {
                sscanf(ip->name, "%*[^:]: %lf", &temp);

                switch (count)
                {
                case 0:
                    cf_this[ob_temp0] = temp;
                    break;
                case 1:
                    cf_this[ob_temp1] = temp;
                    break;
                case 2:
                    cf_this[ob_temp2] = temp;
                    break;
                case 3:
                    cf_this[ob_temp3] = temp;
                    break;
                }

                Log(LOG_LEVEL_DEBUG, "Set temp%d to %lf from what looks like core temperatures", count, temp);
            }
        }
    }

    if (cf_this[ob_temp0] != 0)
    {
        /* We got something plausible */
        return true;
    }

    for (ip = list; ip != NULL; ip = ip->next)
    {
        if (strncmp(ip->name, "CPU Temp:", strlen("CPU Temp:")) == 0)
        {
            sscanf(ip->name, "%*[^:]: %lf", &temp);
            Log(LOG_LEVEL_DEBUG, "Setting temp0 to CPU Temp");
            cf_this[ob_temp0] = temp;
        }

        if (strncmp(ip->name, "M/B Temp:", strlen("M/B Temp:")) == 0)
        {
            sscanf(ip->name, "%*[^:]: %lf", &temp);
            Log(LOG_LEVEL_DEBUG, "Setting temp0 to M/B Temp");
            cf_this[ob_temp1] = temp;
        }

        if (strncmp(ip->name, "Sys Temp:", strlen("Sys Temp:")) == 0)
        {
            sscanf(ip->name, "%*[^:]: %lf", &temp);
            Log(LOG_LEVEL_DEBUG, "Setting temp0 to Sys Temp");
            cf_this[ob_temp2] = temp;
        }

        if (strncmp(ip->name, "AUX Temp:", strlen("AUX Temp:")) == 0)
        {
            sscanf(ip->name, "%*[^:]: %lf", &temp);
            Log(LOG_LEVEL_DEBUG, "Setting temp0 to AUX Temp");
            cf_this[ob_temp3] = temp;
        }
    }

    if (cf_this[ob_temp0] != 0)
    {
        /* We got something plausible */
        return true;
    }

/* Alternative name Core x: */

    for (ip = list; ip != NULL; ip = ip->next)
    {
        for (count = 0; count < 4; count++)
        {
            snprintf(name, 16, "temp%d:", count);

            if (strncmp(ip->name, name, strlen(name)) == 0)
            {
                sscanf(ip->name, "%*[^:]: %lf", &temp);

                switch (count)
                {
                case 0:
                    cf_this[ob_temp0] = temp;
                    break;
                case 1:
                    cf_this[ob_temp1] = temp;
                    break;
                case 2:
                    cf_this[ob_temp2] = temp;
                    break;
                case 3:
                    cf_this[ob_temp3] = temp;
                    break;
                }

                Log(LOG_LEVEL_DEBUG, "Set temp%d to %lf", count, temp);
            }
        }
    }

/* Give up? */
    DeleteItemList(list);
    return true;
}
Exemplo n.º 25
0
 int Ardb::LLen(Context& ctx, RedisCommandFrame& cmd)
 {
     ListLen(ctx, cmd.GetArguments()[0]);
     return 0;
 }
Exemplo n.º 26
0
      else
        code[0]='P';
      if(at->cycle&(cH_Ring3|cH_Ring4|cH_Ring5|cH_Ring6|cH_Ring7))
        code[1]='C';
      else 
        code[1]='X';
      code[2]=0;
      ChampAtomToString(I,ai,atom);
      if(atom[0]>96)
        atom[0]-=32;
      strcat(code,atom);
      PyList_SetItem(l1,a,PyString_FromString(code));
      ai = at->link;
    }

    n_bond = ListLen(I->Bond,pat->bond);
    l2 = PyList_New(n_bond);
    bi = pat->bond;
    for(b=0;b<n_bond;b++) {
      bd = I->Bond + bi;
      if(bd->class&cH_Aliphatic)
        code[0]='A';
      else if(bd->class&cH_Aromatic)
        code[0]='R';
      else
        code[0]='P';
      if(bd->cycle&(cH_Ring3|cH_Ring4|cH_Ring5|cH_Ring6|cH_Ring7))
        code[1]='C';
      else 
        code[1]='X';
Exemplo n.º 27
0
static bool GetLMSensors(double *cf_this)
{
    FILE *pp;
    Item *ip, *list = NULL;
    double temp = 0;
    char name[CF_BUFSIZE];
    int count;
    char vbuff[CF_BUFSIZE];

    cf_this[ob_temp0] = 0.0;
    cf_this[ob_temp1] = 0.0;
    cf_this[ob_temp2] = 0.0;
    cf_this[ob_temp3] = 0.0;

    if ((pp = cf_popen("/usr/bin/sensors", "r")) == NULL)
    {
        LMSENSORS = false;      /* Broken */
        return false;
    }

    CfReadLine(vbuff, CF_BUFSIZE, pp);

    while (!feof(pp))
    {
        CfReadLine(vbuff, CF_BUFSIZE, pp);

        if (strstr(vbuff, "Temp") || strstr(vbuff, "temp"))
        {
            PrependItem(&list, vbuff, NULL);
        }
    }

    cf_pclose(pp);

    if (ListLen(list) > 0)
    {
        CfDebug("LM Sensors seemed to return ok data\n");
    }
    else
    {
        return false;
    }

    /* lmsensor names are hopelessly inconsistent - so try a few things */

    for (ip = list; ip != NULL; ip = ip->next)
    {
        for (count = 0; count < 4; count++)
        {
            snprintf(name, 16, "CPU%d Temp:", count);

            if (strncmp(ip->name, name, strlen(name)) == 0)
            {
                sscanf(ip->name, "%*[^:]: %lf", &temp);

                switch (count)
                {
                case 0:
                    cf_this[ob_temp0] = temp;
                    break;
                case 1:
                    cf_this[ob_temp1] = temp;
                    break;
                case 2:
                    cf_this[ob_temp2] = temp;
                    break;
                case 3:
                    cf_this[ob_temp3] = temp;
                    break;
                }

                CfDebug("Set temp%d to %lf from what looks like cpu temperature\n", count, temp);
            }
        }
    }

    if (cf_this[ob_temp0] != 0)
    {
        /* We got something plausible */
        return true;
    }

    /* Alternative name Core x: */

    for (ip = list; ip != NULL; ip = ip->next)
    {
        for (count = 0; count < 4; count++)
        {
            snprintf(name, 16, "Core %d:", count);

            if (strncmp(ip->name, name, strlen(name)) == 0)
            {
                sscanf(ip->name, "%*[^:]: %lf", &temp);

                switch (count)
                {
                case 0:
                    cf_this[ob_temp0] = temp;
                    break;
                case 1:
                    cf_this[ob_temp1] = temp;
                    break;
                case 2:
                    cf_this[ob_temp2] = temp;
                    break;
                case 3:
                    cf_this[ob_temp3] = temp;
                    break;
                }

                CfDebug("Set temp%d to %lf from what looks like core temperatures\n", count, temp);
            }
        }
    }

    if (cf_this[ob_temp0] != 0)
    {
        /* We got something plausible */
        return true;
    }

    for (ip = list; ip != NULL; ip = ip->next)
    {
        if (strncmp(ip->name, "CPU Temp:", strlen("CPU Temp:")) == 0)
        {
            sscanf(ip->name, "%*[^:]: %lf", &temp);
            CfDebug("Setting temp0 to CPU Temp\n");
            cf_this[ob_temp0] = temp;
        }

        if (strncmp(ip->name, "M/B Temp:", strlen("M/B Temp:")) == 0)
        {
            sscanf(ip->name, "%*[^:]: %lf", &temp);
            CfDebug("Setting temp0 to M/B Temp\n");
            cf_this[ob_temp1] = temp;
        }

        if (strncmp(ip->name, "Sys Temp:", strlen("Sys Temp:")) == 0)
        {
            sscanf(ip->name, "%*[^:]: %lf", &temp);
            CfDebug("Setting temp0 to Sys Temp\n");
            cf_this[ob_temp2] = temp;
        }

        if (strncmp(ip->name, "AUX Temp:", strlen("AUX Temp:")) == 0)
        {
            sscanf(ip->name, "%*[^:]: %lf", &temp);
            CfDebug("Setting temp0 to AUX Temp\n");
            cf_this[ob_temp3] = temp;
        }
    }

    if (cf_this[ob_temp0] != 0)
    {
        /* We got something plausible */
        return true;
    }

    /* Alternative name Core x: */

    for (ip = list; ip != NULL; ip = ip->next)
    {
        for (count = 0; count < 4; count++)
        {
            snprintf(name, 16, "temp%d:", count);

            if (strncmp(ip->name, name, strlen(name)) == 0)
            {
                sscanf(ip->name, "%*[^:]: %lf", &temp);

                switch (count)
                {
                case 0:
                    cf_this[ob_temp0] = temp;
                    break;
                case 1:
                    cf_this[ob_temp1] = temp;
                    break;
                case 2:
                    cf_this[ob_temp2] = temp;
                    break;
                case 3:
                    cf_this[ob_temp3] = temp;
                    break;
                }

                CfDebug("Set temp%d to %lf\n", count, temp);
            }
        }
    }

    /* Give up? */
    DeleteItemList(list);
    return true;
}
Exemplo n.º 28
0
/* This function copies the structural information of sim to exp. It does not
   copy chemical shifts etc. */
int BU_CopyStructure(struct BU_Struct *exp, struct BU_Struct *sim)
{
  int i, pos, identical=1;
  struct BU_Unit *unit, *eunit;
  /* check that original does exist */
  if (sim->Units.Head.Succ==&sim->Units.Tail)
    Error(PA_ERR_FAIL, "'Simulated' spectrum has no structure");

  if(ListLen(&sim->Units)==ListLen(&exp->Units))
    {
      for(unit=(struct BU_Unit *)sim->Units.Head.Succ,
	    eunit=(struct BU_Unit *)exp->Units.Head.Succ;
	  unit->Node.Succ!=NULL && eunit->Node.Succ!=NULL;
	  unit=(struct BU_Unit *)unit->Node.Succ,
	    eunit=(struct BU_Unit *)eunit->Node.Succ)
	{
	  /* Check that the residues are the same and that they bind to the same
	     position in the next residue. */
	  if(unit->Residue!=eunit->Residue ||
	     unit->Position!=eunit->Position)
	    {
	      identical=0;
	      break;
	    }
	  /* Check the bonds */
	  for(i=0;i<TY_MAX_BONDS;i++)
	    {
	      if(unit->Subst[i]!=0 && eunit->Subst[i]!=0)
		{
		  /* Just compare the names of the substituents since they are just
		     copies (if they are the same) - they are not identical */
		  if(strcmp(unit->Subst[i]->Node.Name,eunit->Subst[i]->Node.Name)!=0)
		    {
		      identical=0;
		      break;
		    }
		}
	      else if((unit->Subst[i]==0 && eunit->Subst[i]!=0) ||
		      (unit->Subst[i]!=0 && eunit->Subst[i]==0))
		{
		  identical=0;
		  break;
		}
	    }
	}
    }
  else
    {
      identical=0;
    }
  if(identical==1)
    {
      return(PA_ERR_OK);
    }

  /* clear experimental structure */
  FreeList(&exp->Units);

  for(i=0;i<3;i++)
    {
      exp->JHH[i]=sim->JHH[i];
      exp->JCH[i]=sim->JCH[i];
    }

  for (unit=(struct BU_Unit *)sim->Units.Head.Succ; unit->Node.Succ!=NULL;
       unit=(struct BU_Unit *)unit->Node.Succ)
    {
      eunit=ME_CreateNode(&UnitMethod, &(exp->Units), unit->Node.Name);
      if (eunit==NULL) Error(PA_ERR_FATAL, "Out of memory");
      eunit->Residue = unit->Residue;
      eunit->Shifts.Type = unit->Shifts.Type;
      for(i=0;i<TY_MAX_CARBON;i++)
	{
	  eunit->Shifts.C[i]=BU_VOID_SHIFT;
	  eunit->Shifts.H[i][0]=BU_VOID_SHIFT;
	  eunit->Shifts.H[i][1]=BU_VOID_SHIFT;
	}
      eunit->CcpnUnitNr = unit->CcpnUnitNr;
    }  

  /* copy linking info */
  for (unit=(struct BU_Unit*)sim->Units.Head.Succ; unit->Node.Succ!=NULL;
       unit=(struct BU_Unit *)unit->Node.Succ)
    {
      eunit=(struct BU_Unit *)FindNode(&(exp->Units.Head), unit->Node.Name);
      eunit->Position=unit->Position;	/* copy position info */
      for (pos=0; pos<TY_MAX_HEAVY; pos++)	/* copy every 'substituent' */
	{
	  if (unit->Subst[pos]==NULL) continue;
	  eunit->Subst[pos]=(struct BU_Unit*)
	    FindNode(&(exp->Units.Head),unit->Subst[pos]->Node.Name);
	}
    }
  return(PA_ERR_OK);
}
Exemplo n.º 29
0
void PromiseMethod(struct Method *ptr)

{ struct Item *ip;
 int i,amserver;

amserver = (IsItemIn(ptr->servers,IPString2Hostname(VFQNAME)) ||
            IsItemIn(ptr->servers,IPString2UQHostname(VUQNAME)) ||
            IsItemIn(ptr->servers,VIPADDRESS));

if (amserver)
   {
   printf("Promises to provide and execute method %s if context [%s]\n",ptr->name,ptr->classes);
   }
else
   {
   printf("Promise to use voluntary service %s provided by server list if context [%s]\n",ptr->name,ptr->classes);

   i = 1;
   
   for (ip = ptr->send_args; ip != NULL; ip=ip->next)
      {
      printf("   Provide argument %d: %s\n",i++,ip->name);
      }
   
   printf("   %s\n",ChecksumPrint('m',ptr->digest));
   
   i = 1;
   
   for (ip = ptr->send_classes; ip != NULL; ip=ip->next)
      {
      printf("   Provide class %d: %s\n",i++,ip->name);
      }
   
   i = 1;
   
   for (ip = ptr->servers; ip != NULL; ip=ip->next)
      {
      printf("   Encrypt for service provider %d: %s\n",i++,ip->name);
      }

   
   i = 1;
   
   if (ListLen(ptr->servers) > 1)
      {
      for (ip = ptr->return_vars; ip != NULL; ip=ip->next)
         {
         printf("   Return value %d: $(%s_X.%s) - X = 1,2,..\n",i++,ptr->name,ip->name);
         }
      
      i = 1;
      
      for (ip = ptr->return_classes; ip != NULL; ip=ip->next)
         {
         printf("   Will accept return class %d: %s_X_%s\n",i++,ptr->name,ip->name);
         }      
      }
   else
      {      
      for (ip = ptr->return_vars; ip != NULL; ip=ip->next)
         {
         printf("   Will accept return value %d: $(%s.%s)\n",i++,ptr->name,ip->name);
         }
      
      i = 1;
      
      for (ip = ptr->return_classes; ip != NULL; ip=ip->next)
         {
         printf("   Will accept return class %d: %s_%s\n",i++,ptr->name,ip->name);
         }
      }
   
   }

printf("   IfElapsed=%d, ExpireAfter=%d\n",ptr->ifelapsed,ptr->expireafter);
printf("   Using executable file: %s\n",ptr->file);
printf("   Running with Uid=%d,Gid=%d\n",ptr->uid,ptr->gid);
printf("   Running in chdir=%s, chroot=%s\n",ptr->chdir,ptr->chroot);
printf("   Rule from %s at/before line %d\n",ptr->audit->filename,ptr->lineno);
}
Exemplo n.º 30
0
Arquivo: syntax.c Projeto: dnaeon/core
static void CheckParseInt(char *lval, char *s, const char *range)
{
    Item *split;
    int n;
    long max = CF_LOWINIT, min = CF_HIGHINIT, val;
    char output[CF_BUFSIZE];

/* Numeric types are registered by range separated by comma str "min,max" */
    CfDebug("\nCheckParseInt(%s => %s/%s)\n", lval, s, range);

    if (s == NULL)
    {
        return;
    }

    split = SplitString(range, ',');

    if ((n = ListLen(split)) != 2)
    {
        FatalError("INTERN: format specifier for int rvalues is not ok for lval %s - got %d items", lval, n);
    }

    sscanf(split->name, "%ld", &min);

    if (strcmp(split->next->name, "inf") == 0)
    {
        max = CF_INFINITY;
    }
    else
    {
        sscanf(split->next->name, "%ld", &max);
    }

    DeleteItemList(split);

    if (min == CF_HIGHINIT || max == CF_LOWINIT)
    {
        FatalError("INTERN: could not parse format specifier for int rvalues for lval %s", lval);
    }

    if (IsCf3VarString(s))
    {
        CfDebug("Validation: Unable to verify syntax of int \'%s\' due to variable expansion at this stage\n", s);
        return;
    }

    val = Str2Int(s);

    if (val == CF_NOINT)
    {
        snprintf(output, CF_BUFSIZE, "Int item on rhs of lval \'%s\' given as \'%s\' could not be parsed", lval, s);
        ReportError(output);
        return;
    }

    if (val > max || val < min)
    {
        snprintf(output, CF_BUFSIZE,
                 "Int item on rhs of lval \'%s\' given as {%s => %ld} is out of bounds (should be in [%s])", lval, s,
                 val, range);
        ReportError(output);
        return;
    }

    CfDebug("CheckParseInt - syntax verified\n\n");
}