void pbproxy_handle_http_header(pubnub_t *p, char const* header) { char scheme_basic[] = "Basic"; char scheme_NTLM[] = "NTLM"; char proxy_auth[] = "Proxy-Authenticate: "; char const* contents; PUBNUB_ASSERT_OPT(p != NULL); PUBNUB_ASSERT_OPT(header != NULL); if (strncmp(p->core.http_buf, proxy_auth, sizeof proxy_auth - 1) != 0) { return; } contents = p->core.http_buf + sizeof proxy_auth - 1; PUBNUB_LOG_TRACE("pbproxy_handle_http_header(header='%s', contents='%s')\n", header, contents); if (0 == strncmp(contents, scheme_basic, sizeof scheme_basic -1)) { /* We ignore the "realm" for now */ PUBNUB_LOG_TRACE("pbproxy_handle_http_header() Basic authentication\n"); p->proxy_auth_scheme = pbhtauBasic; p->proxy_authorization_sent = false; } else if (0 == strncmp(contents, scheme_NTLM, sizeof scheme_NTLM -1)) { if (pbhtauNTLM != p->proxy_auth_scheme) { pbntlm_core_init(p); p->proxy_auth_scheme = pbhtauNTLM; p->proxy_authorization_sent = false; } else { char const *base64_msg = contents + sizeof scheme_NTLM; pbntlm_core_handle(p, base64_msg, strcspn(base64_msg, " \r\n")); } } else { PUBNUB_LOG_ERROR("Proxy Authentication '%s' not supported\n", contents); p->proxy_auth_scheme = pbhtauNone; } }
void pbproxy_handle_http_header(pubnub_t* p, char const* header) { char scheme_basic[] = "Basic"; char scheme_digest[] = "Digest"; char scheme_NTLM[] = "NTLM"; char proxy_auth[] = "Proxy-Authenticate: "; char const* contents; PUBNUB_ASSERT_OPT(p != NULL); PUBNUB_ASSERT_OPT(header != NULL); switch (header[0]) { case ' ': case '\t': /* Though this is not very nice, we only support multi-line headers for Digest proxy. In practice, Basic and NTLM never use multi-line headers. */ if (p->proxy_auth_scheme != pbhtauDigest) { return; } pbhttp_digest_parse_header(&p->digest_context, header + 1); return; default: if (strncmp(header, proxy_auth, sizeof proxy_auth - 1) != 0) { return; } break; } contents = header + sizeof proxy_auth - 1; PUBNUB_LOG_TRACE("pbproxy_handle_http_header(header='%s', contents='%s')\n", header, contents); if (0 == strncmp(contents, scheme_basic, sizeof scheme_basic - 1)) { /* We ignore the "realm" for now */ PUBNUB_LOG_TRACE("pbproxy_handle_http_header() Basic authentication\n"); p->proxy_auth_scheme = pbhtauBasic; p->proxy_authorization_sent = false; } else if (0 == strncmp(contents, scheme_digest, sizeof scheme_digest - 1)) { /* We ignore the "realm" for now */ PUBNUB_LOG_TRACE( "pbproxy_handle_http_header() Digest authentication\n"); p->proxy_auth_scheme = pbhtauDigest; pbhttp_digest_init(&p->digest_context); pbhttp_digest_parse_header(&p->digest_context, contents + sizeof scheme_digest); p->proxy_authorization_sent = false; } else if (0 == strncmp(contents, scheme_NTLM, sizeof scheme_NTLM - 1)) { if (pbhtauNTLM != p->proxy_auth_scheme) { pbntlm_core_init(p); p->proxy_auth_scheme = pbhtauNTLM; p->proxy_authorization_sent = false; } else { char const* base64_msg = contents + sizeof scheme_NTLM; pbntlm_core_handle(p, base64_msg, strcspn(base64_msg, " \r\n")); } } else { PUBNUB_LOG_ERROR("Proxy Authentication '%s' not supported\n", contents); p->proxy_auth_scheme = pbhtauNone; } }