MCPcopy Create free account
hub / github.com/MaxBelkov/visualsyslog / IsValidSyslogDate

Function IsValidSyslogDate

source/server.cpp:274–337  ·  view source on GitHub ↗

--------------------------------------------------------------------------- sample: "Sep 2 09:46:37"

Source from the content-addressed store, hash-verified

272//---------------------------------------------------------------------------
273// sample: "Sep 2 09:46:37"
274bool IsValidSyslogDate(const char * p)
275{
276 char * szMonths[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
277 "Aug", "Sep", "Oct", "Nov", "Dec" };
278 int Month = 0;
279 for(int i=0; i<12; i++)
280 {
281 if( strncmp(p, szMonths[i], 3) == 0 )
282 Month = i + 1;
283 }
284 if( Month == 0 )
285 return false;
286 p += 3;
287
288 // space
289 if( *p++ != ' ' )
290 return false;
291
292 // day
293 if( *p != ' ' && ! isdigit(*p) )
294 return false;
295 if( ! isdigit(*(p+1)) )
296 return false;
297 p += 2;
298
299 // space
300 if( *p++ != ' ' )
301 return false;
302
303 // hour
304 if( ! isdigit(*p) )
305 return false;
306 if( ! isdigit(*(p+1)) )
307 return false;
308 p += 2;
309
310 // :
311 if( *p++ != ':' )
312 return false;
313
314 // min
315 if( ! isdigit(*p) )
316 return false;
317 if( ! isdigit(*(p+1)) )
318 return false;
319 p += 2;
320
321 // :
322 if( *p++ != ':' )
323 return false;
324
325 // sec
326 if( ! isdigit(*p) )
327 return false;
328 if( ! isdigit(*(p+1)) )
329 return false;
330 p += 2;
331

Callers 1

FromStringSyslogdMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected