Revision ca7626d7

b/asi-http-request-with-pithos/Classes/Pithos/ASIPithosObject.h
59 59
    NSString *allowedTo;
60 60
    
61 61
    NSData *data;
62
    
63
    NSMutableArray *permissions;
64

  
62 65
}
63 66

  
64 67
@property (assign) BOOL subdir;
......
76 79
@property (strong) NSDate *versionTimestamp;
77 80
@property (strong) NSString *modifiedBy;
78 81
@property (strong) NSString *manifest;
79
@property (strong) NSString *sharing;
82
@property (nonatomic, strong) NSString *sharing;
80 83
@property (strong) NSString *sharedBy;
81 84
@property (strong) NSString *publicURI;
82 85
@property (strong) NSMutableDictionary *metadata;
83 86
@property (strong) NSString *allowedTo;
84 87
@property (strong) NSData *data;
88
@property (nonatomic, strong) NSMutableArray *permissions;
85 89

  
86 90
+ (id)object;
87 91
+ (id)subdirWithName:(NSString *)name;
b/asi-http-request-with-pithos/Classes/Pithos/ASIPithosObject.m
35 35
// or implied, of GRNET S.A.
36 36

  
37 37
#import "ASIPithosObject.h"
38
#import "ASIPithosSharingUser.h"
38 39

  
39 40
@implementation ASIPithosObject
40 41
@synthesize subdir;
41 42
@synthesize name, hash, objectHash, UUID, bytes, contentType, contentEncoding, contentDisposition, lastModified, 
42 43
version, versionTimestamp, modifiedBy, manifest, sharing, sharedBy, publicURI, metadata, allowedTo, 
43
data;
44
data, permissions;
44 45

  
45 46
+ (id)object {
46 47
	ASIPithosObject *object = [[self alloc] init];
......
62 63
            name, hash, objectHash, UUID, bytes, contentType, contentEncoding, contentDisposition, lastModified, version, versionTimestamp, modifiedBy, manifest, sharing, sharedBy, publicURI, metadata, allowedTo];
