static int ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr) { struct MHD_Response *response; char *username; const char *password = "******"; const char *realm = "*****@*****.**"; int ret; (void)cls; /* Unused. Silent compiler warning. */ (void)url; /* Unused. Silent compiler warning. */ (void)method; /* Unused. Silent compiler warning. */ (void)version; /* Unused. Silent compiler warning. */ (void)upload_data; /* Unused. Silent compiler warning. */ (void)upload_data_size; /* Unused. Silent compiler warning. */ (void)ptr; /* Unused. Silent compiler warning. */ username = MHD_digest_auth_get_username(connection); if (NULL == username) { response = MHD_create_response_from_buffer(strlen (DENIED), DENIED, MHD_RESPMEM_PERSISTENT); ret = MHD_queue_auth_fail_response(connection, realm, MY_OPAQUE_STR, response, MHD_NO); MHD_destroy_response(response); return ret; } ret = MHD_digest_auth_check(connection, realm, username, password, 300); MHD_free (username); if ( (ret == MHD_INVALID_NONCE) || (ret == MHD_NO) ) { response = MHD_create_response_from_buffer(strlen (DENIED), DENIED, MHD_RESPMEM_PERSISTENT); if (NULL == response) return MHD_NO; ret = MHD_queue_auth_fail_response(connection, realm, MY_OPAQUE_STR, response, (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO); MHD_destroy_response(response); return ret; } response = MHD_create_response_from_buffer(strlen(PAGE), PAGE, MHD_RESPMEM_PERSISTENT); ret = MHD_queue_response(connection, MHD_HTTP_OK, response); MHD_destroy_response(response); return ret; }
static int ahc_echo (void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **unused) { struct MHD_Response *response; char *username; const char *password = "******"; const char *realm = "*****@*****.**"; int ret; username = MHD_digest_auth_get_username(connection); if ( (username == NULL) || (0 != strcmp (username, "testuser")) ) { response = MHD_create_response_from_buffer(strlen (DENIED), DENIED, MHD_RESPMEM_PERSISTENT); ret = MHD_queue_auth_fail_response(connection, realm, OPAQUE, response, MHD_NO); MHD_destroy_response(response); return ret; } ret = MHD_digest_auth_check(connection, realm, username, password, 300); free(username); if ( (ret == MHD_INVALID_NONCE) || (ret == MHD_NO) ) { response = MHD_create_response_from_buffer(strlen (DENIED), DENIED, MHD_RESPMEM_PERSISTENT); if (NULL == response) return MHD_NO; ret = MHD_queue_auth_fail_response(connection, realm, OPAQUE, response, (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO); MHD_destroy_response(response); return ret; } response = MHD_create_response_from_buffer(strlen(PAGE), PAGE, MHD_RESPMEM_PERSISTENT); ret = MHD_queue_response(connection, MHD_HTTP_OK, response); MHD_destroy_response(response); return ret; }
int http_response::enqueue_response_digest( MHD_Connection* connection, MHD_Response* response ) { return MHD_queue_auth_fail_response( connection, realm.c_str(), opaque.c_str(), response, reload_nonce ? MHD_YES : MHD_NO ); }