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

📄 inet_msg_unpack.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 5 页
字号:
            authorization->auth_type = INET_AUTH_BASIC;
        }
        text = value;
    }

    do
    {
        next_token = inet_msg_get_next_token(text);
        inet_msg_skipcfws(&text);

        if ((value = strchr(text, '=')) != NULL)
        {
            *value++ = '\0';

            if (strcmp(text, "cnonce") == 0)
            {
                if ((authorization->cnonce = inet_msg_strdup(mem_func, value)) == NULL)
                {
                    goto exit_err;
                }
            }
            else if (strcmp(text, "nonce") == 0)
            {
                value = inet_msg_mime_quote(value);
                if (value && *value != '\0')    /* handle case of nonce="" */
                {
                    if ((authorization->nonce = inet_msg_strdup(mem_func, value)) == NULL)
                    {
                        goto exit_err;
                    }
                }
                else
                {
                    authorization->nonce = NULL;
                }
            }
            else if (strcmp(text, "username") == 0)
            {
                value = inet_msg_mime_quote(value);
                if ((authorization->username = inet_msg_strdup(mem_func, value)) == NULL)
                {
                    goto exit_err;
                }
            }
            else if (strcmp(text, "realm") == 0)
            {
                value = inet_msg_mime_quote(value);
                if ((authorization->realm = inet_msg_strdup(mem_func, value)) == NULL)
                {
                    goto exit_err;
                }
            }
            else if (strcmp(text, "uri") == 0)
            {
                value = inet_msg_mime_quote(value);
                if ((authorization->digest_uri = inet_msg_strdup(mem_func, value)) == NULL)
                {
                    goto exit_err;
                }
            }
            else if (strcmp(text, "response") == 0)
            {
                value = inet_msg_mime_quote(value);
                if (strlen(value) > 0)
                {
                    if ((authorization->response = inet_msg_strdup(mem_func, value)) == NULL)
                    {
                        goto exit_err;
                    }
                }
            }
            else if (strcmp(text, "opaque") == 0)
            {
                value = inet_msg_mime_quote(value);
                if ((authorization->opaque = inet_msg_strdup(mem_func, value)) == NULL)
                {
                    goto exit_err;
                }
            }
            else if (strcmp(text, "nc") == 0)
            {
                if ((authorization->nc = inet_msg_strdup(mem_func, value)) == NULL)
                {
                    goto exit_err;
                }
            }
            else if (strcmp(text, "qop") == 0)
            {
                if (strcmp(value, "auth") == 0)
                {
                    authorization->qop = INET_AUTH_QOP_AUTH;
                }
                else if (strcmp(value, "auth-int") == 0)
                {
                    authorization->qop = INET_AUTH_QOP_AUTH_INT;
                }
                else
                {
                    authorization->qop = INET_AUTH_QOP_UNSUPPORT;
                }
            }
            else if (strcmp(text, "algorithm") == 0)
            {
                if (inet_msg_compare_cstring(value, "MD5") == 0)
                {
                    authorization->algo = INET_AUTH_ALGO_MD5;
                }
                else if (inet_msg_compare_cstring(value, "MD5-sess") == 0)
                {
                    authorization->algo = INET_AUTH_ALGO_MD5_SESS;
                }
                else
                {
                    authorization->algo = INET_AUTH_ALGO_UNSUPPORT;
                }
            }
        }
        else
        {
            /* abnormal value */
            goto exit_err;
        }

        text = next_token;

    } while (text);
    return (kal_uint32) authorization;
  exit_err:
    if (authorization)
    {
        inet_authorization_struct_free_fn(mem_func, authorization);
    }
    return 0;
}


/*****************************************************************************
 * FUNCTION
 *  inet_msg_unpack_date_string
 * DESCRIPTION
 *  This function unpacks rfc1123, rfc850 and asctime date string.
 * GRAMMER
 *  HTTP-date    = rfc1123-date | rfc850-date | asctime-date
 *  rfc1123-date = wkday "," SP date1 SP time SP "GMT"
 *  rfc850-date  = weekday "," SP date2 SP time SP "GMT"
 *  asctime-date = wkday SP date3 SP time SP 4DIGIT
 *  date1        = 2DIGIT SP month SP 4DIGIT
 *  ; day month year (e.g., 02 Jun 1982)
 *  date2        = 2DIGIT "-" month "-" 2DIGIT
 *  ; day-month-year (e.g., 02-Jun-82)
 *  date3        = month SP ( 2DIGIT | ( SP 1DIGIT ))
 *  ; month day (e.g., Jun  2)
 *  time         = 2DIGIT ":" 2DIGIT ":" 2DIGIT
 *  ; 00:00:00 - 23:59:59
 *  wkday        = "Mon" | "Tue" | "Wed"
 *  | "Thu" | "Fri" | "Sat" | "Sun"
 *  weekday      = "Monday" | "Tuesday" | "Wednesday"
 *  | "Thursday" | "Friday" | "Saturday" | "Sunday"
 *  month        = "Jan" | "Feb" | "Mar" | "Apr"
 *  | "May" | "Jun" | "Jul" | "Aug"
 *  | "Sep" | "Oct" | "Nov" | "Dec"
 * PARAMETERS
 *  mem_func        [IN]        Memory function
 *  text            [IN]        String of field value
 * RETURNS
 *  inet_addr_list_struct pointer
 *****************************************************************************/
kal_uint32 inet_msg_unpack_date_string(inet_mem_func_struct *mem_func, kal_char *text)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint32 time;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (text == NULL)
    {
        return 0;
    }
    if (applib_dt_rfc1123_rfc850_asctime_dateString2Time(text, &time) == KAL_TRUE)
    {
        return time;
    }
    else
    {
        return 0;
    }

}


