/* Copyright (C) 2000-2003 Max Berger This file is part of 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$ #include #import "OGoSyncMLZSAdapter.h" #import "OGoSyncMLZSAdapterSessionHandler.h" #include "common.h" #include "libSyncML/SyncML.h" @implementation SoApplication(OGoSyncMLZSAdapter) - (id)syncmlInContext:(id)_ctx { /* TODO: - check content-type on incoming - check accept header - check encoding of incoming message */ WOResponse *r = [_ctx response]; WORequest *request = [_ctx request]; NSData *content; NSString *str; SyncML *syncml; OGoSyncMLZSAdapterSessionHandler *handler; if ([[request method]isEqual:@"POST"]) { handler = [[OGoSyncMLZSAdapterSessionHandler alloc]init]; [handler setAuthenticator:[self authenticatorInContext:_ctx]]; syncml = [[SyncML alloc]initWithSessionHandler:handler]; [self logWithFormat:@"POST on SyncML"]; [handler release]; content = [request content]; [r setContentEncoding:NSUTF8StringEncoding]; [r setHeader:@"application/vnd.syncml+xml; charset=\"UTF-8\"" forKey:@"Content-Type"]; [r setHeader:@"private" forKey:@"Cache-Control"]; str = [[NSString alloc]initWithData:[syncml processSyncMessage:content messageForInvalid:YES] encoding:NSUTF8StringEncoding]; [r appendContentString:str]; [str release]; [syncml dealloc]; [r setStatus:200 /* Ok */]; } else if ([[request method]isEqual:@"GET"]) { /* TODO: Make GET start a "server initiated" Sync OR Make GET return a html page with information about SyncML */ [r appendContentString:@"GET not (yet) supported! Please use POST"]; [r setStatus:200 /* Ok */]; } else { // Can't handle that. Only allow GET and POST [r setHeader:@"GET, POST" forKey:@"Allow"]; [r setStatus:405]; } return r; } @end