Beispiel #1
0
void TestVariableScan()
{
    int i;
    char *list_text1 = "$(administrator),a,b,c,d,e,f";
    char *list_text2 = "1,2,3,4,@(one)";
    Rlist *varlist1, *varlist2, *listoflists = NULL, *scalars = NULL;

    static char *varstrings[] =
    {
        "alpha $(one) beta $(two) gamma",
        "alpha $(five) beta $(none) gamma $(array[$(four)])",
        "alpha $(none) beta $(two) gamma",
        "alpha $(four) beta $(two) gamma $(array[$(diagnostic.three)])",
        NULL
    };

    printf("%d. Test variable scanning\n", ++NR);
    SetNewScope("diagnostic");

    varlist1 = SplitStringAsRList(list_text1, ',');
    varlist2 = SplitStringAsRList(list_text2, ',');

    NewList("diagnostic", "one", varlist1, cf_slist);
    NewScalar("diagnostic", "two", "secondary skills", cf_str);
    NewScalar("diagnostic", "administrator", "root", cf_str);
    NewList("diagnostic", "three", varlist2, cf_slist);
    NewList("diagnostic", "four", varlist2, cf_slist);
    NewList("diagnostic", "five", varlist2, cf_slist);

    for (i = 0; varstrings[i] != NULL; i++)
    {
        if (VERBOSE || DEBUG)
        {
            printf("-----------------------------------------------------------\n");
            printf("Scanning: [%s]\n", varstrings[i]);
            MapIteratorsFromRval("diagnostic", &scalars, &listoflists, (Rval) {
                varstrings[i], CF_SCALAR
            }, NULL);
            printf("Cumulative scan produced:\n");
            printf("   Scalar variables: ");
            ShowRlist(stdout, scalars);
            printf("\n");
            printf("   Lists variables: ");
            ShowRlist(stdout, listoflists);
            printf("\n");
        }
    }
}
void BannerSubBundle(struct Bundle *bp,struct Rlist *params)

{
CfOut(cf_verbose,"","\n");
CfOut(cf_verbose,"","      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");

if (VERBOSE || DEBUG)
   {
   printf("%s>       BUNDLE %s",VPREFIX,bp->name);
   }

if (params && (VERBOSE||DEBUG))
   {
   printf("(");
   ShowRlist(stdout,params);
   printf(" )\n");
   }
else
   {
   if (VERBOSE||DEBUG) printf("\n");
   }
CfOut(cf_verbose,"","      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\n");
CfOut(cf_verbose,"","\n");
LastSawBundle(bp->name);
}
Beispiel #3
0
Bundle *AppendBundle(Bundle **start, char *name, char *type, Rlist *args)
{
    Bundle *bp, *lp;

    CfDebug("Appending new bundle %s %s (", type, name);

    if (DEBUG)
    {
        ShowRlist(stdout, args);
    }
    CfDebug(")\n");

    CheckBundle(name, type);

    bp = xcalloc(1, sizeof(Bundle));

    if (*start == NULL)
    {
        *start = bp;
    }
    else
    {
        for (lp = *start; lp->next != NULL; lp = lp->next)
        {
        }

        lp->next = bp;
    }

    bp->name = xstrdup(name);
    bp->type = xstrdup(type);
    bp->args = args;

    return bp;
}
Beispiel #4
0
void ArgTemplate(FnCall *fp, const FnCallArg *argtemplate, Rlist *realargs)
{
    int argnum, i;
    Rlist *rp = fp->args;
    char id[CF_BUFSIZE], output[CF_BUFSIZE];
    const FnCallType *fn = FindFunction(fp->name);

    snprintf(id, CF_MAXVARSIZE, "built-in FnCall %s-arg", fp->name);

    for (argnum = 0; rp != NULL && argtemplate[argnum].pattern != NULL; argnum++)
    {
        if (rp->type != CF_FNCALL)
        {
            /* Nested functions will not match to lval so don't bother checking */
            CheckConstraintTypeMatch(id, (Rval) {rp->item, rp->type}, argtemplate[argnum].dtype, argtemplate[argnum].pattern, 1);
        }

        rp = rp->next;
    }

    if (argnum != RlistLen(realargs) && !fn->varargs)
    {
        snprintf(output, CF_BUFSIZE, "Argument template mismatch handling function %s(", fp->name);
        ReportError(output);
        ShowRlist(stderr, realargs);
        fprintf(stderr, ")\n");

        for (i = 0, rp = realargs; i < argnum; i++)
        {
            printf("  arg[%d] range %s\t", i, argtemplate[i].pattern);
            if (rp != NULL)
            {
                ShowRval(stdout, (Rval) {rp->item, rp->type});
                rp = rp->next;
            }
            else
            {
                printf(" ? ");
            }
            printf("\n");
        }

        FatalError("Bad arguments");
    }

    for (rp = realargs; rp != NULL; rp = rp->next)
    {
        CfDebug("finalarg: %s\n", (char *) rp->item);
    }

    CfDebug("End ArgTemplate\n");
}
Beispiel #5
0
struct Bundle *AppendBundle(struct Bundle **start,char *name, char *type, struct Rlist *args)

{   struct Bundle *bp,*lp;

    if (INSTALL_SKIP)
    {
        return NULL;
    }

    Debug("Appending new bundle %s %s (",type,name);

    if (DEBUG)
    {
        ShowRlist(stdout,args);
    }
    Debug(")\n");

    CheckBundle(name,type);

    if ((bp = (struct Bundle *)malloc(sizeof(struct Bundle))) == NULL)
    {
        CfOut(cf_error,"malloc","Unable to alloc Bundle");
        FatalError("");
    }