63 64
}
64 65

  
66
- (void)setSharing:(NSString *)aSharing {
67
    if (!aSharing || ![aSharing isEqualToString:sharing]) {
68
        permissions = nil;
69
    }
70
    sharing = aSharing;
71
}
72

  
73
- (NSMutableArray *)permissions {
74
    if (!permissions) {
75
        NSMutableArray *newPermissions = [NSMutableArray array];
76
        if (self.sharing.length) {
77
            for (NSString *sharingList in [self.sharing componentsSeparatedByString:@";"]) {
78
                NSRange equalsRange = [sharingList rangeOfString:@"="];
79
                if (equalsRange.location != NSNotFound) {
80
                    NSString *sharingType = [sharingList substringToIndex:equalsRange.location];
81
                    if ([sharingType hasPrefix:@" "]) {
82
                        sharingType = [sharingType substringFromIndex:1];
83
                    }
84
                    for (NSString *sharingUser in [[sharingList substringFromIndex:(equalsRange.location + 1)] componentsSeparatedByString:@","]) {
85
                        [newPermissions addObject:[ASIPithosSharingUser sharingUserWithUser:sharingUser permission:sharingType]];
86
                    }
87
                }
88
            }
89
        }
90
        permissions = newPermissions;
91
    }
92
    return permissions;
93
}
94

  
95
- (void)setPermissions:(NSMutableArray *)aPermissions {
96
    if (!aPermissions || ![aPermissions isEqualToArray:permissions]) {
97
        if (aPermissions.count) {
98
            NSMutableDictionary *sharingListsDictionary = [NSMutableDictionary dictionary];
99
            for (ASIPithosSharingUser *sharingUser in aPermissions) {
100
                if (sharingUser.permission) {
101
                    NSMutableString *sharingList = [sharingListsDictionary objectForKey:sharingUser.permission];
102
                    if (!sharingList) {
103
                        sharingList = [NSMutableString stringWithFormat:@"%@=", sharingUser.permission];
104
                        [sharingListsDictionary setObject:sharingList forKey:sharingUser.permission];
105
                    }
106
                    if (sharingUser.name) {
107
                        if (sharingUser.group) {
108
                            [sharingList appendFormat:@"%@:%@,", sharingUser.name, sharingUser.group];
109
                        } else {
110
                            [sharingList appendFormat:@"%@,", sharingUser.name];
111
                        }
112
                    }
113
                }
114
            }
115
            NSMutableString *newSharing = [NSMutableString string];
116
            for (NSMutableString *sharingList in [sharingListsDictionary objectEnumerator]) {
117
                [newSharing appendFormat:@"%@;", [sharingList substringToIndex:(sharingList.length - 1)]];
118
            }
119
            self.sharing = [newSharing substringToIndex:(newSharing.length - 1)];
120
        } else {
121
            self.sharing = nil;
122
        }
123
    }
124
    permissions = aPermissions;
125
}
65 126

  
66 127
@end
b/asi-http-request-with-pithos/Classes/Pithos/ASIPithosRequest.m
134 134
}
135 135

  
136 136
- (NSDictionary *)catalogs {
137
    SBJsonParser *parser = [[SBJsonParser alloc] init];
137
    SBJsonParser *parser = [[[SBJsonParser alloc] init] autorelease];
138 138
    NSDictionary *catalogs = [parser objectWithString:[self responseString]];
139 139
    return catalogs;
140 140
}
b/asi-http-request-with-pithos/Classes/Pithos/ASIPithosSharingUser.h
1
//  ASIPithosSharingUser.h
2
//  pithos-macos
3
//
4
// Copyright 2013 GRNET S.A. All rights reserved.
5
//
6
// Redistribution and use in source and binary forms, with or
7
// without modification, are permitted provided that the following
8
// conditions are met:
9
// 
10
//   1. Redistributions of source code must retain the above
11
//      copyright notice, this list of conditions and the following
12
//      disclaimer.
13
// 
14
//   2. Redistributions in binary form must reproduce the above
15
//      copyright notice, this list of conditions and the following
16
//      disclaimer in the documentation and/or other materials
17
//      provided with the distribution.
18
// 
19
// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
20
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
23
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
// POSSIBILITY OF SUCH DAMAGE.
31
// 
32
// The views and conclusions contained in the software and
33
// documentation are those of the authors and should not be
34
// interpreted as representing official policies, either expressed
35
// or implied, of GRNET S.A.
36

  
37
#import <Foundation/Foundation.h>
38

  
39
@interface ASIPithosSharingUser : NSObject <NSCopying> {
40
	NSString *name;
41
    NSString *group;
42
    NSString *permission;
43
}
44

  
45
@property (strong) NSString *name;
46
@property (strong) NSString *group;
47
@property (strong) NSString *permission;
48

  
49
+ (id)sharingUser;
50
+ (id)sharingUserWithName:(NSString *)aName group:(NSString *)aGroup permission:(NSString *)aPermission;
51
+ (id)sharingUserWithUser:(NSString *)aUser permission:(NSString *)aPermission;
52

  
53
@end
b/asi-http-request-with-pithos/Classes/Pithos/ASIPithosSharingUser.m
1
//  ASIPithosSharingUser.m
2
//  pithos-macos
3
//
4
// Copyright 2013 GRNET S.A. All rights reserved.
5
//
6
// Redistribution and use in source and binary forms, with or
7
// without modification, are permitted provided that the following
8
// conditions are met:
9
// 
10
//   1. Redistributions of source code must retain the above
11
//      copyright notice, this list of conditions and the following
12
//      disclaimer.
13
// 
14
//   2. Redistributions in binary form must reproduce the above
15
//      copyright notice, this list of conditions and the following
16
//      disclaimer in the documentation and/or other materials
17
//      provided with the distribution.
18
// 
19
// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
20
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
23
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27
// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29
// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
// POSSIBILITY OF SUCH DAMAGE.
31
// 
32
// The views and conclusions contained in the software and
33
// documentation are those of the authors and should not be
34
// interpreted as representing official policies, either expressed
35
// or implied, of GRNET S.A.
36

  
37
#import "ASIPithosSharingUser.h"
38

  
39
@implementation ASIPithosSharingUser
40
@synthesize name, group, permission;
41

  
42
+ (id)sharingUser {
43
	ASIPithosSharingUser *sharingUser = [[self alloc] init];
44
	return sharingUser;
45
}
46

  
47
+ (id)sharingUserWithName:(NSString *)aName group:(NSString *)aGroup permission:(NSString *)aPermission {
48
    ASIPithosSharingUser *sharingUser = [[self alloc] init];
49
    sharingUser.name = aName;
50
    sharingUser.group = aGroup;
51
    sharingUser.permission = aPermission;
52
    return sharingUser;
53
}
54

  
55
+ (id)sharingUserWithUser:(NSString *)aUser permission:(NSString *)aPermission {
56
    NSRange colonRange = [aUser rangeOfString:@":"];
57
    if (colonRange.location == NSNotFound) {
58
        return [self sharingUserWithName:aUser group:nil permission:aPermission];
59
    } else if (colonRange.location != aUser.length - 1) {
60
        return [self sharingUserWithName:[aUser substringToIndex:colonRange.location]
61
                                   group:[aUser substringFromIndex:(colonRange.location + 1)]
62
                              permission:aPermission];
63
    } else {
64
        return [self sharingUserWithName:[aUser substringToIndex:colonRange.location] group:nil permission:aPermission];
65
    }
66
}
67

  
68
- (id)copyWithZone:(NSZone *)zone {
69
    return [ASIPithosSharingUser sharingUserWithName:[name copy]
70
                                               group:[group copy]
71
                                          permission:[permission copy]];
72
}
73

  
74
@end

Also available in: Unified diff