// $Id$ #include "PHPIncludes.h" #include "PHPRequest.h" #include "NSString+PHP.h" #include "common.h" @implementation PHPRequest - (id)initWithMethod:(NSString *)_method uri:(NSString *)_uri translatedPath:(NSString *)_path remoteUser:(NSString *)_login { if ((self = [super init])) { self->method = [_method copy]; self->uri = [_uri copy]; self->translatedPath = [_path copy]; self->authUser = [_login copy]; } return self; } - (id)init { return [self initWithMethod:@"GET" uri:@"/" translatedPath:nil remoteUser:nil]; } - (void)dealloc { [self shutdown]; [self->method release]; [self->uri release]; [self->translatedPath release]; [self->authUser release]; [super dealloc]; } /* operations */ - (BOOL)startup { /* INITIALIZE */ /* TODO: what about memory management? */ SG(request_info).request_method = [self->method phpString]; SG(request_info).request_uri = [self->uri phpString]; SG(request_info).path_translated = [self->translatedPath phpString]; SG(request_info).auth_user = [self->authUser phpString]; SG(sapi_headers).http_response_code = 200; SG(request_info).query_string = NULL; SG(request_info).content_type = NULL; SG(request_info).content_length = 0; /* SETUP */ /* does that run anything for us? */ if (php_request_startup(TSRMLS_C) == FAILURE) /* TODO: should tear down above values? */ return NO; self->prFlags.started = 1; return YES; } - (void)shutdown { if (!self->prFlags.started) return; php_request_shutdown(NULL); self->prFlags.started = 0; } - (void)executeFileAtPath:(NSString *)_path { zend_file_handle zfd = { 0 }; /* setup file handle */ zfd.type = ZEND_HANDLE_FILENAME; #if 0 // original by jwk zfd.filename = (char *) SG(request_info).path_translated; zfd.free_filename = 0; #else zfd.filename = [_path phpString]; zfd.free_filename = 1; /* free path, correct? */ #endif zfd.opened_path = NULL; /* execute */ php_execute_script(&zfd TSRMLS_CC); } @end /* PHPRequest */