Beispiel #1
0
char *getXmlFromRoot(Dictionary * root)
{
	char buffer[4096];
	char *toReturn;
	char *ret;
	size_t toReturnSize;

	sprintf(buffer,
		"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">\n");
	toReturnSize = sizeof(char) * (strlen(buffer) + 1);
	toReturn = malloc(toReturnSize);
	toReturn = strcpy(toReturn, buffer);

	ret = getXmlFromDictionary(root, 0);
	toReturnSize += sizeof(char) * (strlen(ret) + 1);
	toReturn = realloc(toReturn, toReturnSize);
	toReturn = strcat(toReturn, ret);
	free(ret);

	sprintf(buffer, "</plist>\n");
	toReturnSize += sizeof(char) * (strlen(buffer) + 1);
	toReturn = realloc(toReturn, toReturnSize);
	toReturn = strcat(toReturn, buffer);

	return toReturn;

}
Beispiel #2
0
char *getXmlFromDictionary(Dictionary * myself, int tabsCount)
{
	char tabs[100];
	char buffer[4096];
	char *toReturn;
	char *ret;
	size_t toReturnSize;
	int i;
	DictValue *curValue;

	tabs[0] = '\0';
	for (i = 0; i < tabsCount; i++) {
		strcat(tabs, "\t");
	}

	sprintf(buffer, "%s<dict>\n", tabs);
	toReturnSize = sizeof(char) * (strlen(buffer) + 1);
	toReturn = malloc(toReturnSize);
	toReturn = strcpy(toReturn, buffer);

	curValue = myself->values;
	while (curValue != NULL) {
		sprintf(buffer, "%s\t<key>%s</key>\n", tabs, curValue->key);
		toReturnSize += sizeof(char) * (strlen(buffer) + 1);
		toReturn = realloc(toReturn, toReturnSize);
		toReturn = strcat(toReturn, buffer);

		if (curValue->type == DictionaryType) {
			ret =
			    getXmlFromDictionary((Dictionary *) curValue,
						 tabsCount + 1);
			toReturnSize += sizeof(char) * (strlen(ret) + 1);
			toReturn = realloc(toReturn, toReturnSize);
			toReturn = strcat(toReturn, ret);
			free(ret);

		} else if (curValue->type == StringType) {
			sprintf(buffer, "%s\t<string>%s</string>\n", tabs,
				((StringValue *) curValue)->value);
			toReturnSize += sizeof(char) * (strlen(buffer) + 1);
			toReturn = realloc(toReturn, toReturnSize);
			toReturn = strcat(toReturn, buffer);

		} else if (curValue->type == DataType) {
			sprintf(buffer, "%s\t<data>%s</data>\n", tabs,
				((DataValue *) curValue)->value);
			toReturnSize += sizeof(char) * (strlen(buffer) + 1);
			toReturn = realloc(toReturn, toReturnSize);
			toReturn = strcat(toReturn, buffer);

		} else if (curValue->type == IntegerType) {
			sprintf(buffer, "%s\t<integer>%d</integer>\n", tabs,
				((IntegerValue *) curValue)->value);
			toReturnSize += sizeof(char) * (strlen(buffer) + 1);
			toReturn = realloc(toReturn, toReturnSize);
			toReturn = strcat(toReturn, buffer);

		} else if (curValue->type == ArrayType) {
			ret =
			    getXmlFromArrayValue((ArrayValue *) curValue,
						 tabsCount + 1);
			toReturnSize += sizeof(char) * (strlen(ret) + 1);
			toReturn = realloc(toReturn, toReturnSize);
			toReturn = strcat(toReturn, ret);
			free(ret);
		} else if (curValue->type == BoolType) {
			if (((BoolValue *) curValue)->value) {
				sprintf(buffer, "%s\t<true/>\n", tabs);
			} else {
				sprintf(buffer, "%s\t<false/>\n", tabs);
			}

			toReturnSize += sizeof(char) * (strlen(buffer) + 1);
			toReturn = realloc(toReturn, toReturnSize);
			toReturn = strcat(toReturn, buffer);
		}

		curValue = curValue->next;
	}

	sprintf(buffer, "%s</dict>\n", tabs);
	toReturnSize += sizeof(char) * (strlen(buffer) + 1);
	toReturn = realloc(toReturn, toReturnSize);
	toReturn = strcat(toReturn, buffer);

	return toReturn;
}
Beispiel #3
0
char* getXmlFromArrayValue(ArrayValue* myself, int tabsCount) {
	char tabs[100];
	char buffer[4096];
	char* toReturn;
	char* ret;
	size_t toReturnSize;
	int i;
	DictValue* curValue;
	
	tabs[0] = '\0';
	for(i = 0; i < tabsCount; i++) {
		strcat(tabs, "\t");
	}

	
	sprintf(buffer, "%s<array>\n", tabs);
	toReturnSize = sizeof(char) * (strlen(buffer) + 1);
	toReturn = malloc(toReturnSize);
	toReturn = strcpy(toReturn, buffer);
	
	for(i = 0; i < myself->size; i++) {
		curValue = myself->values[i];

		if(curValue->type == DictionaryType) {
			ret = getXmlFromDictionary((Dictionary*)curValue, tabsCount + 1);
			toReturnSize += sizeof(char) * (strlen(ret) + 1);
			toReturn = realloc(toReturn, toReturnSize);
			toReturn = strcat(toReturn, ret);
			free(ret);
		} else if(curValue->type == StringType) {
			sprintf(buffer, "%s\t<string>%s</string>\n", tabs, ((StringValue*)curValue)->value);
			toReturnSize += sizeof(char) * (strlen(buffer) + 1);
			toReturn = realloc(toReturn, toReturnSize);
			toReturn = strcat(toReturn, buffer);
		} else if(curValue->type == DataType) {
			char* base64 = convertBase64(((DataValue*)curValue)->value, ((DataValue*)curValue)->len, 0, -1);
			sprintf(buffer, "%s\t<data>", tabs);
			toReturnSize += sizeof(char) * (strlen(buffer) + strlen(base64) + 1);
			toReturn = realloc(toReturn, toReturnSize);
			toReturn = strcat(toReturn, buffer);
			toReturn = strcat(toReturn, base64);
			sprintf(buffer, "</data>\n", tabs);
			toReturnSize += sizeof(char) * (strlen(buffer) + 1);
			toReturn = realloc(toReturn, toReturnSize);
			toReturn = strcat(toReturn, buffer);
			free(base64);
		} else if(curValue->type == IntegerType) {
			sprintf(buffer, "%s\t<integer>%d</integer>\n", tabs, ((IntegerValue*)curValue)->value);
			toReturnSize += sizeof(char) * (strlen(buffer) + 1);
			toReturn = realloc(toReturn, toReturnSize);
			toReturn = strcat(toReturn, buffer);
		} else if(curValue->type == ArrayType) {
			ret = getXmlFromArrayValue((ArrayValue*)curValue, tabsCount + 1);
			toReturnSize += sizeof(char) * (strlen(ret) + 1);
			toReturn = realloc(toReturn, toReturnSize);
			toReturn = strcat(toReturn, ret);
			free(ret);
		} else if(curValue->type == BoolType) {
			if(((BoolValue*)curValue)->value) {
				sprintf(buffer, "%s\t<true/>\n", tabs);
			} else {
				sprintf(buffer, "%s\t<false/>\n", tabs);
			}
			toReturnSize += sizeof(char) * (strlen(buffer) + 1);
			toReturn = realloc(toReturn, toReturnSize);
			toReturn = strcat(toReturn, buffer);
		}
	}
	
	sprintf(buffer, "%s</array>\n", tabs);
	toReturnSize += sizeof(char) * (strlen(buffer) + 1);
	toReturn = realloc(toReturn, toReturnSize);
	toReturn = strcat(toReturn, buffer);
	
	return toReturn;
}