123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- #include "stdafx.h"
- #include "bizlog.h"
- #include <memutil.h>
- #include <y2k_time.h>
- typedef struct session_t {
- char *id;
- FILE *fp;
- char file[MAX_PATH];
- }session_t;
- struct bizlog_t
- {
- char base_dir[MAX_PATH];
- session_t *curr_session;
- };
- static void session_destroy(session_t *session)
- {
- if (session) {
- char tmp[MAX_PATH];
- fclose(session->fp);
- session->fp = NULL;
- //strcpy(tmp, session->file);
- //strcat(tmp, ".xml");
- //MoveFileExA(session->file, tmp, MOVEFILE_REPLACE_EXISTING);
- free(session->id);
- free(session);
- }
- }
- bizlog_t *bizlog_create(const char *base_dir)
- {
- bizlog_t *log;
-
- if (!base_dir) {
- return NULL;
- }
- log = ZALLOC_T(bizlog_t);
- strcpy(log->base_dir, base_dir);
- return log;
- }
- void bizlog_destroy(bizlog_t *log)
- {
- if (log) {
- if (log->curr_session) {
- session_destroy(log->curr_session);
- log->curr_session = NULL;
- }
- free(log);
- }
- }
- int bizlog_has_session(bizlog_t *log)
- {
- return !!log->curr_session;
- }
- // <SessionBegin Time="" SessionID=""/>
- int bizlog_session_begin(bizlog_t *log, const char *id,const char*filename)
- {
- session_t *session;
- if (!log || !id)
- return -1;
-
- if (log->curr_session) {
- session_destroy(log->curr_session);
- log->curr_session = NULL;
- }
- session = ZALLOC_T(session_t);
- #ifdef RVC_OS_WIN
- sprintf(session->file, "%s\\%s.xml", log->base_dir, filename);
- #else
- sprintf(session->file, "%s/%s.xml", log->base_dir, filename);
- #endif
- session->fp = fopen(session->file, "wb+");
- if (!session->fp) {
- free(session);
- return -1;
- }
- session->id = _strdup(id);
- y2k_time_t now = y2k_time_now();
- fprintf(session->fp, "<SessionBegin Time=\"0x%08X\" SessionID=\"%s\"/>\r\n", now, id);
- fflush(session->fp);
- log->curr_session = session;
- return 0;
- }
- // <SessionEnd Time="" SessionID=""/>
- int bizlog_session_end(bizlog_t *log)
- {
- if (log->curr_session) {
- y2k_time_t now = y2k_time_now();
- fprintf(log->curr_session->fp, "<SessionEnd Time=\"0x%08X\" SessionID=\"%s\"/>\r\n", now, log->curr_session->id);
- fflush(log->curr_session->fp);
- fclose(log->curr_session->fp);
- log->curr_session->fp = NULL;
- session_destroy(log->curr_session);
- log->curr_session = NULL;
- }
- return 0;
- }
- // <Function Time=”” Display=”” ServiceCode=”” ActionID=”0xAABBCCDD”/>XXX</Function>
- int bizlog_function(bizlog_t *log, const char *name, const char *display_name, const char *product, const char *service_code, int action_id)
- {
- if (!log || !log->curr_session)
- return -1;
- y2k_time_t now = y2k_time_now();
- fprintf(log->curr_session->fp, "<Function Time=\"0x%08X\" Name=\"%s\" Product=\"%s\" Display=\"%s\" ServiceCode=\"%s\" ActionID=\"0x%08X\"/>\r\n", now, name, product, display_name, service_code, action_id);
- fflush(log->curr_session->fp);
- return 0;
- }
- // <CustomerID Time=”” Method=”RI” Level=”5” ActionID=”0xAABBCCDD”>XXX</CustomerID>
- int bizlog_call_id(bizlog_t *log, const char *call_id, const char *skillcode, const char *agent_id, int action_id)
- {
- if (!log || !log->curr_session)
- return -1;
- y2k_time_t now = y2k_time_now();
- fprintf(log->curr_session->fp, "<CallID Time=\"0x%08X\" ID=\"%s\" SkillCode=\"%s\" AgentID=\"%s\" ActionID=\"0x%08X\"/>\r\n", now, call_id, skillcode, agent_id, action_id);
- fflush(log->curr_session->fp);
- return 0;
- }
- // <CustomerID Time=”” Method=”RI” Level=”5” ActionID=”0xAABBCCDD”>XXX</CustomerID>
- int bizlog_customer_id(bizlog_t *log, const char *customer_id, const char *verify_method, int level, int action_id)
- {
- if (!log || !log->curr_session)
- return -1;
- y2k_time_t now = y2k_time_now();
- fprintf(log->curr_session->fp, "<CustomerID Time=\"0x%08X\" ID=\"%s\" Method=\"%s\" Level=\"%d\" ActionID=\"0x%08X\"/>\r\n", now, customer_id, verify_method, level, action_id);
- fflush(log->curr_session->fp);
- return 0;
- }
- // <Agreement Time=”” ActionID=”0xAABBCCDD”>确认要素</Agree>
- int bizlog_agreement(bizlog_t *log, const char *content, int action_id)
- {
- if (!log || !log->curr_session)
- return -1;
- y2k_time_t now = y2k_time_now();
- fprintf(log->curr_session->fp, "<Agreement Time=\"0x%08X\" ActionID=\"0x%08X\">%s</Agreement>\r\n", now, action_id, content);
- fflush(log->curr_session->fp);
- return 0;
- }
- // <Receipt Time=”” ActionID=”0xAABBCCDD” bDone=”1”>结果要素</Receipt>
- int bizlog_receipt(bizlog_t *log, const char *content, int action_id)
- {
- if (!log || !log->curr_session)
- return -1;
- y2k_time_t now = y2k_time_now();
- fprintf(log->curr_session->fp, "<Receipt Time=\"0x%08X\" ActionID=\"0x%08X\">%s</Receipt>\r\n", now, action_id, content);
- fflush(log->curr_session->fp);
- return 0;
- }
- // <Operation Time=”” Code=”” >xxxx</Operation>
- int bizlog_operation(bizlog_t *log, const char *op_code, const char *content, int action_id)
- {
- if (!log || !log->curr_session)
- return -1;
- y2k_time_t now = y2k_time_now();
- fprintf(log->curr_session->fp, "<Operation Time=\"0x%08X\" Code=\"%s\" ActionID=\"0x%08X\">%s</Operation>\r\n", now, op_code, action_id, content);
- fflush(log->curr_session->fp);
- return 0;
- }
- // <Response Time=”” Code=””>xxxx</Response>
- int bizlog_response(bizlog_t *log, const char *ret_code, const char *content, int action_id)
- {
- if (!log || !log->curr_session)
- return -1;
- y2k_time_t now = y2k_time_now();
- fprintf(log->curr_session->fp, "<Response Time=\"0x%08X\" Code=\"%s\" ActionID=\"0x%08X\">%s</Response>\r\n", now, ret_code, action_id, content);
- fflush(log->curr_session->fp);
- return 0;
- }
- // <Agent Time=”” Code=”” ActionID=”0xAABBCCDD”>XXX</Agent>
- int bizlog_agent(bizlog_t *log, const char *op_code, const char *content, int action_id)
- {
- if (!log || !log->curr_session)
- return -1;
- y2k_time_t now = y2k_time_now();
- fprintf(log->curr_session->fp, "<Agent Time=\"0x%08X\" Code=\"%s\" ActionID=\"0x%08X\">%s</Agent>\r\n", now, op_code, action_id, content);
- fflush(log->curr_session->fp);
- return 0;
- }
|