2
Copyright (C) 2000-2005 SKYRIX Software AG
4
This file is part of SOPE.
6
SOPE is free software; you can redistribute it and/or modify it under
7
the terms of the GNU Lesser General Public License as published by the
8
Free Software Foundation; either version 2, or (at your option) any
11
SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14
License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with SOPE; see the file COPYING. If not, write to the
18
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22
#include "iCalPublishAction.h"
23
#include "iCalPortalUser.h"
24
#include <NGObjWeb/WEClientCapabilities.h>
25
#include <NGMime/NGMime.h>
29
Publish Sequence in Outlook 2000 is:
30
a) post an empty request without creds => 401
31
b) post an empty request with creds => 200
32
c) post the full request with (validated) creds
35
@implementation iCalPublishAction
41
- (int)maxCalSizeForUser:(iCalPortalUser *)_user {
42
return 200 * 1024; /* 200K for now */
51
int okStatus = 201 /* created */;
53
if ((user = [self user]) == nil) {
59
r = [WOResponse responseWithRequest:[self request]];
61
/* check for OL 2000 (which does a "POST" to publish requests) */
63
if ([[rq method] isEqualToString:@"POST"]) {
64
/* could extract file name from content-disposition ... */
65
NGMimeMultipartBody *body;
68
okStatus = 200; /* override for OL 2K */
70
[self debugWithFormat:@"got a post from: %@",
71
[rq headerForKey:@"user-agent"]];
73
if ((body = [[rq httpRequest] body]) == nil)
75
else if (![body isKindOfClass:[NGMimeMultipartBody class]])
76
/* probably a bit strict ... */
81
if ((parts = [body parts]) == nil)
83
else if ([parts count] == 0)
88
part = [parts objectAtIndex:0];
94
[self debugWithFormat:@"but the content was empty, returning 200 !!!"];
100
data = [[self request] content];
102
/* process a "usual" PUT */
104
[self debugWithFormat:@"write calendar of user: %@", user];
105
[self debugWithFormat:@" url of: %@", [self requestUser]];
106
[self debugWithFormat:@" cal: %@", [self requestCalendarPath]];
108
if (data == nil) data = [[[NSData alloc] init] autorelease];
110
if ([data length] > [self maxCalSizeForUser:user]) {
111
[self logWithFormat:@"calendar to be published exceeds maximum size !"];
114
else if ((e = [user writeICalendarData:data
115
toCalendar:[self requestCalendarPath]])) {
117
[self logWithFormat:@"calendar upload failed: %@", e];
119
[r setStatus:500 /* server error */];
120
[r appendContentString:@"<h3>calendar upload failed !</h3>"];
121
[r appendContentHTMLString:[e description]];
124
WEClientCapabilities *cc;
126
cc = [[self request] clientCapabilities];
128
if ([cc isWebFolder]) {
129
[r setStatus:200 /* OK */];
132
/* 201 is generated by mod_dav, when iCal.app does a PUT */
133
[r setStatus:okStatus];
134
[r appendContentString:@"the calendar has been created ..."];
141
@end /* iCalPublishAction */