/* Copyright (C) 2000-2003 Max Berger This file is part of libsyncml, 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$ #include "SyncMLTagSmarts.h" #include @implementation SyncMLTagItemWithSmartDecode - (SyncMLTagData *)data { NSString *originalFormat = [self->meta format]; NSString *newStringData = NULL; if (([[self->data stringdata]length]==0) || ([originalFormat length]==0)) return [super data]; if ([originalFormat isEqual:SYNCML_FORMAT_BASE64]) { // FIXME: utf8?? see remark below // newStringData = [NSString stringWithData: // [[self->data stringdata]dataByDecodingBase64] // usingEncodingNamed:NSUTF8StringEncoding]; newStringData = [[self->data stringdata]stringByDecodingBase64]; [self->meta setFormat:SYNCML_FORMAT_CHR]; [self->data setStringdata:newStringData]; } return [super data]; } @end @implementation SyncMLTagItemWithSmartEncode - (void)setData:(SyncMLTagData *)_data { NSString *newStringData; NSRange range; [super setData:_data]; if ([[self->data stringdata] length]==0) return; if (self->meta==NULL) self->meta = [[SyncMLTagMeta alloc]init]; if ([[self->meta format]length]==0) [self->meta setFormat:SYNCML_FORMAT_CHR]; if ([[self->meta format]isEqual:SYNCML_FORMAT_CHR]) { range = [[self->data stringdata] rangeOfCharacterFromSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]]; if ( (range.location>0) && (range.location<[[self->data stringdata]length])) { // FIXME: Have absolutely no idea which encoding clients expect on // base64 encoded string data. UTF8 seems right and might work in // the most cases, but who knows? // OR at least, this what i WOULD like to to. // In reality, this crashes :( // newStringData = [[[self->data stringdata] // dataUsingEncodingNamed: NSUTF8StringEncoding] // stringByEncodingBase64]; newStringData = [[self->data stringdata] stringByEncodingBase64]; [self->meta setFormat:SYNCML_FORMAT_BASE64]; [self->data setStringdata:newStringData]; } } } @end /* SyncMLTagItemWithSmartEncode */