0
@@ -22,6 +22,9 @@ limitations under the License.
0
#import <Foundation/Foundation.h>
0
@@ -160,9 +163,11 @@ static void nunja_response_helper(struct evhttp_request *req, int code, NSString
0
- (void) handleRequest:(NunjaRequest *)request;
0
+struct event_base *event_base;
0
@interface Nunja : NSObject
0
-
struct event_base *event_base;0
id<NSObject,NunjaDelegate> delegate;
0
@@ -204,6 +209,7 @@ static void nunja_request_handler(struct evhttp_request *req, void *nunja_pointe
0
event_base = event_init();
0
httpd = evhttp_new(event_base);
0
evhttp_set_gencb(httpd, nunja_request_handler, self);
0
@@ -238,4 +244,106 @@ static void nunja_request_handler(struct evhttp_request *req, void *nunja_pointe
0
+static void nunja_dns_gethostbyname_cb(int result, char type, int count, int ttl, void *addresses, void *arg)
0
+ if (result == DNS_ERR_TIMEOUT) {
0
+ fprintf(stdout, "[Timed out] ");
0
+ if (result != DNS_ERR_NONE) {
0
+ fprintf(stdout, "[Error code %d] ", result);
0
+ fprintf(stderr, "type: %d, count: %d, ttl: %d: ", type, count, ttl);
0
+ struct in_addr *in_addrs = addresses;
0
+ /* a resolution that's not valid does not help */
0
+ address = [NSString stringWithFormat:@"%s", inet_ntoa(in_addrs[0])];
0
+ /* may get at most one PTR */
0
+ fprintf(stderr, "%s ", *(char **)addresses);
0
+ NuBlock *block = (NuBlock *) arg;
0
+ NuCell *args = [[NuCell alloc] init];
0
+ [args setCar:address];
0
+ [block evalWithArguments:args context:nil];
0
+- (void) resolveDomainName:(NSString *) name andDo:(NuBlock *) block
0
+ evdns_resolve_ipv4([name cStringUsingEncoding:NSUTF8StringEncoding], 0, nunja_dns_gethostbyname_cb, block);
0
+nu_http_request_done(struct evhttp_request *req, void *arg)
0
+ printf("received %d\n", (int) arg);
0
+ if (req->response_code != HTTP_OK) {
0
+ fprintf(stderr, "FAILED to get OK\n");
0
+ else if (evhttp_find_header(req->input_headers, "Content-Type") == NULL) {
0
+ fprintf(stderr, "FAILED to find Content-Type\n");
0
+ data = [NSData dataWithBytes:EVBUFFER_DATA(req->input_buffer) length:EVBUFFER_LENGTH(req->input_buffer)];
0
+ NuBlock *block = (NuBlock *) arg;
0
+ NuCell *args = [[NuCell alloc] init];
0
+ [block evalWithArguments:args context:nil];
0
+ //evhttp_connection_free(req->evcon);
0
+- (void) getResourceFromHost:(NSString *) host address:(NSString *) address port:(int)port path:(NSString *)path andDo:(NuBlock *) block
0
+ struct evhttp_connection *evcon = evhttp_connection_new([address cStringUsingEncoding:NSUTF8StringEncoding], port);
0
+ fprintf(stdout, "FAILED to connect\n");
0
+ * At this point, we want to schedule a request to the HTTP
0
+ * server using our make request method.
0
+ struct evhttp_request *req = evhttp_request_new(nu_http_request_done, block);
0
+ /* Add the information that we care about */
0
+ evhttp_add_header(req->output_headers, "Host", [host cStringUsingEncoding:NSUTF8StringEncoding]);
0
+ /* We give ownership of the request to the connection */
0
+ if (evhttp_make_request(evcon, req, EVHTTP_REQ_GET, [path cStringUsingEncoding:NSUTF8StringEncoding]) == -1) {
0
+ fprintf(stdout, "FAILED to make the request \n");
Comments
No one has commented yet.