/*****************************************************************************
 * FUNCTION
 *  inet_msg_unpack_addr_list
 * DESCRIPTION
 *  This function unpacks the param list.
 * GRAMMER
 *  Contact        =  ("Contact" / "m" ) HCOLON
 *  ( STAR / (contact-param *(COMMA contact-param)))
 *  contact-param  =  (name-addr / addr-spec) *(SEMI contact-params)
 *  name-addr      =  [ display-name ] LAQUOT addr-spec RAQUOT
 *  addr-spec      =  SIP-URI / SIPS-URI / absoluteURI
 *  display-name   =  *(token LWS)/ quoted-string
 *  
 *  Ex1:<sip:ad-hoc@mtk.com.tw>
 *  Ex2: Kevin    <sip:ad-hoc@mtk.com.tw>
 *  Ex3: sip:ad-hoc@mtk.com.tw
 * PARAMETERS
 *  mem_func        [IN]        Memory function
 *  text            [IN]        String of field value
 * RETURNS
 *  inet_addr_list_struct pointer
 *****************************************************************************/
kal_uint32 inet_msg_unpack_addr_list(inet_mem_func_struct *mem_func, kal_char *text)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_char *uri, *angle /* < */ ;

    /* with initialized value */
    kal_char *next_token = NULL, *disp = NULL, *param = NULL, *s = NULL;
    inet_addr_list_struct *addr_list, *addr_list_head;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (!text)
    {
        return (kal_uint32) text;
    }
    addr_list_head = (inet_addr_list_struct*) inet_malloc(mem_func, sizeof(inet_addr_list_struct));
    if (!addr_list_head)
    {
        return (kal_uint32) addr_list_head;
    }
    addr_list_head->object = (inet_addr_struct*) inet_malloc(mem_func, sizeof(inet_addr_struct));
    if (!(addr_list_head->object))
    {
        return (kal_uint32) addr_list_head;
    }

    addr_list = addr_list_head;

    do
    {

        if (next_token)
        {
            text = next_token;
            next_token = NULL;  /* reset */
            uri = NULL;
            angle = NULL;

            if (addr_list->next == NULL)
            {
                addr_list->next = (inet_addr_list_struct*) inet_malloc(mem_func, sizeof(inet_addr_list_struct));
                if (!addr_list->next)
                {
                    return (kal_uint32) addr_list_head;
                }
            }
            addr_list = addr_list->next;

            if (!(addr_list->object))
            {
                addr_list->object = (inet_addr_struct*) inet_malloc(mem_func, sizeof(inet_addr_struct));
                if (!(addr_list->object))
                {
                    return (kal_uint32) addr_list_head;
                }
            }
        }

        next_token = strchr(text, ',');
        if (next_token)
        {
            *next_token++ = '\0';
        }

        inet_msg_skipcfws(&text);

        uri = text;

        /* check */
        angle = strchr(uri, '<');

        if (angle)
        {
            if (angle > uri)
            {
                disp = uri;
            }

            *angle++ = '\0';
            uri = angle;

            angle = strchr(uri, '>');
            if (angle)
            {
                *angle++ = '\0';
                s = angle;
            }
            else;   /* LOG */
        }
        else
        {
            s = uri;
        }

        if (s)
        {
            inet_msg_skipcfws(&s);
        }

        if (s && *s != '\0')
        {
            param = strchr(s, ';');
            if (param)
            {
                *param++ = '\0';
            }
        }

        if (disp)
        {
            inet_msg_skipcfws(&disp);
            inet_msg_trimcfws(disp);
            inet_msg_mime_quote(disp);
            addr_list->object->display_name = (kal_char*) inet_msg_strdup(mem_func, disp);
        }

        if (uri)
        {
            inet_msg_skipcfws(&uri);
            inet_msg_trimcfws(uri);
            addr_list->object->uri = (inet_uri_struct*) inet_msg_unpack_uri(mem_func, uri);
        }

        if (param)
        {
            addr_list->object->param_list = (inet_param_list_struct*) inet_msg_unpack_param(mem_func, param);
        }
    } while (next_token);
    return (kal_uint32) addr_list_head;
}


/*****************************************************************************
 * FUNCTION
 *  inet_msg_unpack_content_type
 * DESCRIPTION
 *  This function unpacks the content-type.
 * GRAMMER
 *  type/subtype
 * PARAMETERS
 *  mem_func        [IN]        Memory function
 *  text            [IN]        String of field value
 * RETURNS
 *  inet_content_type_struct pointer
 *****************************************************************************/
kal_uint32 inet_msg_unpack_content_type(inet_mem_func_struct *mem_func, kal_char *text)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_char *param;
    kal_char *subtype;

    inet_content_type_struct *ct = NULL;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    param = strchr(text, ';');
    if (param)
    {
        *param++ = '\0';
    }

    subtype = strchr(text, '/');
    if (subtype)
    {
        *subtype++ = '\0';
    }

    ct = inet_malloc(mem_func, sizeof(inet_content_type_struct));
    if (ct)
    {
        ct->mime_type = inet_msg_strdup(mem_func, text);
        if (!ct->mime_type)
        {
            goto no_mem;
        }

        if (subtype)
        {
            ct->mime_subtype = inet_msg_strdup(mem_func, subtype);
            if (!ct->mime_subtype)
            {
                goto no_mem;
            }
        }

        if (param)
        {
            ct->param_list = (inet_param_list_struct*) inet_msg_unpack_param(mem_func, param);
            if (!ct->param_list)

⌨️ 快捷键说明

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