__osip_quoted_string_set()函数,提取Sip中带引号的字符串

该函数是osip2库中的函数(稍作修改)
定义在osip2库中的parser.h中,声明在osip_www_authenticate.c中

该函数可用于GB35114提取Authorization字段中的random1以及random2、sign1、algorithm等字段的值

函数如下:

int __osip_quoted_string_set(const char *name, const char *str, string &result, const char **next) {
        *next = str;

//		if (*result != nullptr)
//			return OSIP_SUCCESS; /* already parsed */
        if (!result.empty())
            return OSIP_SUCCESS; /* already parsed */

        *next = nullptr;

        while ((' ' == *str) || ('\t' == *str) || (',' == *str))
            if (*str)
                str++;

            else
                return OSIP_SYNTAXERROR; /* bad header format */

        if (osip_strncasecmp(name, str, strlen(name)) == 0) {
            const char *quote1;
            const char *quote2;
            const char *tmp;
            const char *hack = strchr(str, '=');

            if (hack == nullptr)
                return OSIP_SYNTAXERROR;

            while (' ' == *(hack - 1)) /* get rid of extra spaces */
                hack--;

            if ((size_t) (hack - str) != strlen(name)) {
                *next = str;
                return OSIP_SUCCESS;
            }

            quote1 = __osip_quote_find(str);

            if (quote1 == nullptr)
                return OSIP_SYNTAXERROR; /* bad header format... */

            quote2 = __osip_quote_find(quote1 + 1);

            if (quote2 == nullptr)
                return OSIP_SYNTAXERROR; /* bad header format... */

            if (quote2 - quote1 == 1) {
                /* this is a special case! The quote contains nothing! */
                /* example:   Digest opaque="",cnonce=""               */
                /* in this case, we just forget the parameter... this  */
                /* this should prevent from user manipulating empty    */
                /* strings */
                tmp = quote2 + 1; /* next element start here */
                tmp += strspn(tmp, " \t");
                tmp += strspn(tmp, "\n\r");
                *next = nullptr;

                if (*tmp == '\0') /* end of header detected */
                    return OSIP_SUCCESS;

                if (*tmp != '\t' && *tmp != ' ')
                    /* LWS here ? */
                    *next = tmp;

                else { /* it is: skip it... */
                    tmp += strspn(tmp, " \t");

                    if (*tmp == '\0') /* end of header detected */
                        return OSIP_SUCCESS;

                    *next = tmp;
                }

                return OSIP_SUCCESS;
            }

//			*result = (char *) osip_malloc(quote2 - quote1 + 3);
//
//			if (*result == nullptr)
//				return OSIP_NOMEM;
//
//			osip_strncpy(*result, quote1, quote2 - quote1 + 1);
            result = string(quote1 + 1, quote2 - quote1 - 1);   //去掉引号
            tmp = quote2 + 1; /* next element start here */
            tmp += strspn(tmp, " \t");
            tmp += strspn(tmp, "\n\r");
            *next = nullptr;

            if (*tmp == '\0') /* end of header detected */
                return OSIP_SUCCESS;

            if (*tmp != '\t' && *tmp != ' ')
                /* LWS here ? */
                *next = tmp;

            else { /* it is: skip it... */
                tmp += strspn(tmp, " \t");

                if (*tmp == '\0') /* end of header detected */
                    return OSIP_SUCCESS;

                *next = tmp;
            }

        } else
            *next = str; /* wrong header asked! */

        return OSIP_SUCCESS;
    }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

美丽的欣情

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值