Exemple #1
0
std::string Time::addTime(int addHours, int addMinutes, int addSeconds){
    seconds = seconds + addSeconds;
    if(seconds >= 60){
	seconds = seconds - 60;
	++ addMinutes;
    }
    minutes = minutes + addMinutes;
    if(minutes >= 60){
	minutes = minutes - 60;
	++ addHours;
    }
    hours = hours + addHours;
    if(hours >= 24){
	hours = hours - 24;
	++ day;
    }
    return stringTime();
}
Exemple #2
0
/**
 * TODO Improve speed of this method (with KRegExp class for example)
 */
LogLine *SyslogAnalyzer::parseMessage(const QString &logLine, const LogFile &originalFile)
{
    // logDebug() << QTime::currentTime() << " : Reading line : " << logLine << " from " <<
    // originalFile.url.path();

    // 15 is the default date size format
    if (logLine.length() < 15) {
        logDebug() << "Too short line";
        return undefinedLogLine(logLine, originalFile);
    }

    int year = QDate::currentDate().year();

    // Month number
    QString month(logLine.left(3));

    QString line(logLine);

    line = line.remove(0, 4);
    int monthNum = ParsingHelper::instance()->parseSyslogMonth(month);

    // Day number
    QString day(line.left(2));
    int dayNum = day.toInt();

    line = line.remove(0, 3);

    // Time
    QString stringTime(line.left(8));
    int h = stringTime.leftRef(2).toInt();
    stringTime.remove(0, 3);
    int m = stringTime.leftRef(2).toInt();
    stringTime.remove(0, 3);
    int s = stringTime.leftRef(2).toInt();
    stringTime.remove(0, 3);

    QDateTime dateTime(QDate(year, monthNum, dayNum), QTime(h, m, s));
    if (dateTime.isValid() == false) {
        logDebug() << "Malformed date and time";
        return undefinedLogLine(logLine, originalFile);
    }

    line = line.remove(0, 9);

    QString hostname;

    int nextSpace = line.indexOf(QLatin1Char(' '));
    int nextDoubleDot = line.indexOf(QLatin1Char(':'));

    // Normal case or no process name
    if (nextSpace < nextDoubleDot || nextDoubleDot == -1) {
        // Host name
        hostname = line.left(nextSpace);
        line = line.remove(0, nextSpace + 1);
    }
    // No host name case (very rare)
    else {
        // Host name
        hostname = undefinedHostName();
    }

    // Refresh double dot once the line has been substr'ed
    nextDoubleDot = line.indexOf(QLatin1Char(':'));

    QString process;
    QString message;

    // Process name
    if (nextDoubleDot != -1) {
        process = line.left(nextDoubleDot);

        // If the delete process identifier option is enabled
        if (KSystemLogConfig::deleteProcessIdentifier() == true) {
            int squareBracket = process.indexOf(QLatin1Char('['));

            // If we find a bracket, we remove the useless part
            if (squareBracket != -1) {
                process = process.left(squareBracket);
            }
        }
        line = line.remove(0, nextDoubleDot + 1);

        message = line.remove(0, 1);
    }
    // If we can't find any ':' character, it means that this line is a
    // internal message of syslogd
    else {
        if (line.contains(QLatin1String("last message repeated"))
            || line.contains(QLatin1String("-- MARK --"))) {
            process = QStringLiteral("syslog");
        } else {
            process = undefinedProcess();
        }

        message = line;
    }

    QStringList list;
    list.append(hostname);
    list.append(process);
    list.append(message);

    return new LogLine(logLineInternalIdGenerator++, dateTime, list, originalFile.url().path(),
                       originalFile.defaultLogLevel(), logMode);
}
Exemple #3
0
static void
retsFromOdbc(void)
{
    void *q, *q1;
    int i, l;
    int fd, flags;
    bool yearfirst, indata = false;
    long dt;			/* temporarily hold date or time */
    char *s;
    short c_type;		/* C data type */
    long input_length, output_length;
    char tbuf[20];		/* temp buf, for dates and times */
    double fmoney;		/* float version of money */
    int blobcount = 0;
    bool fbc = fetchBlobColumns;

    /* no blobs unless proven otherwise */
    rv_blobLoc = 0;
    rv_blobSize = nullint;

    if(!rv_numRets)
	errorPrint("@calling retsFromOdbc() with no returns pending");

    stmt_text = "retsFromOdbc";
    debugStatement();

/* count the blobs */
    if(fbc)
	for(i = 0; i < rv_numRets; ++i)
	    if(rv_type[i] == 'B' || rv_type[i] == 'T')
		++blobcount;
    if(blobcount > 1) {
	i_puts(MSG_DBManyBlobs);
	fbc = false;
    }

    for(i = 0; i < rv_numRets; ++i) {
	if(!indata) {
	    q = va_arg(sqlargs, void *);
	    if(!q) {
		if(i)
		    break;
		indata = true;
	    }
	}
	if(indata) {
	    if(rv_type[i] == 'S') {
		q = retstring[i];
		rv_data[i].ptr = q;
	    } else
		q = rv_data + i;
	}
	if((int)q < 1000 && (int)q > -1000)
	    errorPrint("2retsFromOdbc, pointer too close to 0");
	q1 = q;
	tbuf[0] = 0;
	output_length = 0;

	switch (rv_type[i]) {
	case 'S':
	    c_type = SQL_C_CHAR;
	    input_length = STRINGLEN + 1;
	    *(char *)q = 0;	/* null */
	    break;

	case 'C':
	    c_type = SQL_C_CHAR;
	    input_length = 2;
	    *(char *)q = 0;	/* null */
	    q1 = tbuf;
	    break;

	case 'F':
	    c_type = SQL_C_DOUBLE;
	    input_length = 8;
	    *(double *)q = nullfloat;	/* null */
	    break;

	case 'N':
	    c_type = SQL_C_SLONG;
	    input_length = 4;
	    *(long *)q = nullint;	/* null */
	    break;

	case 'M':
	    c_type = SQL_C_DOUBLE;
	    input_length = 8;
	    fmoney = nullfloat;
	    q1 = &fmoney;
	    break;

	case 'D':
	    c_type = SQL_C_CHAR;
	    input_length = 11;
	    q1 = tbuf;
	    break;

	case 'I':
	    c_type = SQL_C_CHAR;
	    input_length = 10;
	    q1 = tbuf;
	    break;

	case 'B':
	case 'T':
	    c_type = SQL_C_BINARY;
	    input_length = sizeof (blobbuf);
	    q1 = blobbuf;
	    *(long *)q = nullint;
	    break;

	default:
	    errorPrint("@retsFromOdbc, rv_type[%d] = %c", i, rv_type[i]);
	}			/* switch */

	if(everything_null || c_type == SQL_C_BINARY && !fbc) {
	    rc = SQL_SUCCESS;
	    output_length = SQL_NULL_DATA;
	} else {
	    rc = SQLGetData(hstmt, (ushort) (i + 1),
	       c_type, q1, input_length, &output_length);
	    /* we'll deal with blob overflow later */
	    if(rc == SQL_SUCCESS_WITH_INFO && c_type == SQL_C_BINARY &&
	       output_length > sizeof (blobbuf))
		rc = SQL_SUCCESS;
	    if(errorTrap(0))
		break;
	    if(output_length == SQL_NO_TOTAL)
		errorPrint
		   ("@retsFromOdbc cannot get size of data for column %d",
		   i + 1);
	}

	/* Postprocess the return values. */
	/* For instance, turn string dates into our own 4-byte format. */
	s = tbuf;
	clipString(s);
	switch (rv_type[i]) {
	case 'C':
	    *(char *)q = tbuf[0];
	    break;

	case 'S':
	    clipString(q);
	    break;

	case 'D':
	    yearfirst = false;
	    if(s[4] == '-')
		yearfirst = true;
	    dt = stringDate(s, yearfirst);
	    if(dt < 0)
		errorPrint("@database holds invalid date %s", s);
	    *(long *)q = dt;
	    break;

	case 'I':
	    /* thanks to stringTime(), this works
	       for either hh:mm or hh:mm:ss */
	    if(s[0] == 0)
		*(long *)q = nullint;
	    else {
		/* Note that Informix introduces a leading space,
		   how about ODBC? */
		leftClipString(s);
		if(s[1] == ':')
		    shiftRight(s, '0');
		dt = stringTime(s);
		if(dt < 0)
		    errorPrint("@database holds invalid time %s", s);
		*(long *)q = dt;
	    }
	    break;

	case 'M':
	    if(fmoney == nullfloat)
		dt = nullint;
	    else
		dt = fmoney * 100.0 + 0.5;
	    *(long *)q = dt;
	    break;

	case 'B':
	case 'T':
	    if(output_length == SQL_NULL_DATA)
		break;
	    /* note, 0 length blob is treated as a null blob */
	    if(output_length == 0)
		break;
	    /* the size of the blob is returned, in an int. */
	    *(long *)q = output_length;
	    rv_blobSize = output_length;

	    if(isnullstring(rv_blobFile)) {
		/* the blob is always allocated; you have to free it! */
		/* SQL doesn't null terminate its text blobs, but we do. */
		rv_blobLoc = allocMem(output_length + 1);
		l = output_length;
		if(l > sizeof (blobbuf))
		    l = sizeof (blobbuf);
		memcpy(rv_blobLoc, blobbuf, l);
		if(l < output_length) {	/* more to do */
		    long waste;
		    rc = SQLGetData(hstmt, (ushort) (i + 1),
		       c_type, (char *)rv_blobLoc + l,
		       output_length - l, &waste);
		    if(rc) {
			nzFree(rv_blobLoc);
			rv_blobLoc = 0;
			*(long *)q = nullint;
			errorTrap(0);
			goto breakloop;
		    }		/* error getting rest of blob */
		}		/* blob is larger than the buffer */
		if(rv_type[i] == 'T')	/* null terminate */
		    ((char *)rv_blobLoc)[output_length] = 0;
		break;
	    }

	    /* blob in memory */
	    /* at this point the blob is being dumped into a file */
	    flags = O_WRONLY | O_BINARY | O_CREAT | O_TRUNC;
	    if(rv_blobAppend)
		flags = O_WRONLY | O_BINARY | O_CREAT | O_APPEND;
	    fd = eopen(rv_blobFile, flags, 0666);
	    rc = SQL_SUCCESS;
	    while(true) {
		int outbytes;
		l = output_length;
		if(l > sizeof (blobbuf))
		    l = sizeof (blobbuf);
		outbytes = write(fd, blobbuf, l);
		if(outbytes < l) {
		    close(fd);
		    errorPrint("2cannot write to file %s, errno %d",
		       rv_blobFile, errno);
		}
		if(l == output_length)
		    break;

		/* get the next chunk from ODBC */
		rc = SQLGetData(hstmt, (ushort) (i + 1),
		   c_type, q1, input_length, &output_length);
		if(rc == SQL_SUCCESS_WITH_INFO && output_length > input_length)
		    rc = SQL_SUCCESS;	/* data truncation error */
	    }

	    close(fd);
	    errorTrap(0);
	    break;

	}			/* switch */

    }				/* loop over returned elements */