Exemplo n.º 1
0
    QString Address::toString() const
    {
        QString ad =  device + ":/" + path.join("/");
        if (!validateString(ad))
            ad.clear();

        return ad;
    }
Exemplo n.º 2
0
char parseAndSave(char* line){
	char* strPointer;
	char* descriptionStartPointer;
	char* key=NULL;
	char* description=NULL;
	strPointer=line;
	while(*strPointer!='\0'){
		if(*strPointer=='\t'){
			if(key!=NULL){
				//tabulation is ok only once, so key should not be setted
				perror("Invalid file structure");
				return -1;
			}
			*strPointer='\0';	
			key=line;
			if(validateString(key)==STRING_UNVALID){
				perror("Invalid file structure");
				return -1;
			}
			descriptionStartPointer=strPointer+1;
		}
		if(*strPointer=='\n'){
			*strPointer='\0';
			description=descriptionStartPointer;
			if(validateString(description)==STRING_UNVALID){
				perror("Invalid file structure");
				return -1;
			}
		}
		strPointer++;
	}
	if (key==NULL||description==NULL){
		perror("Invalid file structure");
		return -1;
	}
	
	if(DictionaryAdd(dictionary,key, description)!=0)
		return -1;
	return 0;
}
/*!
 \fn validateData
 \return boolean - true, everything validated OK, false otherwise
 
 Validates data in this container. 
 */   
bool NmApiMailboxSettingsDataPrivate::validateData() const
{
    NM_FUNCTION;
    QHash<int, QVariant>::const_iterator i = mSettings->constBegin();
    while (i != mSettings->constEnd()) {
        
        bool validated = false;
        bool valid = false;        
        
        int key = i.key();
        QVariant val = i.value();
        
        ++i;
        
        valid = validateString(key ,val, validated);
        if (validated) {
            if (!valid){
                return valid;
            }
            continue;
        }
        
        valid = validateInteger(key ,val, validated);
        if (validated) {
            if (!valid){
                return valid;
            }
            continue;
        }
         
        valid = validateBool(key ,val, validated);
        if (validated) {
            if (!valid){
                return valid;
            }
            continue;
        } 
         
        valid = validateDateTime(key ,val, validated);
        if (validated) {
            if (!valid){
                return valid;
            }
            continue;
        }
     }
     return true;
}
Exemplo n.º 4
0
    Address Address::fromString(const QString &str)
    {
        if (!validateString( str))
            return {"", {""} };

        QStringList path = str.split("/");
        ISCORE_ASSERT(path.size() > 0);

        auto device = path.first().remove(":");
        path.removeFirst(); // Remove the device.
        if(path.first().isEmpty()) // case "device:/"
        {
            return {device, {}};
        }

        return {device, path};
    }
Exemplo n.º 5
0
void ArgParse::validateValue(const ArgParse::ValueType type,
                             const std::string name,
                             const std::string choices,
                             const std::string value) const
{
  switch ( type ) {
     case INT :
       validateInt(name, choices, value);
       break;
     case FLOAT :
       validateFloat(name, choices, value);
       break;
     case BOOL :
       validateBool(name, choices, value);
       break;
     case STRING :
       validateString(name, choices, value);
       break;
     default:
       break;
   }
}
Exemplo n.º 6
0
static rfbBool
parseParams(const char *request, char *result, int max_bytes)
{
    char param_request[128];
    char param_formatted[196];
    const char *tail;
    char *delim_ptr;
    char *value_str;
    int cur_bytes, len;

    result[0] = '\0';
    cur_bytes = 0;

    tail = request;
    for (;;) {
	/* Copy individual "name=value" string into a buffer */
	delim_ptr = strchr((char *)tail, '&');
	if (delim_ptr == NULL) {
	    if (strlen(tail) >= sizeof(param_request)) {
		return FALSE;
	    }
	    strcpy(param_request, tail);
	} else {
	    len = delim_ptr - tail;
	    if (len >= sizeof(param_request)) {
		return FALSE;
	    }
	    memcpy(param_request, tail, len);
	    param_request[len] = '\0';
	}

	/* Split the request into parameter name and value */
	value_str = strchr(&param_request[1], '=');
	if (value_str == NULL) {
	    return FALSE;
	}
	*value_str++ = '\0';
	if (strlen(value_str) == 0) {
	    return FALSE;
	}

	/* Validate both parameter name and value */
	if (!validateString(param_request) || !validateString(value_str)) {
	    return FALSE;
	}

	/* Prepare HTML-formatted representation of the name=value pair */
	len = sprintf(param_formatted,
		      "<PARAM NAME=\"%s\" VALUE=\"%s\">\n",
		      param_request, value_str);
	if (cur_bytes + len + 1 > max_bytes) {
	    return FALSE;
	}
	strcat(result, param_formatted);
	cur_bytes += len;

	/* Go to the next parameter */
	if (delim_ptr == NULL) {
	    break;
	}
	tail = delim_ptr + 1;
    }
    return TRUE;
}
TEST(LexerJson, String)
{
    std::stringstream                       jsonElements("\"Text\" \"\\\"\"  \"\\\\\" \"\\/\" \"\\b\" \"\\f\" \"\\n\" \"\\r\" \"\\t\" \"\\u0020\" \"\\u00a0\" \"\\u1Fd5\" \"\\uD834\\uDD1E\"");
    ThorsAnvil::Json::LexerJson             parser(jsonElements);
    ThorsAnvil::Json::ParserCleanInterface  cleanInterface;


    ASSERT_TRUE(validateString(parser, cleanInterface, "Text"));
    ASSERT_TRUE(validateString(parser, cleanInterface, "\""));
    ASSERT_TRUE(validateString(parser, cleanInterface, "\\"));
    ASSERT_TRUE(validateString(parser, cleanInterface, "/"));
    ASSERT_TRUE(validateString(parser, cleanInterface, "\b"));
    ASSERT_TRUE(validateString(parser, cleanInterface, "\f"));
    ASSERT_TRUE(validateString(parser, cleanInterface, "\n"));
    ASSERT_TRUE(validateString(parser, cleanInterface, "\r"));
    ASSERT_TRUE(validateString(parser, cleanInterface, "\t"));


    /*
     * The Unicode code point 002O is encoded in UTF-8 as 20
     * see http://www.fileformat.info/info/unicode/char/20/index.htm
     */
    ASSERT_TRUE(validateString(parser, cleanInterface, "\x020"));


    /*
     * The Unicode code point 00AO is encoded in UTF-8 as C2 A0
     * see http://www.fileformat.info/info/unicode/char/A0/index.htm
     */
    ASSERT_TRUE(validateString(parser, cleanInterface, "\x0c2\x0a0"));

    /*
     * The Unicode code point 1FD5 is encoded in UTF-8 as E1 BF 95
     * see http://www.fileformat.info/info/unicode/char/1FD5/index.htm
     */
    ASSERT_TRUE(validateString(parser, cleanInterface, "\x0e1\x0bf\x095"));

    /*
     * The unicode code point 1D11E is encoded in UTF-8 as 0xF0 0x9D 0x84 0x9E
     * Note it is encode in Json as UTF-16 surrogate pair 0xD834 0xDD1E
     * http://www.fileformat.info/info/unicode/char/1D11E/index.htm
     */
    ASSERT_TRUE(validateString(parser, cleanInterface, "\x0F0\x09D\x084\x09E"));

}