Permalink
Browse files

accepting the packfile data to a temp file

  • Loading branch information...
1 parent 5409326 commit 417071e63b99d182f1840ba9fde98164dcf1e9d3 @schacon committed Apr 6, 2010
Showing with 73 additions and 47 deletions.
  1. +8 −0 Controllers/AppController.m
  2. +2 −1 Controllers/GitHTTPConnection.h
  3. +63 −46 Controllers/GitHTTPConnection.m
@@ -36,10 +36,12 @@ @implementation AppController
@synthesize tabBarController;
@synthesize serverViewController;
+// creates [userDocs]/git path for git repos
- (NSString *)getGitPath
{
NSArray *paths;
NSString *gitPath = @"";
+ NSString *tmpPath = @"";
paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if ([paths count] > 0) {
gitPath = [NSString stringWithString:[[paths objectAtIndex:0] stringByAppendingPathComponent:@"git"]];
@@ -49,6 +51,12 @@ - (NSString *)getGitPath
if (![fm fileExistsAtPath:gitPath isDirectory:&isDir] && isDir) {
[fm createDirectoryAtPath:gitPath attributes:nil];
}
+
+ tmpPath = [NSString stringWithString:[[paths objectAtIndex:0] stringByAppendingPathComponent:@"gitTmp"]];
+
+ if (![fm fileExistsAtPath:tmpPath isDirectory:&isDir] && isDir) {
+ [fm createDirectoryAtPath:tmpPath attributes:nil];
+ }
}
return gitPath;
}
@@ -10,6 +10,7 @@
@interface GitHTTPConnection : HTTPConnection
{
NSString* gitService;
+ NSFileHandle* packfile;
}
- (BOOL)isBrowseable:(NSString *)path;
@@ -23,7 +24,7 @@
- (NSObject<HTTPResponse> *)receivePack:(NSString *)project;
- (NSObject<HTTPResponse> *)uploadPack:(NSString *)project;
-- (NSData*) packetData:(NSString*) info;
- (NSString*) prependPacketLine:(NSString*) info;
+- (NSData*) packetData:(NSString*) info;
@end
@@ -156,52 +156,38 @@ - (NSData *)preprocessResponse:(CFHTTPMessageRef)response
return [super preprocessResponse:response];
}
-- (NSData*) packetData:(NSString*) info
-{
- return [[self prependPacketLine:info] dataUsingEncoding:NSUTF8StringEncoding];
-}
-
-#define hex(a) (hexchar[(a) & 15])
-- (NSString*) prependPacketLine:(NSString*) info
-{
- static char hexchar[] = "0123456789abcdef";
- uint8_t buffer[5];
- unsigned int length = [info length] + 4;
-
- buffer[0] = hex(length >> 12);
- buffer[1] = hex(length >> 8);
- buffer[2] = hex(length >> 4);
- buffer[3] = hex(length);
-
- NSLog(@"write len [%c %c %c %c]", buffer[0], buffer[1], buffer[2], buffer[3]);
-
- NSData *data=[[NSData alloc] initWithBytes:buffer length:4];
- NSString *lenStr = [[NSString alloc]
- initWithData:data
- encoding:NSUTF8StringEncoding];
-
- return [NSString stringWithFormat:@"%@%@", lenStr, info];
-}
- (NSObject<HTTPResponse> *)receivePack:(NSString *)project
{
NSLog(@"ACCEPT PACKFILE");
- if (requestContentLength > 0) // Process POST data
- {
- NSLog(@"processing post data: %i", requestContentLength);
- [[NSNotificationCenter defaultCenter] postNotificationName:@"NewFileUploaded" object:nil];
- requestContentLength = 0;
- }
+
+ NSData *requestData = [(NSData *)CFHTTPMessageCopySerializedMessage(request) autorelease];
+ NSString *requestStr = [[[NSString alloc] initWithData:requestData encoding:NSASCIIStringEncoding] autorelease];
+ NSLog(@"\n=== Request ====================\n%@\n================================", requestStr);
+
+ NSLog(@"file offset: %d", [packfile offsetInFile]);
+ [packfile seekToFileOffset:0];
+ NSData* pktlen = [packfile readDataOfLength:4];
+ NSLog(@"pkt-ln: %@", pktlen);
+
+ // readRefs
+ // readPack
+ // writeRefs
+ // send updated refs (oks)
+ // packetFlush
+
return nil;
}
+
- (NSObject<HTTPResponse> *)uploadPack:(NSString *)project
{
NSLog(@"GENERATE AND TRANSFER PACKFILE");
return nil;
}
+
- (NSObject<HTTPResponse> *)plainResponse:(NSString *)project path:(NSString *)path
{
NSData *requestData = [(NSData *)CFHTTPMessageCopySerializedMessage(request) autorelease];
@@ -232,28 +218,59 @@ - (NSString*) prependPacketLine:(NSString*) info
}
+// TODO: Add random and move to temp?
+- (void)prepareForBodyWithSize:(UInt64)contentLength
+{
+ NSArray *paths;
+ NSString *tmpPath = @"";
+ paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+ tmpPath = [NSString stringWithString:[[paths objectAtIndex:0] stringByAppendingPathComponent:@"gitTmp"]];
+ NSString* packfilePath = [tmpPath stringByAppendingPathComponent:@"pack-upload.data"];
+ NSLog(@"PREPARE %@", packfilePath);
+ [[NSFileManager defaultManager] createFileAtPath: packfilePath
+ contents: nil attributes: nil];
+ packfile = [[NSFileHandle fileHandleForUpdatingAtPath:packfilePath] retain];
+ [packfile truncateFileAtOffset: 0];
+}
+
/**
* This method is called to handle data read from a POST.
* The given data is part of the POST body.
**/
- (void)processDataChunk:(NSData *)postDataChunk
{
- // Override me to do something useful with a POST.
- // If the post is small, such as a simple form, you may want to simply append the data to the request.
- // If the post is big, such as a file upload, you may want to store the file to disk.
- //
- // Remember: In order to support LARGE POST uploads, the data is read in chunks.
- // This prevents a 50 MB upload from being stored in RAM.
- // The size of the chunks are limited by the POST_CHUNKSIZE definition.
- // Therefore, this method may be called multiple times for the same POST request.
-
- NSLog(@"processPostDataChunk");
- NSLog(@"data: %@", postDataChunk);
+ [packfile writeData:postDataChunk];
+}
+
+#define hex(a) (hexchar[(a) & 15])
+- (NSString*) prependPacketLine:(NSString*) info
+{
+ static char hexchar[] = "0123456789abcdef";
+ uint8_t buffer[5];
- if (requestContentLength > 0) {
- } else {
- }
+ unsigned int length = [info length] + 4;
+
+ buffer[0] = hex(length >> 12);
+ buffer[1] = hex(length >> 8);
+ buffer[2] = hex(length >> 4);
+ buffer[3] = hex(length);
+
+ NSLog(@"write len [%c %c %c %c]", buffer[0], buffer[1], buffer[2], buffer[3]);
+
+ NSData *data=[[NSData alloc] initWithBytes:buffer length:4];
+ NSString *lenStr = [[NSString alloc]
+ initWithData:data
+ encoding:NSUTF8StringEncoding];
+
+ return [NSString stringWithFormat:@"%@%@", lenStr, info];
+}
+
+
+- (NSData*) packetData:(NSString*) info
+{
+ return [[self prependPacketLine:info] dataUsingEncoding:NSUTF8StringEncoding];
}
+
@end

0 comments on commit 417071e

Please sign in to comment.