Example #1
0
	bool Utils::VixieCron::Entry::parseFields(const std::string &fields) {
		std::vector<std::string> tokens;
		bool ret = true;
		
		Rpn<void>::parse(fields, tokens, " \t", '\\', "", "");
		if(tokens.size() != 5)
			return(false);
		
		rangeSet(this->minutes, false);
		rangeSet(this->hours, false);
		rangeSet(this->doms, false);
		rangeSet(this->dows, false);
		rangeSet(this->months, false);
		
		ret = ret && this->parseField(tokens[0], this->minutes);
		
		ret = ret && this->parseField(tokens[1], this->hours);
		
		ret = ret && this->parseField(tokens[2], this->doms, 1);
		
		ret = ret && this->parseField(tokens[3], this->months, 1);
		
		ret = ret && this->parseField(tokens[4], this->dows);
		
		if(ret) {
			this->dows[0] = this->dows[7] = this->dows[0] || this->dows[7];
		}
		
		return(ret);
	}
Example #2
0
ranges(const Tufao::Headers &headers, qulonglong fileSize)
{
    if (!headers.contains("Range"))
        return QList< QPair<qulonglong, qulonglong> >();

    QList< QPair<qulonglong, qulonglong> > ranges;

    QList<QByteArray> rangeHeaders(headers.values("Range"));
    foreach (QByteArray rangesSpecifier, rangeHeaders) {
        static const QByteArray bytesUnit("bytes=");
        if (!rangesSpecifier.startsWith(bytesUnit))
            continue;

        QList<QByteArray> rangeSet(rangesSpecifier.mid(bytesUnit.size())
                                   .split(','));
        foreach (QByteArray rangeSpec, rangeSet) {
            rangeSpec = rangeSpec.trimmed();

            if (rangeSpec.startsWith('-')) {
                bool ok;
                qulonglong nbytes = rangeSpec.mid(1).toULongLong(&ok);
                if (!ok || nbytes == 0)
                    continue;

                if (nbytes >= fileSize) {
                    ranges.push_back(QPair<qulonglong, qulonglong>
                                     (0, fileSize - 1));
                } else {
                    ranges.push_back(QPair<qulonglong, qulonglong>
                                     (fileSize - nbytes, fileSize - 1));
                }
            } else {
                int i = rangeSpec.indexOf('-');
                if (i == -1)
                    continue;

                bool ok[2];
                QPair<qulonglong, qulonglong>
                        range(rangeSpec.toULongLong(ok),
                              rangeSpec.mid(1 + i).toULongLong());

                if (!ok[1])
                    range.second = fileSize - 1;

                if (!ok[0] || range.second < range.first
                        || range.first >= fileSize)
                    continue;

                if (range.second >= fileSize)
                    range.second = fileSize;

                ranges.push_back(range);
            }
        }
    }
Example #3
0
	bool Utils::VixieCron::Entry::parseKeyword(const std::string &kw) {
		rangeSet(this->minutes, false);
		rangeSet(this->hours, false);
		rangeSet(this->doms, false);
		rangeSet(this->dows, false);
		rangeSet(this->months, false);
		this->minutes[0] = true;
		
		if(kw.compare(0, 6, "reboot") == 0) {
			this->reboot = true;
		}
		else if(kw.compare(0, 6, "yearly") == 0) {
			this->hours[0] = true;
			this->doms[0] = true;
			this->months[0] = true;
			rangeSet(this->dows, true);
		}
		else if(kw.compare(0, 7, "monthly") == 0) {
			this->hours[0] = true;
			this->doms[0] = true;
			this->months[0] = true;
			rangeSet(this->dows, true);
		}
		else if(kw.compare(0, 6, "weekly") == 0) {
			this->hours[0] = true;
			this->dows[0] = true;
			rangeSet(this->doms, true);
			rangeSet(this->months, true);
		}
		else if(kw.compare(0, 5, "daily") == 0) {
			this->hours[0] = true;
			rangeSet(this->doms, true);
			rangeSet(this->dows, true);
			rangeSet(this->months, true);
		}
		else if(kw.compare(0, 6, "hourly") == 0) {
			rangeSet(this->hours, true);
			rangeSet(this->doms, true);
			rangeSet(this->dows, true);
			rangeSet(this->months, true);
		}
		else {
			return(false);
		}
		
		return(true);
	}
Example #4
0
	bool Utils::VixieCron::Entry::parseSubfield(
		const std::string &subfield,
		std::vector<bool> &out,
		int min
	) {
		std::string from;
		std::string to;
		std::string step;
		int from_i;
		int to_i;
		int step_i;
		
		int token = 0;
		
		if(subfield.size() == 0)
			return(false);
		
		if(subfield == "*") {
			rangeSet(out, true);
			return(true);
		}
		else if(subfield.size() > 2) {
			if(subfield.compare(0, 2, "*/") == 0) {
				from_i = 0;
				to_i = out.size() - 1;
				step_i = atoi(subfield.c_str() + 2);
				token = 2;
				goto parsed;
			}
		}
		
		for(int i = 0, l = subfield.size() ; i < l ; i++) {
			int c = subfield[i];
			
			if(token == 0) {
				if(c == '-')
					token = 1;
				else
					from += c;
			}
			else if(token == 1) {
				if(c == '/')
					token = 2;
				else
					to += c;
			}
			else if(token == 2) {
				step += c;
			}
		}
		
		from_i = atoi(from.c_str()) - min;
		to_i = atoi(to.c_str()) - min;
		step_i = atoi(step.c_str());
		
		parsed:
		
		if(from_i < 0 || (unsigned) from_i >= out.size())
			return(false);
		
		if(token >= 1) {
			if(to_i < 0 || (unsigned) to_i >= out.size())
				return(false);
		}
		else {
			to_i = from_i;
		}
		
		if(token == 2) {
			if(step_i <= 0)
				return(false);
		}
		else {
			step_i = 1;
		}
		
		for(int i = from_i ; i <= to_i ; i += step_i) {
			out[i] = true;
		}
		
		return(true);
	}