/* Copyright (C) 2000-2003 Max Berger This file is part of vCardReceiver, written for the OpenGroupware project (OGo) OGo is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. OGo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OGo; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // $Id$ #import #import #import "vCardReceiverSessionHandler.h" #ifdef __APPLE__ #import "URLPOSTRequestApple.h" #else #import "URLPOSTRequestNGObjWeb.h" #endif int main(int argc, char **argv, char **env) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *subpool; NSData *recData = nil; NSData *answer = nil; URLPOSTRequest *req; NSURLResponse *resp = nil; NSError *err = nil; NSString *stringData; NSURL *url; vCardSyncSessionHandler* vcardsyncsessionhandler; SyncML *syncml; NSMutableArray *arguments; NSString *user = @""; NSString *pass = @""; BOOL firstTime = YES; #if LIB_FOUNDATION_LIBRARY [NSProcessInfo initializeWithArguments:argv count:argc environment:env]; #endif arguments = [NSMutableArray arrayWithArray:[[NSProcessInfo processInfo]arguments]]; while ([[arguments objectAtIndex:1]characterAtIndex:0]=='-') { stringData = [arguments objectAtIndex:2]; [arguments removeObjectAtIndex:2]; if ([[arguments objectAtIndex:1]characterAtIndex:1]=='u') user = stringData; if ([[arguments objectAtIndex:1]characterAtIndex:1]=='p') pass = stringData; [arguments removeObjectAtIndex:1]; } url = [NSURL URLWithString:[arguments objectAtIndex:1]]; //NSLog(@"Connection to %@ as %@",url,user); req = nil; vcardsyncsessionhandler = [[vCardSyncSessionHandler alloc]initWithUser:user pass:pass]; syncml = [[SyncML alloc]initWithSessionHandler:vcardsyncsessionhandler]; answer = [syncml createInitialSyncPackageTo:@"www.syncserver.org"]; /* stringData = [[NSString alloc] initWithData:answer encoding:NSISOLatin1StringEncoding]; NSLog(@"First Packet Sent: %@",stringData); [stringData release]; */ [answer retain]; while ( (err==nil) && ([answer length]>0) ) { subpool = [[NSAutoreleasePool alloc]init]; req = [[URLPOSTRequest alloc]initWithURL:url]; [req setPostData:answer]; [syncml release]; syncml = nil; //NSLog(@"sending data with len %u",[answer length]); [answer release]; answer = nil; recData = [NSURLConnection sendSynchronousRequest:req returningResponse:&resp error:&err]; [req release]; req = nil; //NSLog(@"receiving data with len %u",[recData length]); if ( [recData length]>0 ) { syncml = [[SyncML alloc]initWithSessionHandler:vcardsyncsessionhandler]; answer = [syncml processSyncMessage:recData messageForInvalid:NO]; if (([answer length]==0)&&(firstTime)) { NSLog(@"Error: Received invalid SyncML packet from server"); } } firstTime=NO; if (err!=nil) { NSLog(@"Error connecting to Server: %@",[err description]); } [answer retain]; [subpool release]; subpool = nil; } [syncml release]; syncml = nil; [vcardsyncsessionhandler release]; vcardsyncsessionhandler = nil; //NSLog(@"encoding: %@",[resp textEncodingName]); /*` stringData = [[NSString alloc] initWithData:answer encoding:NSISOLatin1StringEncoding]; NSLog(@"Last Packet Sent: %@",stringData); [stringData release]; stringData = nil; */ [answer release]; answer = nil; /* stringData = [[NSString alloc] initWithData:recData encoding:NSISOLatin1StringEncoding]; NSLog(@"Last Packet Received: %@",stringData); [stringData release]; stringData = nil; */ [SyncML cleanup]; [pool release]; return 0; }