aboutsummaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authoryaworsky <yaworsky>2005-11-15 12:36:44 +0000
committeryaworsky <yaworsky>2005-11-15 12:36:44 +0000
commitef543fb112c69bc877a1d0b22823d9e07c7ab05b (patch)
treefd62723b216338b2eb5d42e74862f7aa590bec38 /daemon
parenta704fc5981f7f2c0a3179f62f0ce818f75467078 (diff)
downloadsyslog-win32-ef543fb112c69bc877a1d0b22823d9e07c7ab05b.tar.gz
syslog-win32-ef543fb112c69bc877a1d0b22823d9e07c7ab05b.tar.xz
syslog-win32-ef543fb112c69bc877a1d0b22823d9e07c7ab05b.zip
Optimized for speed parsing the month field
Diffstat (limited to 'daemon')
-rw-r--r--daemon/syslogd.c105
1 files changed, 98 insertions, 7 deletions
diff --git a/daemon/syslogd.c b/daemon/syslogd.c
index da53e60..99e9a92 100644
--- a/daemon/syslogd.c
+++ b/daemon/syslogd.c
@@ -391,6 +391,102 @@ no_pri:
}
/******************************************************************************
+ * str2month
+ *
+ * return month (1..12) or 0 if error
+ */
+static int str2month( char* s )
+{
+ register char s1, s2, s3;
+
+ s1 = s[0];
+ if( 'A' <= s[0] && s[0] <= 'Z' )
+ s1 += 'a' - 'A';
+
+ s2 = s[1];
+ if( 'A' <= s[1] && s[1] <= 'Z' )
+ s2 += 'a' - 'A';
+
+ s3 = s[2];
+ if( 'A' <= s[2] && s[2] <= 'Z' )
+ s3 += 'a' - 'A';
+
+ if( s1 < 'm' )
+ {
+ if( s1 < 'f' )
+ {
+ if( s1 == 'a' )
+ {
+ if( s2 == 'p' && s3 == 'r' )
+ return 4; /* Apr */
+ if( s2 == 'u' && s3 == 'g' )
+ return 8; /* Aug */
+ return 0;
+ }
+ else if( s1 == 'd' )
+ {
+ if( s2 == 'e' && s3 == 'c' )
+ return 12; /* Dec */
+ return 0;
+ }
+ else
+ return 0;
+ }
+ else if( s1 == 'f' )
+ {
+ if( s2 == 'e' && s3 == 'b' )
+ return 2; /* Feb */
+ return 0;
+ }
+ else if( s1 == 'j' )
+ {
+ if( s2 == 'a' && s3 == 'n' )
+ return 1; /* Jan */
+ if( s2 != 'u' )
+ return 0;
+ if( s3 == 'l' )
+ return 7; /* Jul */
+ if( s3 == 'n' )
+ return 6; /* Jun */
+ return 0;
+ }
+ else
+ return 0;
+ }
+ else if( s1 > 'm' )
+ {
+ if( s1 < 'o' )
+ {
+ if( s1 == 'n' && s2 == 'o' && s3 == 'v' )
+ return 11; /* Nov */
+ return 0;
+ }
+ else if( s1 > 'o' )
+ {
+ if( s1 == 's' && s2 == 'e' && s3 == 'p' )
+ return 9; /* Sep */
+ return 0;
+ }
+ else /* s1 == 'o' */
+ {
+ if( s2 == 'c' && s3 == 't' )
+ return 10; /* Oct */
+ return 0;
+ }
+ }
+ else /* s1 == 'm' */
+ {
+ if( s2 != 'a' )
+ return 0;
+ if( s3 == 'r' )
+ return 3; /* Mar */
+ if( s3 == 'y' )
+ return 5; /* May */
+ return 0;
+ }
+}
+
+/******************************************************************************
* parse_timestamp
*
* parse TIMESTAMP part of message;
@@ -398,16 +494,11 @@ no_pri:
*/
static gchar* parse_timestamp( gchar* msg, LPSYSTEMTIME timestamp )
{
- int i;
-
TRACE_ENTER( "\n" );
- for( i = 0; i < 12; i++ )
- if( strncasecmp( msg, str_month[ i ], 3 ) == 0 )
- break;
- if( i == 12 )
+ timestamp->wMonth = str2month( msg );
+ if( 0 == timestamp->wMonth )
goto no_timestamp;
- timestamp->wMonth = i + 1;
if( msg[3] != ' ' )
goto no_timestamp;