parse_auth_header(struct mg_connection *conn, struct auth_s *auth)
{
	if (!auth || !conn) {
		return 0;
	}

	const char *auth_header = NULL;
	if (((auth_header = mg_get_header(conn, "Authorization")) == NULL) ||
			strncasecmp(auth_header, "Basic ", 6) != 0) {
		return 0;
	}

	/* Parse authorization header */
	const char* src = auth_header + 6;
	size_t len = apr_base64_decode_len((const char*)src);
	auth->pworkbuf = auth->workbuf;
	if (len > sizeof(auth->workbuf)) {
		auth->pworkbuf = calloc(0, len);
		auth->workbuf_len = len;
	}
	len = apr_base64_decode(auth->pworkbuf, src);
	if (len == 0) {
		return 0;
	}

	char *passwd = NULL, *saveptr = NULL;
	char *user = strtok_r(auth->pworkbuf, ":", &saveptr);
	if (user) {
		passwd = strtok_r(NULL, ":", &saveptr);
	}

	auth->pszUser = user;
	auth->pszPasswd = passwd;

	return 1;
}
parse_auth_header(struct mg_connection *conn, struct auth_s *auth)
{
	if (!auth || !conn) {
		return 0;
	}

	const char *auth_header = NULL;
	if (((auth_header = mg_get_header(conn, "Authorization")) == NULL) ||
			strncasecmp(auth_header, "Basic ", 6) != 0) {
		return 0;
	}

	 
	const char* src = auth_header + 6;
	size_t len = apr_base64_decode_len((const char*)src);
	auth->pworkbuf = auth->workbuf;
	if (len > sizeof(auth->workbuf)) {
		auth->pworkbuf = calloc(0, len);
		auth->workbuf_len = len;
	}
	len = apr_base64_decode(auth->pworkbuf, src);
	if (len == 0) {
		return 0;
	}

	char *passwd = NULL, *saveptr = NULL;
	char *user = strtok_r(auth->pworkbuf, ":", &saveptr);
	if (user) {
		passwd = strtok_r(NULL, ":", &saveptr);
	}

	auth->pszUser = user;
	auth->pszPasswd = passwd;

	return 1;
}