Ejemplo n.º 1
0
bool XMLLoader::clientXMLHasValidValues(TiXmlDocument xmlFile){
	TiXmlElement *connection = xmlFile.FirstChildElement(kClientTag)->FirstChildElement(kConnectionTag);
	const char* clientIP = connection->FirstChildElement(kIPTag)->GetText();
	struct sockaddr_in sa;
	int success = inet_pton(AF_INET, clientIP, &(sa.sin_addr));
	if (success != 1){
		this->logWriter->writeInvalidValueForElementInXML(kIPTag);
		return false;
	}

	const char *clientPort = connection->FirstChildElement(kIPTag)->NextSiblingElement(kPortTag)->GetText();
	std::stringstream portStrValue;
	portStrValue << clientPort;
	unsigned int portIntValue;
	portStrValue >> portIntValue;
	if (portIntValue <= 0 || portIntValue > kMaxNumberOfValidPort) {
		this->logWriter->writeInvalidValueForElementInXML(kPortTag);
		return false;
	}

	TiXmlElement *firstMessageElement = xmlFile.FirstChildElement(kClientTag)->FirstChildElement(kConnectionTag)->NextSiblingElement(kMessagesTag)->FirstChildElement(kMessageTag);
	for(TiXmlElement *message = firstMessageElement; message != NULL; message = message->NextSiblingElement(kMessageTag)) {
		const char *messageID = message->FirstChildElement(kMessageIDTag)->GetText();
		this->messageIDList.push_back(messageID);

		string messageType = stringFromChar(message->FirstChildElement(kMessageTypeTag)->GetText());
		if ((messageType.compare(kMessageTypeInt) != 0) && (messageType.compare(kMessageTypeString) != 0) && (messageType.compare(kMessageTypeChar) != 0) && (messageType.compare(kMessageTypeDouble) != 0)) {
			this->logWriter->writeInvalidValueForElementInXML(kMessageTypeTag);
			return false;
		}
	}

	return true;
}
Ejemplo n.º 2
0
static void systemGetEnv(Thread *thread) {
    char *env = getenv(stringToCString(thread->variable(0).object));

    if (!env) {
        thread->returnNothingnessFromFunction();
        return;
    }

    thread->returnOEValueFromFunction(stringFromChar(env));
}
Ejemplo n.º 3
0
static Something systemGetEnv(Thread *thread){
    char* variableName = stringToChar(stackGetVariable(0, thread).object->value);
    char* env = getenv(variableName);
    
    if(!env)
        return NOTHINGNESS;
    
    free(variableName);
    return somethingObject(stringFromChar(env));
}
Ejemplo n.º 4
0
static void systemArgs(Thread *thread) {
    auto listObject = thread->retain(newObject(CL_LIST));

    auto *newList = listObject->val<List>();
    newList->capacity = cliArgumentCount;
    Object *items = newArray(sizeof(Value) * cliArgumentCount);

    listObject->val<List>()->items = items;

    for (int i = 0; i < cliArgumentCount; i++) {
        listAppendDestination(listObject, thread)->copySingleValue(T_OBJECT, stringFromChar(cliArguments[i]));
    }

    thread->release(1);
    thread->returnFromFunction(listObject.unretainedPointer());
}
Ejemplo n.º 5
0
static Something systemArgs(Thread *thread) {
    stackPush(NOTHINGNESS, 1, 0, thread);
    
    Object *listObject = newObject(CL_LIST);
    stackSetVariable(0, somethingObject(listObject), thread);
    
    List *newList = listObject->value;
    newList->capacity = cliArgumentCount;
    Object *items = newArray(sizeof(Something) * cliArgumentCount);
    
    listObject = stackGetVariable(0, thread).object;
    
    ((List *)listObject->value)->items = items;
    
    for (int i = 0; i < cliArgumentCount; i++) {
        listAppend(listObject, somethingObject(stringFromChar(cliArguments[i])), thread);
    }
    
    stackPop(thread);
    return somethingObject(listObject);
}
Ejemplo n.º 6
0
static void systemCWD(Thread *thread) {
    char path[1050];
    getcwd(path, sizeof(path));
    thread->returnFromFunction(stringFromChar(path));
}
Ejemplo n.º 7
0
static Something systemCWD(Thread *thread){
    char path[1050];
    getcwd(path, sizeof(path));
    
    return somethingObject(stringFromChar(path));
}
Ejemplo n.º 8
0
static Something errorGetMessage(Thread *thread){
    EmojicodeError *error = stackGetThisObject(thread)->value;
    return somethingObject(stringFromChar(error->message));
}