⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msg.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************
        Copyright (c) 2002 RADVISION Ltd.
************************************************************************
NOTICE:
This document contains information that is confidential and proprietary
to RADVISION Ltd.. No part of this document may be reproduced in any
form whatsoever without written prior approval by RADVISION Ltd..

RADVISION Ltd. reserve the right to revise this publication and make
changes without obligation to notify any person of such revisions or
changes.
***********************************************************************/

#include "rvinternal.h"
#include <stdlib.h>

#include "rvstdio.h"
#include "rvloglistener.h"
#include "rvclock.h"
#include "rvtm.h"
#include "strutils.h"
#include "msg.h"


#if (RV_LOGMASK_COMPILEMASK)

#ifdef __cplusplus
extern "C" {
#endif


#define CONF_FILE  "rvtele.ini"
#define LOG_FILE   "rvtsp.log"

static void (*stackNotify)(IN char *line,...) = NULL;

static char msConfFileName[128] = CONF_FILE; /* configuration file name */
static char msLogFileName[128]  = "";  /* log file name */

static int msgDebugLevel = -1;
static int fileSize = -1;
static int numOfFiles = -1;
static int flushFile = -1;

static RvLogListener fileListener;
static RvBool logfiled = RV_FALSE;

static RvLogListener termListener;
static RvBool logtermed = RV_FALSE;

static RvLogListener debListener;
static RvBool logdebed = RV_FALSE;

/* Indication if the application has a listener set */
static RvBool applicationListenerOn = RV_FALSE;

static msCalls = 0;


/************************** Assisting Functions **************************/

static int parseSupservLine(
    IN  char line[],
    OUT char ** param,
    OUT char ** value
)
{
    int cToInd=0, cFromInd=0;

    *param = *value = NULL;

    while(line[cFromInd] != '\0')
    {
        if((isspace((int) line[cFromInd])) || (line[cFromInd] == '='))
        {
            cFromInd++;
            continue;
        }
        if(*param == NULL)
        {
            /* found the param. we start copying the param to the beginning of the line,
            ending with '\0' */
            *param = &line[cToInd];

            while((line[cFromInd] != '\0') && !(isspace((int) line[cFromInd])) && (line[cFromInd] != '='))
            {
                line[cToInd] = (char) tolower((int) line[cFromInd]);
                cToInd++;
                cFromInd++;
            }
            if(line[cFromInd] != '\0') cFromInd++;
            line[cToInd] = '\0';
            cToInd++;
        }
        else if(*value == NULL)
        {
            /* found the value. we start copying the param to the beginning of the line,
            ending with '\0' */
            *value = &line[cToInd];

            while(!(isspace((int) line[cFromInd])))
            {
                line[cToInd] = line[cFromInd];
                cToInd++;
                cFromInd++;
            }
            line[cToInd] = '\0';
            break;
        }
    }
    if((*param == NULL) || (*value == NULL))
    {
        return RV_ERROR_UNKNOWN;
    }
    return RV_OK;
}


static char * lowerString(char * string)
{
    int ind;
    for(ind=0; string[ind] != '\0'; ind++)
        string[ind] = (char)tolower((int) string[ind]);
    return string;
}


static int parseInsertLine(
    IN  char line[],
    OUT char ** logName,
    OUT RvLogMessageType * logMask
)
{
    int cToInd=0, cFromInd=0;

    *logMask = 0;
    *logName = NULL;

    while(line[cFromInd] != '\0')
    {
        if((isspace((int) line[cFromInd])) || (line[cFromInd] == '='))
        {
            cFromInd++;
            continue;
        }
        if(*logName == NULL)
        {
            /* found the log name. we start copying the param to the beginning of the line,
            ending with '\0' */
            *logName = &line[cToInd];

            while((line[cFromInd] != '\0') && !(isspace((int) line[cFromInd])) && (line[cFromInd] != '='))
            {
                cToInd++;
                cFromInd++;
            }
            if(line[cFromInd] != '\0')
                cFromInd++;
            line[cToInd] = '\0';
            cToInd++;
            if (line[cToInd] == '\0')
                *logMask = RV_LOGLEVEL_ALL; /* Log everything. User stated only the name */
        }
        else
        {
            /* we add each log filter to the mask */
            if(line[cFromInd] == '0')
            {
                *logMask = (RvLogMessageType) 0;
                return RV_OK;
            }
            if ((isdigit(line[cFromInd]) && (line[cFromInd] != '0')) ||
                (line[cFromInd] == '*'))
            {
                *logMask = RV_LOGLEVEL_ALL;
                return RV_OK;
            }
            if(!strncmp_ci(&line[cFromInd], "EXCEP", 5))
            {
                *logMask |= RV_LOGLEVEL_EXCEP;
                cFromInd += 5;
                continue;
            }
            if(!strncmp_ci(&line[cFromInd], "ERROR", 5))
            {
                *logMask |= RV_LOGLEVEL_ERROR;
                cFromInd += 5;
                continue;
            }
            if(!strncmp_ci(&line[cFromInd], "WARN", 7))
            {
                *logMask |= RV_LOGLEVEL_WARNING;
                cFromInd += 7;
                continue;
            }
            if(!strncmp_ci(&line[cFromInd], "INFO", 4))
            {
                *logMask |= RV_LOGLEVEL_INFO;
                cFromInd += 4;
                continue;
            }
            if(!strncmp_ci(&line[cFromInd], "DEBUG", 5))
            {
                *logMask |= RV_LOGLEVEL_DEBUG;
                cFromInd += 5;
                continue;
            }
            if(!strncmp_ci(&line[cFromInd], "ENTER", 5))
            {
                *logMask |= RV_LOGLEVEL_ENTER;
                cFromInd += 5;
                continue;
            }
            if(!strncmp_ci(&line[cFromInd], "LEAVE", 5))
            {
                *logMask |= RV_LOGLEVEL_LEAVE;
                cFromInd += 5;
                continue;
            }
            /* didn't match anything - skip this word */
            while((line[cFromInd] != '\0') && !(isspace((int) line[cFromInd])))
                cFromInd++;
        }
    }
    if(*logName == NULL)
    {
        return RV_ERROR_UNKNOWN;
    }
    return RV_OK;
}


/************************** Read File Functions **************************/

RvBool rvteleSepserv(FILE** fdp, char line[]);
RvBool rvteleInsertIntoLog(FILE** fdp, char line[]);


/* Open log configuration parse it and start the listeners */
RVAPI void RVCALLCONV msOpen(void)
{
    FILE *fd = NULL;
    char line[200];

    msCalls++;

    if (msCalls <= 1)
        /* initialization */
    {
        RvLogSetGlobalMask(RvLogGet(), 0);
    }

    if (msConfFileName[0])
    {
        fd = RvFopen(msConfFileName, "r");
#if (RV_OS_TYPE == RV_OS_TYPE_WIN32)
        if(fd == NULL)
        {
            char winPath[64];
            char fullPath[128];

            GetWindowsDirectory(winPath, 64);
            RvSprintf(fullPath, "%s\\%s", winPath, msConfFileName);
            fd = RvFopen(fullPath, "r");
        }
#endif
    }

    if(fd != NULL)
    {
        while (fgets(line, 200, fd))
        {
            if (strlen(line) < 2) continue; /* ignore empty lines */

            if (line[0] == '#') continue; /* ignore remarks */

            if (line[0] == '[')
            {
                RvBool retry;

                line[strlen(line)-1] = 0; /* remove \n */

                do
                {
                    retry = RV_FALSE;

                    if(!strcmp(line, "[supserve]"))
                    {
                        retry = rvteleSepserv(&fd, line);
                    }

                    if(!strcmp(line, "[insertIntoLog]"))
                    {
                        retry = rvteleInsertIntoLog(&fd, line);
                    }

                    if(!strcmp(line, "[insertIntoFile]"))
                    {
                        retry = rvteleInsertIntoLog(&fd, line);
                    }
                } while(retry);
            }
        }
        RvFclose(fd);
    }
}


/* Close log listeners */
RVAPI void RVCALLCONV msClose(void)
{
    msCalls--;
    if (msCalls>0) return;

    if(logfiled)
    {
        RvLogListenerDestructLogfile(&fileListener);
        logfiled = RV_FALSE;
    }
    if(logtermed)
    {
        RvLogListenerDestructTerminal(&termListener);
        logtermed = RV_FALSE;
    }
    if(logdebed)
    {
        RvLogListenerDestructDebug(&debListener);
        logdebed = RV_FALSE;
    }
}


RvBool rvteleSepserv(FILE** fdp, char line[])
{
    char *param, *value;
    RvBool useFile=RV_FALSE, useTerm=RV_FALSE, useDeb=RV_FALSE;
    RvBool newHeader = RV_FALSE;

    while(fgets(line, 200, *fdp))
    {
        if(strlen(line) < 2) continue; /* ignore empty lines */

        if(line[0] == '#') continue; /* ignore remarks */

        if(line[0] == '[')
        {
            line[strlen(line)-1] = 0; /* remove \n */
            newHeader = RV_TRUE;
            break; /* exit on new header */
        }

        if(parseSupservLine(line, &param, &value) != RV_OK)
            continue;

        if(!strcmp(param, "deblevel"))
        {
            /* set debug level */
            if(msgDebugLevel == -1)
                msgDebugLevel = atoi(value);
            continue;
        }

        if(!strcmp(param, "msgterm"))
        {
            if((!strcmp(lowerString(value), "on")) || (atoi(value) > 0))
            {
                /* create window listerner */
                useTerm = RV_TRUE;
                continue;
            }
        }

        if(!strcmp(param, "msgfile"))
        {
            if((!strcmp(lowerString(value), "on")) || (atoi(value) > 0))
            {
                /* create file listerner */
                useFile = RV_TRUE;
                continue;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -