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

📄 uaprofcomm.c

📁 移动流媒体同步服务器模块
💻 C
字号:
/********************************************************************
Copyright(C), 2006, Wuhan Hongxu Information Technologies Co., Ltd.
Filename   : uaprofComm.c
Description: uaprof comm program.
Author     : LiWeiBing
Version    : Initial version
Date       : 2006年12月
History    :
<author>     <time>     <version >     <desc>
********************************************************************/
#include <sys/varargs.h>
#include "uaprof.h"
#include "msspDefs.h"
#include "msspUtilReadConf.h"

extern int gLogLevel;
extern FILE * gUaprofPrintFP;

/**********************************************************
Function   : uaprofReadConf
Description: 读配置文件
Input      : 
Output     : 
Return     : MSSP_FAILURE表示失败
**********************************************************/
int uaprofReadConf(UaprofConfSt * pConfData)
{
    char    caFileText[5000];

    memset(caFileText, 0, 5000);
    
    if(MSSP_FAILURE == Get_Conf_String(CONF_FILE_NAME, UAPROF_BEGIN, UAPROF_END, caFileText, 5000))
    {
        printf("uaprofReadConf (Get_Conf_String fail)\n");
        return(MSSP_FAILURE);
    }

    /*读取整形数据*/
    if(MSSP_FAILURE == Load_Int_ConfigValue(caFileText, 5000, "listen_port:", &(pConfData->iListenPort)))
    {
        printf("uaprofReadConf:Load_Int_ConfigValue  listen rds port fail!\n");
        return(MSSP_FAILURE);
    }

    if(MSSP_FAILURE == Load_Int_ConfigValue(caFileText, 5000, "http_port:", &(pConfData->iHttpPort)))
    {
        printf("uaprofReadConf:Load_Int_ConfigValue  ismp port fail!\n");
        return(MSSP_FAILURE);
    }

    if(MSSP_FAILURE == Load_Int_ConfigValue(caFileText, 5000, "ftp_port:", &(pConfData->iFtpPort)))
    {
        printf("uaprofReadConf:Load_Int_ConfigValue  ftp port fail!\n");
        return(MSSP_FAILURE);
    }

    if(MSSP_FAILURE == Load_Int_ConfigValue(caFileText, 5000, "data_base_port:", &(pConfData->iDataBasePort)))
    {
        printf("uaprofReadConf:Load_Int_ConfigValue  data base port fail!\n");
        return(MSSP_FAILURE);
    }

    if(MSSP_FAILURE == Load_Int_ConfigValue(caFileText, 5000, "log_level:", &(pConfData->iLogLevel)))
    {
        printf("uaprofReadConf:Load_Int_ConfigValue  log level fail!\n");
        return(MSSP_FAILURE);
    }

    if(MSSP_FAILURE == Load_Int_ConfigValue(caFileText, 5000, "print_to_file:", &(pConfData->iPrintFile)))
    {
        printf("uaprofReadConf:Load_Int_ConfigValue  print file flag fail!\n");
        return(MSSP_FAILURE);
    }


    /*读取字符串型*/
    if(MSSP_FAILURE == Load_Str_ConfigValue(caFileText, 5000, "uaprof_ip:", pConfData->caUaprofIp, 16))
    {
        printf("rdsReadConf get uaprof ip fail\n");
        return(MSSP_FAILURE);
    }

    if(MSSP_FAILURE == Load_Str_ConfigValue(caFileText, 5000, "host_ip:", pConfData->caHostIp, 16))
    {
        printf("rdsReadConf get ismp ip fail\n");
        return(MSSP_FAILURE);
    }

    if(MSSP_FAILURE == Load_Str_ConfigValue(caFileText, 5000, "data_base_ip:", pConfData->caDataBaseIp, 16))
    {
        printf("rdsReadConf get uaprof ip fail\n");
        return(MSSP_FAILURE);
    }

    if(MSSP_FAILURE == Load_Str_ConfigValue(caFileText, 5000, "user_name:", pConfData->caUserName, 16))
    {
        printf("rdsReadConf get user name fail\n");
        return(MSSP_FAILURE);
    }

    if(MSSP_FAILURE == Load_Str_ConfigValue(caFileText, 5000, "passwd:", pConfData->caPassWd, 16))
    {
        printf("rdsReadConf get passwd fail\n");
        return(MSSP_FAILURE);
    }

    if(MSSP_FAILURE == Load_Str_ConfigValue(caFileText, 5000, "local_path:", pConfData->caLocalPath, 64))
    {
        printf("rdsReadConf get local path fail\n");
        return(MSSP_FAILURE);
    }

    if(MSSP_FAILURE == Load_Str_ConfigValue(caFileText, 5000, "content_path:", pConfData->caContentPath, 16))
    {
        printf("rdsReadConf get content path fail\n");
        return(MSSP_FAILURE);
    }

    return(MSSP_SUCCESS);
}


