static void auditAlarm(nbCELL context,void *skillHandle,void *nodeHandle,nbCELL cell){ nbAudit *audit=(nbAudit *)nodeHandle; nbCELL value=nbCellGetValue(context,cell); char logbuf[2048],*cursor; long endloc; if(value!=NB_CELL_TRUE) return; // only act when schedule toggles to true if((audit->file=fopen(audit->fileName,"r"))==NULL){ nbLogMsg(context,0,'E',"Log file \"%s\" not found - disabling node.",audit->fileName); auditDisable(context,skillHandle,audit); return; } if((fseek(audit->file,0,SEEK_END))!=0){ nbLogMsg(context,0,'E',"Log file \"%s\" fseek failed errno=%d - disabling node.",audit->fileName,errno); auditDisable(context,skillHandle,audit); return; } endloc=ftell(audit->file); if(endloc==audit->pos){ if(audit->trace) nbLogMsg(context,0,'T',"File \"%s\" has not grown.",audit->fileName); fclose(audit->file); audit->file=NULL; return; } if(endloc<audit->pos){ nbLogMsg(context,0,'I',"File \"%s\" has shrunk from %d to %d, starting at beginning.",audit->fileName,audit->pos,endloc); audit->pos=0; } if((fseek(audit->file,audit->pos,SEEK_SET))!=0){ nbLogMsg(context,0,'E',"File \"%s\" fseek failed errno=%d.",audit->fileName,errno); fclose(audit->file); audit->file=NULL; auditDisable(context,skillHandle,audit); return; } if(audit->trace) nbLogBar(context); while(fgets(logbuf,2048,audit->file)!=NULL){ cursor=strchr(logbuf,'\n'); if(cursor!=NULL) *cursor=0; if(audit->trace) nbLogPut(context,"] %s\n",logbuf); //nbLogPut(context,"] %s\n",logbuf); nbTranslatorExecute(context,audit->translatorCell,logbuf); if(audit->file==NULL){ nbLogMsg(context,0,'W',"Node disabled during file processing"); return; } } if(audit->trace) nbLogBar(context); audit->pos=ftell(audit->file); if(audit->trace) nbLogMsg(context,0,'T',"File size=%u",audit->pos); fclose(audit->file); audit->file=NULL; }
/* * Read incoming packets */ void serverRead(nbCELL context,int serverSocket,void *handle){ NB_MOD_Server *server=handle; char buffer[NB_BUFSIZE]; size_t buflen=NB_BUFSIZE; int len; unsigned short rport; char daddr[40],raddr[40]; nbIpGetSocketAddrString(serverSocket,daddr); len=nbIpGetDatagram(context,serverSocket,&server->sourceAddr,&rport,(unsigned char *)buffer,buflen); while(len<0 && errno==EINTR) len=nbIpGetDatagram(context,serverSocket,&server->sourceAddr,&rport,(unsigned char *)buffer,buflen); if(len<0) return; // 2012-12-18 eat - CID 751566 if(server->trace) nbLogMsg(context,0,'I',"Datagram %s:%5.5u -> %s len=%d",nbIpGetAddrString(raddr,server->sourceAddr),rport,daddr,len); if(server->dump) nbLogDump(context,buffer,len); *(buffer+len)=0; // make sure we have a null terminator nbTranslatorExecute(context,server->translator,buffer); }