static inline char *pcs_http_get_charset_from_header(const char *header, int size) { char *res = NULL; const char *p = header, *key = "charset", *end = NULL, *tmp; int i = 7;//strlen(key) = 7; while (*p) { if (*p == key[0] && pcs_utils_streq(p, key, i)) { tmp = p + i; if (*tmp != '=') continue; tmp++; end = tmp; while (*end && PCS_IS_TOKEN_CHAR(*end)) end++; if (end > tmp) { res = (char *)pcs_malloc(end - tmp + 1); memcpy(res, tmp, end - tmp); res[end - tmp] = '\0'; break; } } p++; } return res; }
/*从URL地址的QueryString中解析出类似于 &token=abc_ef-g&a= 的值。此例中,key传入"&token",将返回abc_ef-g*/ static char *pcs_get_embed_query_token_by_key(const char *html, const char *key) { char *val = NULL; const char *p = html, *end = NULL, *tmp; int i = strlen(key);// \f\n\r\t\v while (*p) { if (*p == key[0] && pcs_utils_streq(p, key, i)) { tmp = p + i; if (*tmp != '=') continue; tmp++; end = tmp; while (*end && PCS_IS_TOKEN_CHAR(*end)) end++; if (end > tmp) { val = (char *)pcs_malloc(end - tmp + 1); memcpy(val, tmp, end - tmp); val[end - tmp] = '\0'; return val; } } p++; } return val; }