该函数是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;
}