inet_msg_pack.c

来自「最新MTK手机软件源码」· C语言 代码 · 共 1,737 行 · 第 1/5 页

C
1,737
字号
                CHECK_INET_PACK_ENBUF(l) size += l;
            }
        }
        addr_list = addr_list->next;
        if (addr_list && addr_list->object &&
            (addr_list->object->display_name || addr_list->object->uri || addr_list->object->param_list))
        {
            l = _snprintf(buf + size, buf_len - size, ", ");
            CHECK_INET_PACK_ENBUF(l) size += l;
        }

    }

    *r_size = size;
    return INET_RESULT_OK;

}   /* end of inet_msg_pack_addr_list */


/*****************************************************************************
 * FUNCTION
 *  inet_msg_pack_date_string
 * DESCRIPTION
 *  This function packs the date header value.
 * PARAMETERS
 *  app_type        [IN]            application type
 *  arg             [IN]            pointer of header value
 *  buf             [IN]            buffer to store packed header value
 *  buf_len         [IN]            available data size of buffer
 *  r_size          [IN/OUT]        real data size to pack
 * RETURNS
 *  INET result code
 *****************************************************************************/
inet_result_enum inet_msg_pack_date_string(
                    kal_uint8 app_type,
                    void *arg,
                    kal_char *buf,
                    kal_int32 buf_len,
                    kal_int32 *r_size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint32 gmt_time = (kal_uint32) arg;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    CHECK_INET_PARAM(arg, INET_RESULT_ERROR);

    if (buf_len < 31)
    {
        return INET_RESULT_NO_ENBUF;
    }
    kal_mem_set(buf, 0, buf_len);

    if (applib_dt_time2rfc1123dateString(gmt_time, buf) == KAL_TRUE)
    {
        *r_size = strlen(buf);
        return INET_RESULT_OK;
    }
    else
    {
        return INET_RESULT_MSG_PACK_ERROR;
    }
}


/*****************************************************************************
 * FUNCTION
 *  inet_msg_pack_uri
 * DESCRIPTION
 *  This function packs the inet_uri_struct header value.
 * PARAMETERS
 *  app_type        [IN]            application type
 *  arg             [IN]            pointer of header value
 *  buf             [IN]            buffer to store packed header value
 *  buf_len         [IN]            available data size of buffer
 *  r_size          [IN/OUT]        real data size to pack
 * RETURNS
 *  INET result code
 *****************************************************************************/
/* sip:172.21.120.203:5070 */
inet_result_enum inet_msg_pack_uri(kal_uint8 app_type, void *arg, kal_char *buf, kal_int32 buf_len, kal_int32 *r_size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    inet_uri_struct *uri = (inet_uri_struct*) arg;
    kal_int32 l = 0, m;
    inet_result_enum ret;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    CHECK_INET_PARAM(arg, INET_RESULT_ERROR) if (uri->host != NULL && !strcmp(uri->host, "*"))
    {
        m = _snprintf(buf, buf_len, "*");
        CHECK_INET_PACK_ENBUF(m) l = m;
    }
    else
    {
        if (uri->scheme != INET_URI_SCHEME_UNRECOGNIZED && uri->scheme < INET_URI_SCHEME_NUM)
        {
            m = _snprintf(buf, buf_len, "%s:", inet_uri_table[uri->scheme]);
            CHECK_INET_PACK_ENBUF(m) l += m;
        }
        if (uri->scheme == INET_URI_SCHEME_HTTP || uri->scheme == INET_URI_SCHEME_HTTPS)
        {
            m = _snprintf(buf + l, buf_len - l, "%s", "//");
            CHECK_INET_PACK_ENBUF(m) l += m;
        }
        if (uri->host != NULL)
        {
            m = _snprintf(buf + l, buf_len - l, "%s", uri->host);
            CHECK_INET_PACK_ENBUF(m) l += m;
        }
        if (uri->port != 0)
        {
            m = _snprintf(buf + l, buf_len - l, ":%d", uri->port);
            CHECK_INET_PACK_ENBUF(m) l += m;
        }
        if (uri->path != NULL)
        {
            m = _snprintf(buf + l, buf_len - l, "%s", uri->path);
            CHECK_INET_PACK_ENBUF(m) l += m;
        }
    }
    if (uri->param_list)
    {
        if ((ret = inet_msg_pack_param_list(app_type, (void*)uri->param_list, buf + l, buf_len - l, &m)) != INET_RESULT_OK)
        {
            return ret;
        }
        CHECK_INET_PACK_ENBUF(m) l += m;
    }

    *r_size = l;
    return INET_RESULT_OK;

}   /* end of inet_msg_pack_uri */


/*****************************************************************************
 * FUNCTION
 *  inet_msg_pack_param_list
 * DESCRIPTION
 *  This function packs the inet_param_list_struct header value.
 * PARAMETERS
 *  app_type        [IN]            application type
 *  arg             [IN]            pointer of header value
 *  buf             [IN]            buffer to store packed header value
 *  buf_len         [IN]            available data size of buffer
 *  r_size          [IN/OUT]        real data size to pack
 * RETURNS
 *  INET result code
 *****************************************************************************/
