Exemple #1
0
static int GenerateAvahiConfig(const char *path)
{
    FILE *fout;
    Writer *writer = NULL;
    fout = fopen(path, "w+");
    if (fout == NULL)
    {
        CfOut(cf_error, "", "Unable to open %s", path);
        return -1;
    }
    writer = FileWriter(fout);
    fprintf(fout, "<?xml version=\"1.0\" standalone='no'?>\n");
    fprintf(fout, "<!DOCTYPE service-group SYSTEM \"avahi-service.dtd\">\n");
    XmlComment(writer, "This file has been automatically generated by cf-serverd.");
    XmlStartTag(writer, "service-group", 0);
#ifdef HAVE_NOVA
    fprintf(fout,"<name replace-wildcards=\"yes\" >CFEngine Enterprise %s Policy Hub on %s </name>\n", Version(), "%h");
#else
    fprintf(fout,"<name replace-wildcards=\"yes\" >CFEngine Community %s Policy Server on %s </name>\n", Version(), "%h");
#endif
    XmlStartTag(writer, "service", 0);
    XmlTag(writer, "type", "_cfenginehub._tcp",0);
    DetermineCfenginePort();
    XmlTag(writer, "port", STR_CFENGINEPORT, 0);
    XmlEndTag(writer, "service");
    XmlEndTag(writer, "service-group");
    fclose(fout);

    return 0;
}
static int GenerateAvahiConfig(const char *path)
{
    FILE *fout;
    Writer *writer = NULL;
    fout = safe_fopen(path, "w+");
    if (fout == NULL)
    {
        Log(LOG_LEVEL_ERR, "Unable to open '%s'", path);
        return -1;
    }
    writer = FileWriter(fout);
    fprintf(fout, "<?xml version=\"1.0\" standalone='no'?>\n");
    fprintf(fout, "<!DOCTYPE service-group SYSTEM \"avahi-service.dtd\">\n");
    XmlComment(writer, "This file has been automatically generated by cf-serverd.");
    XmlStartTag(writer, "service-group", 0);
    FprintAvahiCfengineTag(fout);
    XmlStartTag(writer, "service", 0);
    XmlTag(writer, "type", "_cfenginehub._tcp",0);
    DetermineCfenginePort();
    XmlStartTag(writer, "port", 0);
    WriterWriteF(writer, "%d", CFENGINE_PORT);
    XmlEndTag(writer, "port");
    XmlEndTag(writer, "service");
    XmlEndTag(writer, "service-group");
    fclose(fout);

    return 0;
}
Exemple #3
0
void XmlManual(const char *mandir, FILE *fout)
{
    Writer *writer = NULL;
    int i;
    SubTypeSyntax *st = NULL;

    MANUAL_DIRECTORY = (char *) mandir;
    AddSlash(MANUAL_DIRECTORY);

    writer = FileWriter(fout);

/* XML HEADER */
    XmlComment(writer, "AUTOGENERATED SYNTAX DOCUMENTATION BY CF-KNOW");
    WriterWrite(writer, "\n");

/* START XML ELEMENT -- SYNTAX-DOCUMENTATION */
    XmlStartTag(writer, XMLTAG_DOC_ROOT, 0);

/* SPECIAL VARIABLES */
    XmlStartTag(writer, XMLTAG_VARSCOPES_ROOT, 0);
    XmlExportVariables(writer, "const");
    XmlExportVariables(writer, "edit");
    XmlExportVariables(writer, "match");
    XmlExportVariables(writer, "mon");
    XmlExportVariables(writer, "sys");
    XmlExportVariables(writer, "this");
    XmlEndTag(writer, XMLTAG_VARSCOPES_ROOT);

/* SPECIAL FUNCTIONS */
    XmlStartTag(writer, XMLTAG_FUNCTIONS_ROOT, 0);
    for (i = 0; CF_FNCALL_TYPES[i].name != NULL; i++)
    {
        XmlExportFunction(writer, CF_FNCALL_TYPES[i]);
    }
    XmlEndTag(writer, XMLTAG_FUNCTIONS_ROOT);

/* CONTROL */
    XmlStartTag(writer, XMLTAG_CONTROLS_ROOT, 0);
    for (i = 0; CF_ALL_BODIES[i].btype != NULL; i++)
    {
        XmlExportControl(writer, CF_ALL_BODIES[i]);
    }
    XmlEndTag(writer, XMLTAG_CONTROLS_ROOT);

/* PROMISE TYPES */
    XmlStartTag(writer, XMLTAG_PROMISETYPES_ROOT, 0);
    for (i = 0; i < CF3_MODULES; i++)
    {
        st = CF_ALL_SUBTYPES[i];
        XmlExportPromiseType(writer, st);
    }
    XmlEndTag(writer, XMLTAG_PROMISETYPES_ROOT);

/* END XML ELEMENT -- SYNTAX-DOCUMENTATION */
    XmlEndTag(writer, XMLTAG_DOC_ROOT);

    WriterClose(writer);
}
Exemple #4
0
static void XmlExportFunction(Writer *writer, FnCallType fn)
{
    int i;
    char *filebuffer = NULL;

/* START XML ELEMENT -- FUNCTION */
    XmlAttribute fun_name_attr = { "name", fn.name };
    XmlAttribute fun_returntype_attr = { "return-type", CF_DATATYPES[fn.dtype] };
    XmlAttribute fun_varargs_attr = { "varargs", NULL };

    if (fn.varargs)
    {
        fun_varargs_attr.value = "true";
    }
    else
    {
        fun_varargs_attr.value = "false";
    }

    XmlStartTag(writer, XMLTAG_FUNCTION, 3, fun_name_attr, fun_returntype_attr, fun_varargs_attr);

/* XML ELEMENT -- DESCRIPTION */
    XmlTag(writer, XMLTAG_DESCRIPTION, fn.description, 0);

    for (i = 0; fn.args[i].pattern != NULL; i++)
    {
        /* START XML ELEMENT -- ARGUMENT */
        XmlAttribute argument_type_attr = { "type", CF_DATATYPES[fn.args[i].dtype] };
        XmlStartTag(writer, XMLTAG_ARGUMENT, 1, argument_type_attr);

        /* XML ELEMENT -- DESCRIPTION */
        XmlTag(writer, XMLTAG_DESCRIPTION, fn.args[i].description, 0);

        /* END XML ELEMENT -- ARGUMENT */
        XmlEndTag(writer, XMLTAG_ARGUMENT);
    }

/* XML ELEMENT -- LONG-DESCRIPTION */
    filebuffer = ReadTexinfoFileF("functions/%s_notes.texinfo", fn.name);
    XmlTag(writer, XMLTAG_LONGDESCRIPTION, filebuffer, 0);
    free(filebuffer);

/* XML ELEMENT -- EXAMPLE */
    filebuffer = ReadTexinfoFileF("functions/%s_example.texinfo", fn.name);
    XmlTag(writer, XMLTAG_EXAMPLE, filebuffer, 0);
    free(filebuffer);

/* END XML ELEMENT -- FUNCTION */
    XmlEndTag(writer, XMLTAG_FUNCTION);
}
Exemple #5
0
void XmlExportConstraint(Writer *writer, const BodySyntax *bs)
{
    char *filebuffer = NULL;

    if (bs == NULL)
    {
        return;
    }

/* START XML ELEMENT -- CONSTRAINT */
    XmlAttribute constraint_name_attr = { "name", bs->lval };
    XmlStartTag(writer, XMLTAG_CONSTRAINT, 1, constraint_name_attr);

/* EXPORT TYPE */
    XmlExportType(writer, bs->dtype, bs->range);

/* XML ELEMENT -- DEFAULT-VALUE */
    if (bs->default_value != NULL)
    {
        XmlTag(writer, XMLTAG_DEFAULTVAL, bs->default_value, 0);
    }

    switch (bs->dtype)
    {
    case cf_body:
    case cf_bundle:
    case cf_notype:
    case cf_counter:
        /* NO ADDITIONAL INFO */
        break;

    default:
        /* XML ELEMENT -- DESCRIPTION */
        XmlTag(writer, XMLTAG_DESCRIPTION, bs->description, 0);

        /* XML ELEMENT -- LONG-DESCRIPTION */
        filebuffer = ReadTexinfoFileF("bodyparts/%s_notes.texinfo", bs->lval);
        XmlTag(writer, XMLTAG_LONGDESCRIPTION, filebuffer, 0);
        free(filebuffer);

        /* XML ELEMENT -- EXAMPLE */
        filebuffer = ReadTexinfoFileF("bodyparts/%s_example.texinfo", bs->lval);
        XmlTag(writer, XMLTAG_EXAMPLE, filebuffer, 0);
        free(filebuffer);
    }

/* END XML ELEMENT -- CONSTRAINT */
    XmlEndTag(writer, XMLTAG_CONSTRAINT);
}
Exemple #6
0
void test_complex_tag(void **state)
{
    Writer *w = StringWriter();

    XmlStartTag(w, "complex-tag", 2, (XmlAttribute)
                {
                "attr1", "value1"}, (XmlAttribute)
                {
                "attr2", "value2"});
    XmlContent(w, "Some content");
    XmlEndTag(w, "complex-tag");

    assert_string_equal(StringWriterClose(w),
                        "<complex-tag attr1=\"value1\" attr2=\"value2\" >\nSome content</complex-tag>\n");
}
Exemple #7
0
static void XmlExportVariables(Writer *writer, const char *scope)
{
    char *filebuffer = NULL;
    Rlist *rp = NULL;
    Rlist *list = NULL;

/* START XML ELEMENT -- VARIABLE*-SCOPE */
    XmlAttribute scope_name_attr = { "name", scope };
    XmlStartTag(writer, XMLTAG_VARSCOPE, 1, scope_name_attr);

/* XML ELEMENT -- INTRO */
    filebuffer = ReadTexinfoFileF("varcontexts/%s_intro.texinfo", scope);
    XmlTag(writer, XMLTAG_INTRO, filebuffer, 0);
    free(filebuffer);

    HashToList(GetScope(scope), &list);
    list = AlphaSortRListNames(list);
    for (rp = list; rp != NULL; rp = rp->next)
    {
        /* START XML ELEMENT -- VARIABLE */
        XmlAttribute var_name_attr = { "name", ScalarValue(rp) };
        XmlStartTag(writer, XMLTAG_VARIABLE, 1, var_name_attr);

        /* XML ELEMENT -- LONG-DESCRIPTION */
        filebuffer = ReadTexinfoFileF("vars/%s_%s.texinfo", scope, ScalarValue(rp));
        XmlTag(writer, XMLTAG_LONGDESCRIPTION, filebuffer, 0);
        free(filebuffer);

        /* END XML ELEMENT -- VARIABLE */
        XmlEndTag(writer, XMLTAG_VARIABLE);
    }
    DeleteRlist(list);

/* END XML ELEMENT -- VARIABLE-SCOPE */
    XmlEndTag(writer, XMLTAG_VARSCOPE);
}
Exemple #8
0
void XmlExportConstraints(Writer *writer, const BodySyntax *bs)
{
    int i;

    if (bs == NULL)
    {
        return;
    }

/* START XML ELEMENT -- CONSTRAINTS */
    XmlStartTag(writer, XMLTAG_CONSTRAINTS_ROOT, 0);
    for (i = 0; bs[i].lval != NULL; i++)
    {
        XmlExportConstraint(writer, (const BodySyntax *) &bs[i]);
    }
/* END XML ELEMENT -- CONSTRAINTS */
    XmlEndTag(writer, XMLTAG_CONSTRAINTS_ROOT);
}
Exemple #9
0
static void XmlExportControl(Writer *writer, SubTypeSyntax type)
{
    char *filebuffer = NULL;

/* START XML ELEMENT -- CONTROL */
    XmlAttribute control_name_attr = { "name", type.btype };
    XmlStartTag(writer, XMLTAG_CONTROL, 1, control_name_attr);

/* XML ELEMENT -- LONG-DESCRIPTION */
    filebuffer = ReadTexinfoFileF("control/%s_notes.texinfo", type.btype);
    XmlTag(writer, XMLTAG_LONGDESCRIPTION, filebuffer, 0);
    free(filebuffer);

/* XML ELEMENT -- EXAMPLE */
    filebuffer = ReadTexinfoFileF("control/%s_example.texinfo", type.btype);
    XmlTag(writer, XMLTAG_EXAMPLE, filebuffer, 0);
    free(filebuffer);

/* XML ELEMENT -- CONSTRAINTS */
    XmlExportConstraints(writer, type.bs);

/* END XML ELEMENT -- CONTROL */
    XmlEndTag(writer, XMLTAG_CONTROL);
}
Exemple #10
0
void XmlExportType(Writer *writer, enum cfdatatype dtype, const void *range)
{
    Rlist *list = NULL;
    Rlist *rp = NULL;

/* START XML ELEMENT -- TYPE */
    XmlAttribute type_name_attr = { "name", CF_DATATYPES[dtype] };
    XmlStartTag(writer, XMLTAG_TYPE, 1, type_name_attr);

    switch (dtype)
    {
    case cf_body:
        /* EXPORT CONSTRAINTS */
        XmlExportConstraints(writer, (BodySyntax *) range);
        break;

    case cf_int:
    case cf_real:
    case cf_ilist:
    case cf_rlist:
    case cf_irange:
    case cf_rrange:
        if (range != NULL)
        {
            /* START XML ELEMENT -- RANGE */
            XmlStartTag(writer, XMLTAG_RANGE, 0);

            /* XML ELEMENT -- MIN/MAX */
            int i = 0;

            list = SplitStringAsRList((char *) range, ',');
            for (rp = list; rp != NULL; rp = rp->next, i++)
            {
                if (i == 0)
                {
                    XmlTag(writer, XMLTAG_MIN, ScalarValue(rp), 0);
                }
                else
                {
                    XmlTag(writer, XMLTAG_MAX, ScalarValue(rp), 0);
                }
            }
            DeleteRlist(list);

            /* END XML ELEMENT -- RANGE */
            XmlEndTag(writer, XMLTAG_RANGE);

            break;
        }

    case cf_opts:
    case cf_olist:
        if (range != NULL)
        {
            /* START XML ELEMENT -- OPTIONS */
            XmlStartTag(writer, XMLTAG_OPTIONS, 0);

            /* XML ELEMENT -- VALUE */
            list = SplitStringAsRList((char *) range, ',');
            for (rp = list; rp != NULL; rp = rp->next)
            {
                XmlTag(writer, XMLTAG_VALUE, ScalarValue(rp), 0);
            }
            DeleteRlist(list);

            /* END XML ELEMENT -- OPTIONS */
            XmlEndTag(writer, XMLTAG_OPTIONS);

            break;
        }

    case cf_str:
    case cf_slist:
    case cf_class:
    case cf_clist:
        /* XML ELEMENT -- ACCEPTED-VALUES */
        if (strlen((char *) range) == 0)
        {
            XmlTag(writer, XMLTAG_ACCEPTEDVALS, "arbitrary string", 0);
        }
        else
        {
            XmlTag(writer, XMLTAG_ACCEPTEDVALS, (char *) range, 0);
        }

        break;

    case cf_bundle:
    case cf_notype:
    case cf_counter:
        /* NONE */
        break;
    }

/* END XML ELEMENT -- TYPE */
    XmlEndTag(writer, XMLTAG_TYPE);
}
Exemple #11
0
void XmlExportPromiseType(Writer *writer, SubTypeSyntax *st)
{
    int i;
    char *filebuffer = NULL;

    if (st == NULL)
    {
        return;
    }

    for (i = 0; st[i].btype != NULL; i++)
    {
        /* START XML ELEMENT -- PROMISE TYPE */
        XmlAttribute promise_name_attr = { "name", st[i].subtype };
        if (strcmp(st[i].subtype, "*") != 0)
        {
            XmlAttribute promise_agenttype_attr = { "agent-type", NULL };
            if (strcmp(st[i].btype, "*") == 0)
            {
                promise_agenttype_attr.value = "common";
            }
            else
            {
                promise_agenttype_attr.value = st[i].btype;
            }
            XmlStartTag(writer, XMLTAG_PROMISETYPE, 2, promise_name_attr, promise_agenttype_attr);
        }
        else
        {
            XmlStartTag(writer, XMLTAG_PROMISETYPE, 1, promise_name_attr);
        }

        /* XML ELEMENT -- INTRO */
        if (strcmp("*", st[i].btype) == 0)
        {
            filebuffer = ReadTexinfoFileF("promise_common_intro.texinfo");
        }
        else
        {
            filebuffer = ReadTexinfoFileF("promises/%s_intro.texinfo", st[i].subtype);
        }
        XmlTag(writer, XMLTAG_INTRO, filebuffer, 0);
        free(filebuffer);

        if (strcmp("*", st[i].btype) != 0)
        {
            /* XML ELEMENT -- LONG DESCRIPTION */
            filebuffer = ReadTexinfoFileF("promises/%s_notes.texinfo", st[i].subtype);
            XmlTag(writer, XMLTAG_LONGDESCRIPTION, filebuffer, 0);
            free(filebuffer);

            /* XML ELEMENT -- EXAMPLE */
            filebuffer = ReadTexinfoFileF("promises/%s_example.texinfo", st[i].subtype);
            XmlTag(writer, XMLTAG_EXAMPLE, filebuffer, 0);
            free(filebuffer);
        }

        /* EXPORT CONSTRAINTS */
        XmlExportConstraints(writer, st[i].bs);

        /* END XML ELEMENT -- PROMISE TYPE */
        XmlEndTag(writer, XMLTAG_PROMISETYPE);
    }
}