/**********************************************************
Function   : ConnectToServer
Description: 作为客户端向服务端建TCP连接
Input      : ip:服务端IP地址 port:服务端监听端口
Output     : SOCKET 句柄iFd
Return     : -1表示失败
**********************************************************/
int ConnectToServer(char *ip, int port)
{
    int iFd;
    struct sockaddr_in my_addr;

    if( !ip || port <= 0 )
    {
        printf("ConnectToServer invalid input\n");
        return(-1);
    }

    if ((iFd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
    {
        printf("ConnectToServer socket fail!\n");
        return(-1);
    }

    my_addr.sin_family = AF_INET;
    my_addr.sin_port = htons(port);
    my_addr.sin_addr.s_addr = inet_addr(ip);

    if (connect(iFd,(struct sockaddr *)&my_addr,sizeof(my_addr))== -1)
    {
        printf("ConnectToServer connect fail!ip=%s, port=%d\n",ip, port);
        return(-1);
    }

    return(iFd);
}

int InsertUaprofDB(char *ip, int port, pss_uaprof_t *uaprof)
{
    uaprof_database_insert_req_t InsertMsg;
    int fd;

    fd = ConnectToServer(ip, port);
    if( fd < 0 )
    {
        printf("connect to db fail!\n");
        return(MSSP_FAILURE);
    }

    memset(&InsertMsg, 0, sizeof(uaprof_database_insert_req_t));
    InsertMsg.msgHead.moduleType = STREAM_DB_MODULE_TYPE_UAPROF;
    InsertMsg.msgHead.msgLength = sizeof(uaprof_database_insert_req_t);
    InsertMsg.msgHead.msgType = UAPROF_DATABASE_INSERT_REQ;
    memcpy(&(InsertMsg.uaprof), uaprof, sizeof(pss_uaprof_t));

    send(fd, &InsertMsg, InsertMsg.msgHead.msgLength, 0);
    UAPROF_LOG(TRACE, "send insertmsg to db ok!\n");
    sleep(1);
    close(fd);
    return(MSSP_SUCCESS);
}


/**********************************************************
Function   : UAPROF_LOG
Description:记LOG的函数
Input      : iErrCode可取ERR、WARN、TRACE,分别表示错误信息、警告信息、调试信息
Output     : 
Return     : 
**********************************************************/
void UAPROF_LOG(int iErrCode, const char *format, ...)
{
    va_list A;
    long lTLoc;
    long lCurTime;
    
    if (!format) return;

    if(iErrCode < gLogLevel)
    {
        return;   
    }

    if( NULL != gUaprofPrintFP )
    {
        (lCurTime) = time(&lTLoc); 
        fprintf(gUaprofPrintFP,"@[%d]%ld|%.24s ",iErrCode,getpid(),ctime(&lCurTime));
        va_start( A, format );
        (void)vfprintf( gUaprofPrintFP, format, A );
        fflush(gUaprofPrintFP);
        va_end( A );
    }
}


⌨️ 快捷键说明

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