inet_result_enum inet_msg_pack_param_list(
                    kal_uint8 app_type,
                    void *arg,
                    kal_char *buf,
                    kal_int32 buf_len,
                    kal_int32 *r_size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    inet_param_list_struct *param_list = (inet_param_list_struct*) arg;

    kal_int32 size = 0; /* used bytes */
    kal_int32 l;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    CHECK_INET_PARAM(arg, INET_RESULT_ERROR) while (param_list)
    {
        if (param_list->object)
        {
            if (param_list->object->name)
            {
                l = _snprintf(buf + size, buf_len - size, ";");
                CHECK_INET_PACK_ENBUF(l) size += l;

                l = _snprintf(buf + size, buf_len - size, "%s", param_list->object->name);
                CHECK_INET_PACK_ENBUF(l) size += l;
            }

            if (param_list->object->value)
            {
                l = _snprintf(buf + size, buf_len - size, "=%s", param_list->object->value);
                CHECK_INET_PACK_ENBUF(l) size += l;
            }
        }
        param_list = param_list->next;
    }   /* for */
    *r_size = size;
    return INET_RESULT_OK;
}


/*****************************************************************************
 * FUNCTION
 *  inet_msg_pack_integer
 * DESCRIPTION
 *  This function packs the  int header value.
 * PARAMETERS
 *  app_type        [IN]            application type
 *  arg             [IN]            pointer of header value
 *  buf             [IN]            buffer to store packed header value
 *  buf_len         [IN]            available data size of buffer
 *  r_size          [IN/OUT]        real data size to pack
 * RETURNS
 *  INET result code
 *****************************************************************************/
inet_result_enum inet_msg_pack_integer(
                    kal_uint8 app_type,
                    void *arg,
                    kal_char *buf,
                    kal_int32 buf_len,
                    kal_int32 *r_size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    kal_int32 l;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    l = _snprintf(buf, buf_len, "%d", (kal_int32) arg);
    CHECK_INET_PACK_ENBUF(l) * r_size = l;
    return INET_RESULT_OK;

}   /* end of inet_msg_pack_integer */


/*****************************************************************************
 * FUNCTION
 *  inet_msg_pack_string
 * DESCRIPTION
 *  This function packs the  string header value.
 * PARAMETERS
 *  app_type        [IN]            application type
 *  arg             [IN]            pointer of header value
 *  buf             [IN]            buffer to store packed header value
 *  buf_len         [IN]            available data size of buffer
 *  r_size          [IN/OUT]        real data size to pack
 * RETURNS
 *  INET result code
 *****************************************************************************/
inet_result_enum inet_msg_pack_string(
                    kal_uint8 app_type,
                    void *arg,
                    kal_char *buf,
                    kal_int32 buf_len,
                    kal_int32 *r_size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 l;
    kal_char *s = (kal_char*) arg;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    CHECK_INET_PARAM(arg, INET_RESULT_ERROR) l = _snprintf(buf, buf_len, "%s", s);
    CHECK_INET_PACK_ENBUF(l) * r_size = l;
    return INET_RESULT_OK;

}   /* end of inet_msg_pack_string */


/*****************************************************************************
 * FUNCTION
 *  inet_msg_pack_header_name_list
 * DESCRIPTION
 *  This function packs the inet_str_list_struct header value.
 * PARAMETERS
 *  app_type        [IN]            application type
 *  arg             [IN]            pointer of header value
 *  buf             [IN]            buffer to store packed header value
 *  buf_len         [IN]            available data size of buffer
 *  r_size          [IN/OUT]        real data size to pack
 * RETURNS
 *  INET result code
 *****************************************************************************/
inet_result_enum inet_msg_pack_header_name_list(
                    kal_uint8 app_type,
                    void *arg,
                    kal_char *buf,
                    kal_int32 buf_len,
                    kal_int32 *r_size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 m, size = 0;
    inet_int_str_list_struct *int_str_list = (inet_int_str_list_struct*) arg;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    CHECK_INET_PARAM(arg, INET_RESULT_ERROR) while (int_str_list)
    {
        if (int_str_list->object)
        {
            if (int_str_list->next && int_str_list->next->object)
            {
                m = _snprintf(
                        buf + size,
                        buf_len - size,
                        "%s, ",
                        (int_str_list->object->int_value != INET_HDR_UNRECOGNIZED) ? inet_msg_header_name_str(int_str_list->object->int_value) : int_str_list->object-> str_value);
            }
            else
            {
                m = _snprintf(
                        buf + size,
                        buf_len - size,
                        "%s",
                        (int_str_list->object->int_value != INET_HDR_UNRECOGNIZED) ? inet_msg_header_name_str(int_str_list->object->int_value) : int_str_list->object-> str_value);

            }
            CHECK_INET_PACK_ENBUF(m) size += m;

        }
        int_str_list = int_str_list->next;
    }
    *r_size = size;
    return INET_RESULT_OK;

}   /* end of inet_msg_pack_header_name_list */


/*****************************************************************************
 * FUNCTION
 *  inet_msg_pack_string_list
 * DESCRIPTION
 *  This function packs the inet_str_list_struct header value.
 * PARAMETERS
 *  app_type        [IN]            application type
 *  arg        

⌨️ 快捷键说明

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