0
@@ -28,10 +28,22 @@ limitations under the License.
0
#import <Foundation/Foundation.h>
0
+ static initialized = 0;
0
+ [Nu loadNuFile:@"nunja" fromBundleWithIdentifier:@"nu.programming.nunja" withContext:nil];
0
static bool verbose_nunja = false;
0
@interface NunjaRequest : NSObject
0
struct evhttp_request *req;
0
@@ -39,27 +51,21 @@ static bool verbose_nunja = false;
0
@implementation NunjaRequest
0
-- (id) initWith
Request:(struct evhttp_request *)r
0
+- (id) initWith
Nunja:(Nunja *)n request:(struct evhttp_request *)r
0
+- (Nunja *) nunja {return nunja;}
0
return [NSString stringWithCString:evhttp_request_uri(req) encoding:NSUTF8StringEncoding];
0
- static initialized = 0;
0
- [Nu loadNuFile:@"nunja" fromBundleWithIdentifier:@"nu.programming.nunja" withContext:nil];
0
if (!req->input_buffer->buffer)
0
@@ -163,11 +169,9 @@ 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
@@ -195,7 +199,7 @@ static void nunja_request_handler(struct evhttp_request *req, void *nunja_pointe
0
id delegate = [nunja delegate];
0
- [delegate handleRequest:[[[NunjaRequest alloc] initWith
Request:req] autorelease]];
0
+ [delegate handleRequest:[[[NunjaRequest alloc] initWith
Nunja:nunja request:req] autorelease]];
0
nunja_response_helper(req, HTTP_OK, @"OK",
0
@@ -250,50 +254,45 @@ 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
+ else 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
+ fprintf(stdout, "type: %d, count: %d, ttl: %d\n", type, count, ttl);
0
+ struct in_addr *in_addrs = addresses;
0
+ else if (count == 0) {
0
+ address = [NSString stringWithFormat:@"%s", inet_ntoa(in_addrs[0])];
0
+ /* may get at most one PTR */
0
+ // this needs review. TB.
0
+ fprintf(stdout, "addresses: %s ", *(char **)addresses);
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
+ 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
@@ -302,16 +301,15 @@ static void nunja_dns_gethostbyname_cb(int result, char type, int count, int ttl
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
+void nunja_http_request_done(struct evhttp_request *req, void *arg)
0
-
printf("received %d\n", (int) arg);
0
+
fprintf(stdout, "received %d bytes\n", (int) arg);
0
if (req->response_code != HTTP_OK) {
0
- fprintf(std
err, "FAILED to get OK\n");
0
+ fprintf(std
out, "FAILED to get OK\n");
0
else if (evhttp_find_header(req->input_headers, "Content-Type") == NULL) {
0
- fprintf(std
err, "FAILED to find Content-Type\n");
0
+ fprintf(std
out, "FAILED to find Content-Type\n");
0
data = [NSData dataWithBytes:EVBUFFER_DATA(req->input_buffer) length:EVBUFFER_LENGTH(req->input_buffer)];
0
@@ -321,26 +319,29 @@ nu_http_request_done(struct evhttp_request *req, void *arg)
0
[block evalWithArguments:args context:nil];
0
+ fprintf(stdout, "end of callback\n");
0
//evhttp_connection_free(req->evcon);
0
- (void) getResourceFromHost:(NSString *) host address:(NSString *) address port:(int)port path:(NSString *)path andDo:(NuBlock *) block
0
+ // make the connection
0
struct evhttp_connection *evcon = evhttp_connection_new([address cStringUsingEncoding:NSUTF8StringEncoding], port);
0
fprintf(stdout, "FAILED to connect\n");
0
+ NuCell *args = [[NuCell alloc] init];
0
+ [block evalWithArguments:args context:nil];
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
+ struct evhttp_request *req = evhttp_request_new(nunja_http_request_done, block);
0
evhttp_add_header(req->output_headers, "Host", [host cStringUsingEncoding:NSUTF8StringEncoding]);
0
- /
* We give ownership of the request to the connection */0
+ /
/ give ownership of the request to the connection0
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.