---------------------------------------------------------------------------
| 27 | } |
| 28 | //--------------------------------------------------------------------------- |
| 29 | bool TSyslogMessage::FromStringSyslogd(char * p, int size, sockaddr_in * from_addr) |
| 30 | { |
| 31 | if( from_addr ) |
| 32 | SourceAddr = inet_ntoa(from_addr->sin_addr); |
| 33 | else |
| 34 | SourceAddr = ""; |
| 35 | |
| 36 | PRI = -1; // not exist |
| 37 | if( *p == '<' ) |
| 38 | { |
| 39 | for(int i=1; i<5 && p[i]; i++) |
| 40 | { |
| 41 | if( p[i] == '>' ) |
| 42 | { |
| 43 | PRI = atoi(p+1); |
| 44 | p += i + 1; |
| 45 | break; |
| 46 | } |
| 47 | if( ! isdigit(p[i]) ) |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | if( PRI >= 0 ) |
| 52 | { |
| 53 | // invalid facility number not allowed: message filtering mechanism will fail |
| 54 | // replace invalid facility number by LOGALERT |
| 55 | if( LOG_FAC(PRI) >= LOG_NFACILITIES ) |
| 56 | PRI = LOG_PRI(PRI) | LOG_LOGALERT; |
| 57 | |
| 58 | Facility = getcodetext(LOG_FAC(PRI) << 3, facilitynames); |
| 59 | Priority = getcodetext(LOG_PRI(PRI), prioritynames); |
| 60 | } |
| 61 | |
| 62 | if( IsValidSyslogDate(p) ) |
| 63 | { |
| 64 | DateStr = String(p, 15); |
| 65 | p += 16; // including space |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | // month names in english in compliance to syslog rfc |
| 70 | TFormatSettings fs; |
| 71 | GetLocaleFormatSettings(0x0409, fs); // usa |
| 72 | DateStr = FormatDateTime("mmm dd hh:nn:ss", Now(), fs); |
| 73 | } |
| 74 | |
| 75 | // try to find host name |
| 76 | for(int i=0; i<255 && p[i]; i++) |
| 77 | { |
| 78 | if( p[i] == ' ' ) |
| 79 | { |
| 80 | // found |
| 81 | HostName = String(p, i); |
| 82 | p += i + 1; |
| 83 | break; |
| 84 | } |
| 85 | else if( p[i] == ':' || p[i] == '[' || p[i] == ']' ) |
| 86 | { |
no test coverage detected