    if (*start == NULL)
    {
        *start = bp;
    }
    else
    {
        for (lp = *start; lp->next != NULL; lp=lp->next)
        {
        }

        lp->next = bp;
    }

    bp->name = strdup(name);
    bp->next = NULL;
    bp->type = strdup(type);
    bp->args = args;
    bp->subtypes = NULL;
    return bp;
}
Beispiel #6
0
void ShowPromiseInReport(const char *version, Promise *pp, int indent)
{
    Constraint *cp;
    Body *bp;
    Rlist *rp;
    FnCall *fp;

    fprintf(FREPORT_HTML, "%s\n", CFH[cfx_line][cfb]);
    fprintf(FREPORT_HTML, "%s\n", CFH[cfx_promise][cfb]);
    fprintf(FREPORT_HTML, "Promise type is %s%s%s, ", CFH[cfx_subtype][cfb], pp->agentsubtype, CFH[cfx_subtype][cfe]);
    fprintf(FREPORT_HTML, "<a href=\"#class_context\">context</a> is %s%s%s <br><hr>\n\n", CFH[cfx_class][cfb],
            pp->classes, CFH[cfx_class][cfe]);

    if (pp->promisee.item)
    {
        fprintf(FREPORT_HTML, "Resource object %s\'%s\'%s promises %s (about %s) to", CFH[cfx_object][cfb],
                pp->promiser, CFH[cfx_object][cfe], CFH[cfx_object][cfb], pp->agentsubtype);
        ShowRval(FREPORT_HTML, pp->promisee);
        fprintf(FREPORT_HTML, "%s\n\n", CFH[cfx_object][cfe]);
    }
    else
    {
        fprintf(FREPORT_HTML,
                "Resource object %s\'%s\'%s make the promise to default promisee 'cf-%s' (about %s)...\n\n",
                CFH[cfx_object][cfb], pp->promiser, CFH[cfx_object][cfe], pp->bundletype, pp->agentsubtype);
    }

    Indent(indent);
    if (pp->promisee.item != NULL)
    {
        fprintf(FREPORT_TXT, "%s promise by \'%s\' -> ", pp->agentsubtype, pp->promiser);
        ShowRval(FREPORT_TXT, pp->promisee);
        fprintf(FREPORT_TXT, " if context is %s\n\n", pp->classes);
    }
    else
    {
        fprintf(FREPORT_TXT, "%s promise by \'%s\' (implicit) if context is %s\n\n", pp->agentsubtype, pp->promiser,
                pp->classes);
    }

    for (cp = pp->conlist; cp != NULL; cp = cp->next)
    {
        fprintf(FREPORT_HTML, "%s%s%s => ", CFH[cfx_lval][cfb], cp->lval, CFH[cfx_lval][cfe]);
        Indent(indent + 3);
        fprintf(FREPORT_TXT, "%10s => ", cp->lval);

        switch (cp->rval.rtype)
        {
        case CF_SCALAR:
            if ((bp = IsBody(BODIES, (char *) cp->rval.item)))
            {
                ShowBody(bp, 15);
            }
            else
            {
                fprintf(FREPORT_HTML, "%s", CFH[cfx_rval][cfb]);
                ShowRval(FREPORT_HTML, cp->rval);       /* literal */
                fprintf(FREPORT_HTML, "%s", CFH[cfx_rval][cfe]);

                ShowRval(FREPORT_TXT, cp->rval);        /* literal */
            }
            break;

        case CF_LIST:

            rp = (Rlist *) cp->rval.item;
            fprintf(FREPORT_HTML, "%s", CFH[cfx_rval][cfb]);
            ShowRlist(FREPORT_HTML, rp);
            fprintf(FREPORT_HTML, "%s", CFH[cfx_rval][cfe]);
            ShowRlist(FREPORT_TXT, rp);
            break;

        case CF_FNCALL:
            fp = (FnCall *) cp->rval.item;

            if ((bp = IsBody(BODIES, fp->name)))
            {
                ShowBody(bp, 15);
            }
            else
            {
                ShowRval(FREPORT_HTML, cp->rval);       /* literal */
                ShowRval(FREPORT_TXT, cp->rval);        /* literal */
            }
            break;
        }

        if (cp->rval.rtype != CF_FNCALL)
        {
            Indent(indent);
            fprintf(FREPORT_HTML,
                    " , if body <a href=\"#class_context\">context</a> <span class=\"context\">%s</span>\n",
                    cp->classes);
            fprintf(FREPORT_TXT, " if body context %s\n", cp->classes);
        }
    }

    if (pp->audit)
    {
        Indent(indent);
        fprintf(FREPORT_HTML,
                "<p><small>Promise (version %s) belongs to bundle <b>%s</b> (type %s) in \'<i>%s</i>\' near line %zu</small></p>\n",
                version, pp->bundle, pp->bundletype, pp->audit->filename, pp->offset.line);
    }

    fprintf(FREPORT_HTML, "%s\n", CFH[cfx_promise][cfe]);
    fprintf(FREPORT_HTML, "%s\n", CFH[cfx_line][cfe]);

    if (pp->audit)
    {
        Indent(indent);
        fprintf(FREPORT_TXT, "Promise (version %s) belongs to bundle \'%s\' (type %s) in file \'%s\' near line %zu\n",
                version, pp->bundle, pp->bundletype, pp->audit->filename, pp->offset.line);
        fprintf(FREPORT_TXT, "\n\n");
    }
    else
    {
        Indent(indent);
        fprintf(FREPORT_TXT, "Promise (version %s) belongs to bundle \'%s\' (type %s) near line %zu\n\n", version,
                pp->bundle, pp->bundletype, pp->offset.line);
    }
}