Пример #1
0
	bool fromString(const QByteArray &str)
	{
		PropList list;
		int at = 0;
		while(1) {
			int n = str.indexOf('=', at);
			if(n == -1)
				break;
			QByteArray var, val;
			var = str.mid(at, n-at);
			at = n + 1;
			if(str[at] == '\"') {
				++at;
				n = str.indexOf('\"', at);
				if(n == -1)
					break;
				val = str.mid(at, n-at);
				at = n + 1;
			}
			else {
				n = str.indexOf(',', at);
				if(n != -1) {
					val = str.mid(at, n-at);
					at = n;
				}
				else {
					val = str.mid(at);
					at = str.length()-1;
				}
			}
			Prop prop;
			prop.var = var;
			prop.val = val;
			list.append(prop);

			if(str[at] != ',')
				break;
			++at;
		}

		// integrity check
		if(list.varCount("nonce") != 1)
			return false;
		if(list.varCount("algorithm") != 1)
			return false;
		*this = list;
		return true;
	}
    bool fromString(const QByteArray &str)
    {
        PropList list;
        int at = 0;
        while(1) {
            while (at < str.length() && (str[at] == ',' || str[at] == ' ' || str[at] == '\t'))
                ++at;
            int n = str.indexOf('=', at);
            if(n == -1)
                break;
            QByteArray var, val;
            var = str.mid(at, n-at);
            at = n + 1;
            if(str[at] == '\"') {
                ++at;
                n = str.indexOf('\"', at);
                if(n == -1)
                    break;
                val = str.mid(at, n-at);
                at = n + 1;
            }
            else {
                n = at;
                while (n < str.length() && str[n] != ',' && str[n] != ' ' && str[n] != '\t')
                    ++n;
                val = str.mid(at, n-at);
                at = n;
            }
            Prop prop;
            prop.var = var;
            if (var == "qop" || var == "cipher") {
                int a = 0;
                while (a < val.length()) {
                    while (a < val.length() && (val[a] == ',' || val[a] == ' ' || val[a] == '\t'))
                        ++a;
                    if (a == val.length())
                        break;
                    n = a+1;
                    while (n < val.length() && val[n] != ',' && val[n] != ' ' && val[n] != '\t')
                        ++n;
                    prop.val = val.mid(a, n-a);
                    list.append(prop);
                    a = n+1;
                }
            }
            else {
                prop.val = val;
                list.append(prop);
            }

            if(at >= str.size() - 1 || (str[at] != ',' && str[at] != ' ' && str[at] != '\t'))
                break;
        }

        // integrity check
        if(list.varCount("nonce") != 1)
            return false;
        if(list.varCount("algorithm") != 1)
            return false;
        *this = list;
        return true;
    }