Exemplo n.º 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;
}
Exemplo n.º 2
0
static int GenerateAvahiConfig(const char *path)
{
    FILE *fout;
    Writer *writer = NULL;
    fout = 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();
    XmlTag(writer, "port", STR_CFENGINEPORT, 0);
    XmlEndTag(writer, "service");
    XmlEndTag(writer, "service-group");
    fclose(fout);

    return 0;
}
Exemplo n.º 3
0
String FormatXmlRpcValue(const Value& _v)
{
	String r;
	Value v = _v;
	if(v.GetType() == INT64_V) {
		int64 x = v;
		if((int)x == x)
			v = (int)x;
	}
	if(IsNull(v) && !IsString(v) && !IsValueArray(v))
		r = XmlTag("nil")();
	else
	if(v.GetType() == INT_V)
		r = XmlTag("int")(Format("%d", (int)v));
	else
	if(v.GetType() == BOOL_V)
		r = XmlTag("boolean")(AsString((int)(bool)v));
	else
	if(IsNumber(v))
		r = XmlTag("double")(Format("%.16g", (double)v));
	else
	if(IsDateTime(v)) {
		Time t = v;
		r = XmlTag("dateTime.iso8601")
					(Format("%04.4d%02.2d%02.2d`T%02.2d`:%02.2d`:%02.2d",
					        t.year, t.month, t.day, t.hour, t.minute, t.second));
	}
	else
	if(v.GetType() == VALUEMAP_V) {
		r = "<struct>";
		ValueMap vm = v;
		const Index<Value>& k = vm.GetKeys();
		ValueArray va = vm.GetValues();
		for(int i = 0; i < k.GetCount(); i++)
			r << XmlTag("member")(XmlTag("name")(k[i]) + FormatXmlRpcValue(va[i]));
		r << "</struct>";
	}
	else
	if(v.GetType() == VALUEARRAY_V) {
		r = "<array><data>";
		ValueArray va = v;
		for(int i = 0; i < va.GetCount(); i++)
			r << FormatXmlRpcValue(va[i]);
		r << "</data></array>";
	}
	else
	if(v.Is<RawJsonText>())
		r = XmlTag("string").Text(v.To<RawJsonText>().json);
	else
		r = XmlTag("string").Text(v);
	return XmlTag("value")(r);
}
Exemplo n.º 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);
}
Exemplo n.º 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);
}
Exemplo n.º 6
0
void test_no_attr(void **state)
{
    Writer *w = StringWriter();

    XmlTag(w, "foobar", NULL, 0);
    assert_string_equal(StringWriterClose(w), "<foobar></foobar>\n");
}
Exemplo n.º 7
0
void test_tag(void **state)
{
    Writer *w = StringWriter();

    XmlTag(w, "foobar", "some value", 1, (XmlAttribute)
           {
           "a", "b"});
    assert_string_equal(StringWriterClose(w), "<foobar a=\"b\" >some value</foobar>\n");
}
Exemplo n.º 8
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);
}
Exemplo n.º 9
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);
}
Exemplo n.º 10
0
//сохранение списка в файл
void AnimeList::Save()
{
	if(IsEmpty(filename)) {
		SaveAs();
		return;
	}
	String xml;
	for(int i = 0; i < mainArray.GetCount(); i++)
		xml <<
			XmlTag("item") (
				XmlTag("complete").Text(mainArray[i].complete) +
				XmlTag("name").Text(mainArray[i].name) +
				XmlTag("russian").Text(mainArray[i].nameRus) + 
				XmlTag("episodes").Text(AsString(mainArray[i].episodes)) +
				XmlTag("views").Text(AsString(mainArray[i].views)) +
				XmlTag("Release").Text(AsString(mainArray[i].Release)) +
				XmlTag("series").Text(mainArray[i].releaseDate)
			);
	if(!SaveFile(filename, XmlDoc("ListView", xml)))
		Exclamation("Error Saving the File");
	
	status.Set(Format("Items: %d. List Save", mainArray.GetCount()));
}
Exemplo n.º 11
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);
}
Exemplo n.º 12
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);
    }
}
Exemplo n.º 13
0
RpcGet RpcRequest::Execute()
{
	if(!shouldExecute)
		return RpcGet();
	shouldExecute = false;
	String request;
	if(json) {
		ContentType("application/json");
		static Atomic id;
		Json json;
		json("jsonrpc", "2.0")
		    ("method", method);
		if(data.out.GetCount()) {
			JsonArray a;
			for(int i = 0; i < data.out.GetCount(); i++) {
				const Value& v = data.out[i];
				if(v.Is<RawJsonText>())
					a.CatRaw(v.To<RawJsonText>().json);
				else
					a << JsonRpcData(v);
			}
			json("params", a);
		}
		else
		if(data.out_map.GetCount()) {
			Json m;
			for(int i = 0; i < data.out_map.GetCount(); i++) {
				const Value& v = data.out_map.GetValue(i);
				String key = (String)data.out_map.GetKey(i);
				if(v.Is<RawJsonText>())
					m.CatRaw(key, v.To<RawJsonText>().json);
				else
					m(key, JsonRpcData(v));
			}
			json("params", m);
		}
		json("id", id);
		AtomicInc(id);
		request = ~json;
	}
	else {
		ContentType("text/xml");
		request = XmlHeader();
		request << XmlTag("methodCall")(XmlTag("methodName")(method) + FormatXmlRpcParams(data.out));
	}
	if(sLogRpcCalls) {
		if(sLogRpcCallsCompress)
			RLOG("=== XmlRpc call request:\n" << CompressLog(request));
		else
			RLOG("=== XmlRpc call request:\n" << request);
	}
	String response;
	New();
	if(shorted)
		response = RpcExecuteShorted(request);
	else
		response = Post(request).Execute();
	if(sLogRpcCalls) {
		if(sLogRpcCallsCompress)
			RLOG("=== XmlRpc call response:\n" << CompressLog(response));
		else
			RLOG("=== XmlRpc call response:\n" << response);
	}
	RpcGet h;
	if(IsNull(response)) {
		faultCode = RPC_CLIENT_HTTP_ERROR;
		faultString = GetErrorDesc();
		error = "Http request failed: " + faultString;
		LLOG(error);
		h.v = ErrorValue(error);
		return h;
	}
	if(json) {
		try {
			Value r = ParseJSON(response);
			if(IsValueMap(r)) {
				ValueMap m = r;
				Value result = m["result"];
				if(!result.IsVoid()) {
					data.in.Clear();
					data.in.Add(result);
					data.ii = 0;
					h.v = result;
					return h;
				}
				Value e = m["error"];
				if(IsValueMap(e)) {
					Value c = e["code"];
					Value m = e["message"];
					if(IsNumber(c) && IsString(m)) {
						faultCode = e["code"];
						faultString = e["message"];
						error.Clear();
						error << "Failed '" << faultString << "' (" << faultCode << ')';
						LLOG(s);
						h.v = ErrorValue(error);
						return h;
					}
				}
			}
			String s;
			faultString = "Invalid response";
			faultCode = RPC_CLIENT_RESPONSE_ERROR;
			error = faultString;
			LLOG(error);
			h.v = ErrorValue(error);
			return h;
		}
		catch(CParser::Error e) {
			String s;
			faultString = e;
			faultCode = RPC_CLIENT_JSON_ERROR;
			error.Clear();
			error << "JSON Error: " << faultString;
			LLOG(error);
			h.v = ErrorValue(error);
			return h;
		}
	}
	else {
		XmlParser p(response);
		try {
			p.ReadPI();
			p.PassTag("methodResponse");
			if(p.Tag("fault")) {
				Value m = ParseXmlRpcValue(p);
				if(IsValueMap(m)) {
					ValueMap mm = m;
					faultString = mm["faultString"];
					faultCode = mm["faultCode"];
					error.Clear();
					error << "Failed '" << faultString << "' (" << faultCode << ')';
					LLOG(s);
					h.v = ErrorValue(error);
					return h;
				}
			}
			else {
				data.in = ParseXmlRpcParams(p);
				data.ii = 0;
				p.PassEnd();
			}
		}
		catch(XmlError e) {
			String s;
			faultString = e;
			faultCode = RPC_CLIENT_XML_ERROR;
			error.Clear();
			error << "XML Error: " << faultString;
			LLOG(error << ": " << p.GetPtr());
			h.v = ErrorValue(error);
			return h;
		}
		h.v = data.in.GetCount() ? data.in[0] : Null;
		return h;
	}
}
Exemplo n.º 14
0
//открытие файла после выбора его в системе
void AnimeList::OpenFile()
{
	mainArray.Clear();
	listName.Clear();
	try {
			String d = LoadFile(filename);
			XmlParser p(d);
			while(!p.IsTag())
				p.Skip();
			p.PassTag("ListView");
			while(!p.IsEof()) {
				if(p.Tag("item")) {
					while(!p.End()) {
						if(p.Tag("complete"))
						{
							String complete = p.ReadText();
							if(complete == "Yes")
							   cell.complete = "Yes";
							else
								if(complete == "No")
									cell.complete = "No";
								else cell.complete = "New";
						}
						else
						if(p.Tag("name"))
							cell.name = p.ReadText();
						else
						if(p.Tag("russian"))
							cell.nameRus = p.ReadText();
						else
						if(p.Tag("episodes"))
							cell.episodes = StrInt(p.ReadText());
						else
						if(p.Tag("views"))
							cell.views = StrInt(p.ReadText());
						else
						if(p.Tag("Release"))
							StrToDate(cell.Release, p.ReadText());
						else
						if(p.Tag("series"))
							cell.releaseDate = p.ReadText();
						else {
							p.Skip();
							continue;
						}
						p.PassEnd();
					}
					mainArray.Add(cell);
					listName.Add(cell.complete, cell.name, cell.nameRus, cell.episodes, cell.views, cell.Release, cell.releaseDate, mainArray.GetCount() - 1);
					RowColor(listName.GetCount()-1);
				}
				else 
					p.Skip();
			}
		}
		catch(XmlError) {
			Exclamation("Error Readong the Input File");
		} 
		
	SetupYears();
	
	Title("Anime List | " + filename);
		
	String iniFile;
	iniFile = GetDataFile("AnimeList.xml");
	String xmlIni;
	xmlIni <<
			XmlTag("File").Text(AsString(filename));
	SaveFile(iniFile, XmlDoc("FileList", xmlIni));
	
	status.Set(Format("Items: %d. List Open", listName.GetCount()));
}
Exemplo n.º 15
0
String XmlDoc(const char *name, const char *xmlbody)
{
	return XmlHeader() + XmlDocType(name) + XmlTag(name)(xmlbody);
}
Exemplo n.º 16
0
String FormatXmlRpcParam(const Value& param)
{
	return XmlTag("param")(FormatXmlRpcValue(param));
}