Neon is really a great library, and has recently been released as version 0.25.0, which has built-in support for NTLM authentication. Here is a sample program showing how this can be used in practise.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "ne_socket.h"
#include "ne_session.h"
#include "ne_request.h"
#include "ne_auth.h"
typedef struct {
static const int challenge_issued = 0;
} user_data;
/*
* Response reader callback function
*
*/
void my_response_reader(void *userdata, const char *buf, size_t len) {
printf("Received: %s\n", buf);
}
/*
* Authentication callback
*/
static int my_auth(void *userdata, const char *realm, int attempts, char *username, char *password)
{
strncpy(username, "username", NE_ABUFSIZ);
strncpy(password, "password", NE_ABUFSIZ);
user_data* data = (user_data*)userdata;
return attempts;
}
int main(int argc, char* argv[]) {
user_data data;
int success = ne_sock_init();
char dropbuf[4096];
if (success != 0) {
printf("Cannot initialize Neon library");
exit(1);
}
ne_session* session = ne_session_create("http", "www.google.com", 80);
ne_session_proxy(session, "proxy1.researchkitchen.co.uk", 8080);
ne_set_proxy_auth(session, my_auth, (void*)&data);
ne_request *req = ne_request_create(session, "GET", "/");
ne_add_request_header(req, "Connection", "Keep-Alive");
ne_debug_init(stdout, NE_DBG_HTTPAUTH);
if (ne_request_dispatch(req))
{
printf("An error occurred\n");
const char* error = ne_get_error(session);
printf("%s", error);
exit(1);
}
else
{
printf("Response status code was %d\n", ne_get_status(req)->code);
ne_request_destroy(req);
}
ne_close_connection(session);
ne_session_destroy(session);
return 0;
}