~ubuntu-branches/ubuntu/edgy/sope/edgy

« back to all changes in this revision

Viewing changes to sope-appserver/samples/iCalPortal/WebDAV/iCalPublishAction.m

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Ley
  • Date: 2005-08-19 16:53:31 UTC
  • Revision ID: james.westby@ubuntu.com-20050819165331-hs683wz1osm708pw
Tags: upstream-4.4rc.2
ImportĀ upstreamĀ versionĀ 4.4rc.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2000-2005 SKYRIX Software AG
 
3
 
 
4
  This file is part of SOPE.
 
5
 
 
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
 
9
  later version.
 
10
 
 
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.
 
15
 
 
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
 
19
  02111-1307, USA.
 
20
*/
 
21
 
 
22
#include "iCalPublishAction.h"
 
23
#include "iCalPortalUser.h"
 
24
#include <NGObjWeb/WEClientCapabilities.h>
 
25
#include <NGMime/NGMime.h>
 
26
#include "common.h"
 
27
 
 
28
/*
 
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
 
33
*/
 
34
 
 
35
@implementation iCalPublishAction
 
36
 
 
37
- (void)dealloc {
 
38
  [super dealloc];
 
39
}
 
40
 
 
41
- (int)maxCalSizeForUser:(iCalPortalUser *)_user {
 
42
  return 200 * 1024; /* 200K for now */
 
43
}
 
44
 
 
45
- (WOResponse *)run {
 
46
  WORequest      *rq;
 
47
  iCalPortalUser *user;
 
48
  WOResponse  *r;
 
49
  NSData      *data;
 
50
  NSException *e;
 
51
  int okStatus = 201 /* created */;
 
52
  
 
53
  if ((user = [self user]) == nil) {
 
54
    return nil;
 
55
  }
 
56
 
 
57
  rq = [self request];
 
58
  
 
59
  r = [WOResponse responseWithRequest:[self request]];
 
60
  
 
61
  /* check for OL 2000 (which does a "POST" to publish requests) */
 
62
  
 
63
  if ([[rq method] isEqualToString:@"POST"]) {
 
64
    /* could extract file name from content-disposition ... */
 
65
    NGMimeMultipartBody *body;
 
66
    BOOL isEmpty = NO;
 
67
    
 
68
    okStatus = 200; /* override for OL 2K */
 
69
    
 
70
    [self debugWithFormat:@"got a post from: %@",
 
71
            [rq headerForKey:@"user-agent"]];
 
72
    
 
73
    if ((body = [[rq httpRequest] body]) == nil)
 
74
      isEmpty = YES;
 
75
    else if (![body isKindOfClass:[NGMimeMultipartBody class]])
 
76
      /* probably a bit strict ... */
 
77
      isEmpty = YES;
 
78
    else {
 
79
      NSArray *parts;
 
80
 
 
81
      if ((parts = [body parts]) == nil)
 
82
        isEmpty = YES;
 
83
      else if ([parts count] == 0)
 
84
        isEmpty = YES;
 
85
      else {
 
86
        NGMimeBodyPart *part;
 
87
        
 
88
        part = [parts objectAtIndex:0];
 
89
        data = [part body];
 
90
      }
 
91
    }
 
92
    
 
93
    if (isEmpty) {
 
94
      [self debugWithFormat:@"but the content was empty, returning 200 !!!"];
 
95
      [r setStatus:200];
 
96
      return r;
 
97
    }
 
98
  }
 
99
  else
 
100
    data = [[self request] content];
 
101
  
 
102
  /* process a "usual" PUT */
 
103
  
 
104
  [self debugWithFormat:@"write calendar of user: %@", user];
 
105
  [self debugWithFormat:@"  url of: %@", [self requestUser]];
 
106
  [self debugWithFormat:@"  cal:    %@", [self requestCalendarPath]];
 
107
  
 
108
  if (data == nil) data = [[[NSData alloc] init] autorelease];
 
109
  
 
110
  if ([data length] > [self maxCalSizeForUser:user]) {
 
111
    [self logWithFormat:@"calendar to be published exceeds maximum size !"];
 
112
    [r setStatus:500];
 
113
  }
 
114
  else if ((e = [user writeICalendarData:data
 
115
                      toCalendar:[self requestCalendarPath]])) {
 
116
    /* failed */
 
117
    [self logWithFormat:@"calendar upload failed: %@", e];
 
118
    
 
119
    [r setStatus:500 /* server error */];
 
120
    [r appendContentString:@"<h3>calendar upload failed !</h3>"];
 
121
    [r appendContentHTMLString:[e description]];
 
122
  }
 
123
  else {
 
124
    WEClientCapabilities *cc;
 
125
    
 
126
    cc = [[self request] clientCapabilities];
 
127
    
 
128
    if ([cc isWebFolder]) {
 
129
      [r setStatus:200 /* OK */];
 
130
    }
 
131
    else {
 
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 ..."];
 
135
    }
 
136
  }
 
137
  
 
138
  return r;
 
139
}
 
140
 
 
141
@end /* iCalPublishAction */