logswan

Fast Web log analyzer using probabilistic data structures
Log | Files | Refs | README | LICENSE

parse.c (1331B)


      1 /*
      2  * Logswan 2.1.6
      3  * Copyright (c) 2015-2020, Frederic Cambus
      4  * https://www.logswan.org
      5  *
      6  * Created:      2015-05-31
      7  * Last Updated: 2019-01-19
      8  *
      9  * Logswan is released under the BSD 2-Clause license.
     10  * See LICENSE file for details.
     11  */
     12 
     13 #include <string.h>
     14 
     15 #include "parse.h"
     16 
     17 void
     18 parseDate(struct date *parsedDate, char *date)
     19 {
     20 	parsedDate->day = strtok(date, "/");
     21 	parsedDate->month = strtok(NULL, "/");
     22 	parsedDate->year = strtok(NULL, ":");
     23 	parsedDate->hour = strtok(NULL, ":");
     24 	parsedDate->minute = strtok(NULL, ":");
     25 	parsedDate->second = strtok(NULL, " ");
     26 }
     27 
     28 void
     29 parseLine(struct logLine *parsedLine, char *lineBuffer)
     30 {
     31 	if (*lineBuffer) {
     32 		/* Remote host */
     33 		parsedLine->remoteHost = strtok(lineBuffer, " ");
     34 
     35 		/* User-identifier */
     36 		strtok(NULL, " ");
     37 
     38 		/* User ID */
     39 		strtok(NULL, "[");
     40 
     41 		/* Date */
     42 		parsedLine->date = strtok(NULL, "]");
     43 
     44 		/* Requested resource */
     45 		strtok(NULL, "\"");
     46 		parsedLine->request = strtok(NULL, "\"");
     47 
     48 		/* HTTP status codes */
     49 		parsedLine->statusCode = strtok(NULL, " ");
     50 
     51 		/* Returned object size */
     52 		parsedLine->objectSize = strtok(NULL, " \"");
     53 	}
     54 }
     55 
     56 void
     57 parseRequest(struct request *parsedRequest, char *request)
     58 {
     59 	char *pch = strrchr(request, ' ');
     60 
     61 	if (pch) {
     62 		parsedRequest->protocol = pch + 1;
     63 		parsedRequest->method = strtok(request, " ");
     64 	}
     65 }