📄 ospaudit.c
字号:
OSPC_COMM_TEXT_MSG, strlen(OSPC_COMM_TEXT_MSG)); } } /* set the audit flag */ msginfo->Flags = (unsigned char)(msginfo->Flags | OSPC_MSGINFO_AUDIT_TYPE); } else { /* msginfo isn't here */ errorcode = OSPC_ERR_AUDIT_NOT_FOUND; } } /* end if errorcode = OSPC_ERR_NO_ERROR after mimemessagecreate */ if (errorcode == OSPC_ERR_NO_ERROR) { OSPPMsgInfoAssignRequestMsg(msginfo, outgoingmessage, sizeofoutmsg); errorcode = OSPPCommAddTransaction(ospvAudit->ospmAuditComm, msginfo); if (errorcode == OSPC_ERR_NO_ERROR) { errorcode = msginfo->ErrorCode; } if (errorcode == OSPC_ERR_NO_ERROR) { errorcode = OSPPAuditProcessReturn(ospvAudit, msginfo); } } } /* end if errorcode == OSPC_ERR_NO_ERROR before mimemessagecreate */ } /* end if auditbuffersz > 0 */ } /* end if security and storage != OSPC_OSNULL */ } /* end if ospvAudit != OSPC_OSNULL */ if (signature != (unsigned char *)OSPC_OSNULL) { OSPM_FREE(signature); signature = OSPC_OSNULL; } if(msginfo != OSPC_OSNULL) { OSPPMsgInfoDelete(&msginfo); } return errorcode;}/* Process return from server */intOSPPAuditProcessReturn( OSPTAUDIT *ospvAudit, OSPTMSGINFO *ospvMsgInfo){ int errorcode = OSPC_ERR_NO_ERROR; unsigned char *incomingmsg = OSPC_OSNULL; unsigned char *incomingsignature = OSPC_OSNULL; unsigned sizeofmsg = 0; unsigned sizeofsig = 0; void *resultrsp = OSPC_OSNULL; OSPE_MSG_DATATYPES msgtype = OSPC_MSG_LOWER_BOUND; OSPTUSAGECNF *usagecnf = (OSPTUSAGECNF *)OSPC_OSNULL; if(ospvMsgInfo != OSPC_OSNULL) { errorcode = OSPPMimeMessageParse( ospvMsgInfo->ResponseMsg, ospvMsgInfo->ResponseSz, ospvMsgInfo->ContentType, ospvMsgInfo->ContentSz, &incomingmsg, &sizeofmsg, &incomingsignature, &sizeofsig); } else { errorcode = OSPC_ERR_AUDIT_NOT_FOUND; }#ifdef ENABLESMIME /* * Validate the S/MIME signature */ if (errorcode == OSPC_ERR_NO_ERROR) { if((incomingsignature != OSPC_OSNULL) && (ospvAudit->ospmAuditSecurity != OSPC_OSNULL)) { errorcode = OSPPSecSignatureVerify( ospvAudit->ospmAuditSecurity, &incomingmsg, &sizeofmsg, incomingsignature, sizeofsig, OSPC_SEC_SIGNATURE_ONLY); } else { errorcode = OSPC_ERR_AUDIT_NOT_FOUND; } }#endif if (errorcode == OSPC_ERR_NO_ERROR) { /* * Send the XML message doc to the XML parser */ errorcode = OSPPXMLMessageParse(incomingmsg, sizeofmsg, &resultrsp, &msgtype); if (errorcode == OSPC_ERR_NO_ERROR) { switch (msgtype) { /* * Authorization Response received */ case OSPC_MSG_ARESP: break; /* * Usage Confirmation received */ case OSPC_MSG_UCNF: for((usagecnf = (OSPTUSAGECNF *)OSPPListFirst((OSPTLIST *)&(resultrsp))); (usagecnf != OSPC_OSNULL); (usagecnf = (OSPTUSAGECNF *)OSPPListNext((OSPTLIST *)&(resultrsp), usagecnf))) { OSPPAuditVerifyUsageCnf(usagecnf, ospvAudit); } while(!OSPPListEmpty((OSPTLIST*)&resultrsp)) { usagecnf = (OSPTUSAGECNF *)OSPPListRemove((OSPTLIST*)&resultrsp); if(usagecnf != OSPC_OSNULL) { OSPPUsageCnfDelete(&usagecnf); } } OSPPListDelete((OSPTLIST*)&resultrsp); break; /* * Authorization Confirmation received */ case OSPC_MSG_ACNF: break; /* * Reauthorization Response received */ case OSPC_MSG_REARESP: break; /* * The Unknown received */ default: errorcode = OSPC_ERR_DATA_INVALID_TYPE; break; } } } if (incomingmsg != (unsigned char *)OSPC_OSNULL) { OSPM_FREE(incomingmsg); incomingmsg = OSPC_OSNULL; } if (incomingsignature != (unsigned char *)OSPC_OSNULL) { OSPM_FREE(incomingsignature); incomingsignature = OSPC_OSNULL; } return errorcode;}/* Subtract Usage Indications from the buffer according to the component ID */voidOSPPAuditRemoveComponentIdFromList( unsigned char *ospvCompid, OSPTAUDIT *ospvAudit){ OSPTCOMPONENTID *compid = (OSPTCOMPONENTID *)OSPC_OSNULL; for(compid = (OSPTCOMPONENTID *)OSPPListFirst(&(ospvAudit->ospmAuditComponentIdList)); (compid != OSPC_OSNULL); compid = (OSPTCOMPONENTID *)OSPPListNext(&(ospvAudit->ospmAuditComponentIdList), compid)) { if(compid != OSPC_OSNULL) { if(compid->ospmComponentId != OSPC_OSNULL) { if(OSPM_STRCMP((const char *)(compid->ospmComponentId), (const char *)ospvCompid) == 0) { ospvAudit->ospmAuditNumMessages--; break; } } } } return;}/* Reset audit values to current defaults */int OSPPAuditResetDefaults( OSPTAUDIT *ospvAudit){ int errorcode = OSPC_ERR_NO_ERROR; if(ospvAudit != OSPC_OSNULL) {/* OSPM_MUTEX_LOCK(ospvAudit->ospmAuditAccessMutex, errorcode);*/ if(errorcode == OSPC_ERR_NO_ERROR) { OSPPBfrClear(ospvAudit->ospmAuditStorage); /* not sure if we want to worry about an error here MOC*//* OSPM_MUTEX_UNLOCK(ospvAudit->ospmAuditAccessMutex, errorcode);*/ } OSPPAuditSetStartTime(ospvAudit, 0); OSPPAuditSetNumMessages(ospvAudit, 0); OSPPAuditSetUsedSpace(ospvAudit, 0); OSPPAuditSetMaxMessages(ospvAudit, OSPC_AUDIT_MAX_MESSAGES); OSPPAuditSetMaxSpace(ospvAudit, OSPC_AUDIT_MAX_SPACE - (OSPC_AUDIT_BFR_END_LEN + 1)); OSPPAuditSetMaxTime(ospvAudit, OSPC_AUDIT_MAX_TIME); OSPPAuditInitializeBuffer(ospvAudit); ospvAudit->ospmAuditFlags = (unsigned char)(ospvAudit->ospmAuditFlags & OSPC_AUDIT_BUFFER_CLEAR_FLAGS); } return errorcode;}/* Set the audit comm pointer for sending data */void OSPPAuditSetComm( OSPTAUDIT *ospvAudit, OSPTCOMM *ospvComm){ if(ospvAudit != OSPC_OSNULL) { if(ospvComm != OSPC_OSNULL) { ospvAudit->ospmAuditComm = ospvComm; } } return;}void OSPPAuditSetMaxMessages( OSPTAUDIT *ospvAudit, unsigned ospvNumMessages){ if(ospvAudit != OSPC_OSNULL) { ospvAudit->ospmAuditMaxMessages = ospvNumMessages; } return;}void OSPPAuditSetMaxSpace( OSPTAUDIT *ospvAudit, unsigned ospvMaxSpace){ if(ospvAudit != OSPC_OSNULL) { ospvAudit->ospmAuditMaxSpace = ospvMaxSpace; } return;}void OSPPAuditSetMaxTime( OSPTAUDIT *ospvAudit, unsigned ospvMaxTime){ if(ospvAudit != OSPC_OSNULL) { ospvAudit->ospmAuditMaxTime = ospvMaxTime; } return;}void OSPPAuditSetNumMessages( OSPTAUDIT *ospvAudit, unsigned ospvNumMsgs){ if(ospvAudit != OSPC_OSNULL) { ospvAudit->ospmAuditNumMessages = ospvNumMsgs; } return;}/* Set the audit security pointer for signing */void OSPPAuditSetSecurity( OSPTAUDIT *ospvAudit, OSPTSEC *ospvSecurity){ if(ospvAudit != OSPC_OSNULL) { if(ospvSecurity != OSPC_OSNULL) { ospvAudit->ospmAuditSecurity = ospvSecurity; } } return;}/* Set the start time for collecting data */void OSPPAuditSetStartTime( OSPTAUDIT *ospvAudit, unsigned long ospvTime){ if(ospvAudit != OSPC_OSNULL) { ospvAudit->ospmAuditStartTime = ospvTime; } return;}/* Set the URL for audit purposes */void OSPPAuditSetURL( OSPTAUDIT *ospvAudit, const char *ospvAuditURL){ if(ospvAudit != OSPC_OSNULL) { if(ospvAuditURL != (const char *)OSPC_OSNULL) { if(ospvAudit->ospmAuditURL != OSPC_OSNULL) { OSPM_FREE(ospvAudit->ospmAuditURL); } OSPM_MALLOC(ospvAudit->ospmAuditURL, char, strlen(ospvAuditURL)+1); if(ospvAudit->ospmAuditURL != OSPC_OSNULL) { OSPM_MEMCPY(ospvAudit->ospmAuditURL, ospvAuditURL, strlen(ospvAuditURL)+1); } } } return;}void OSPPAuditSetUsedSpace( OSPTAUDIT *ospvAudit, unsigned ospvUsedSpace){ if(ospvAudit != OSPC_OSNULL) { ospvAudit->ospmAuditUsedSpace = ospvUsedSpace; } return;}/* Start the worker thread to wait for favorable conditions to send audit */int OSPPAuditStartWorker( OSPTAUDIT *ospvAudit){ int errorcode = OSPC_ERR_NO_ERROR; OSPTTHRATTR thread_attr; if(ospvAudit == OSPC_OSNULL) { errorcode = OSPC_ERR_AUDIT_NOT_FOUND; } else { OSPM_THRATTR_INIT(thread_attr, errorcode); if(errorcode == OSPC_ERR_NO_ERROR) { OSPM_SETDETACHED_STATE(thread_attr, errorcode); if (errorcode == OSPC_ERR_NO_ERROR) { /* * create the new thread which will monitor * the access buffer flag in order to send data */ OSPM_CREATE_THREAD(ospvAudit->ospmAuditThreadId, &thread_attr, OSPPAuditMonitor, ospvAudit, errorcode); } OSPM_THRATTR_DESTROY(thread_attr); } if (errorcode != OSPC_ERR_NO_ERROR) { errorcode = OSPC_ERR_AUDIT_THREAD_INIT_FAILED; OSPM_DBGERRORLOG(errorcode, "thread initialization failed"); } } return errorcode;}voidOSPPAuditVerifyUsageCnf( OSPTUSAGECNF *ospvUsageCnf, OSPTAUDIT *ospvAudit){ /* Get the component Id from the Usage Confirm, * remove the associated Usage Indication from the * storage buffer. */ unsigned char *compid = OSPC_OSNULL; if (OSPPUsageCnfHasComponentId(ospvUsageCnf)) { compid = OSPPUsageCnfGetComponentId(ospvUsageCnf); OSPPAuditRemoveComponentIdFromList(compid, ospvAudit); } return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -