---------------------------------------------------------------------------
| 71 | } |
| 72 | //--------------------------------------------------------------------------- |
| 73 | void UdpReceiveMessage(void) |
| 74 | { |
| 75 | if( ! udp ) |
| 76 | return; |
| 77 | if( ! udp->IsOpen() ) |
| 78 | return; |
| 79 | |
| 80 | struct sockaddr_in a; |
| 81 | DWORD rl; |
| 82 | while( (rl = udp->ReadLength()) > 0 ) |
| 83 | { |
| 84 | BYTE * ReceiveBuffer = new BYTE[rl + 1]; |
| 85 | if( ! udp->ReadFrom(ReceiveBuffer, rl, (struct sockaddr *)&a) ) |
| 86 | { |
| 87 | if( udp->GetWSAError() == MYERROR_READCOUNT ) |
| 88 | ; // Good error :) In the receive buffer still have UDP packets |
| 89 | else |
| 90 | { |
| 91 | WriteToLogError(String("ERROR\tudp: ") + udp->GetErrorMessageEng()); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | if( udp->bytes > 0 ) |
| 96 | { |
| 97 | // NULL terminate syslog message |
| 98 | ReceiveBuffer[udp->bytes] = 0; |
| 99 | |
| 100 | WriteToLogRawMessage((char *)ReceiveBuffer); |
| 101 | |
| 102 | TSyslogMessage sm; |
| 103 | sm.FromStringSyslogd((char *)ReceiveBuffer, udp->bytes, &a); |
| 104 | |
| 105 | if( ProcessMessageRules(&sm) ) |
| 106 | { |
| 107 | // option is not set: "Ignore (do not save to the default file "syslog")" |
| 108 | TStorageFile * sf = fdb->Get(0); |
| 109 | if( sf ) |
| 110 | if( ! sf->Save( sm.ToString() ) ) |
| 111 | WriteToLogError("ERROR\tSave message to file: %s", sf->GetFileName().c_str()); |
| 112 | } |
| 113 | } |
| 114 | delete [] ReceiveBuffer; |
| 115 | } |
| 116 | } |
| 117 | //--------------------------------------------------------------------------- |
| 118 | #pragma package(smart_init) |
no test coverage detected