-
Notifications
You must be signed in to change notification settings - Fork 0
/
OCGICookie.m
100 lines (84 loc) · 2.85 KB
/
OCGICookie.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#import <Foundation/Foundation.h>
#import "NSNumber+OCGIFormResultType.h"
#import "OCGIEncoding.h"
#import "OCGICookie.h"
@implementation OCGICookie
+(NSDictionary *) stringBy:(NSString *)name length:(NSNumber *)max
{
char *result = \
(char *) malloc(sizeof(char) * ([max intValue] + 1));
if (!result)
return nil;
result[0] = '\0';
cgiFormResultType status = \
cgiCookieString(
(char *)[name cStringUsingEncoding:OCGI_ENCODING],
result, [max intValue]);
NSDictionary *out = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithOCGIFormResultType:status], @"status",
[NSString stringWithCString:result encoding:OCGI_ENCODING], @"result",
nil];
if (!out) {
free(result);
return nil;
}
free(result);
return out;
}
+(NSDictionary *) integerBy:(NSString *)name defaultValue:(NSNumber *)defaultV
{
int *result = (int *) malloc(sizeof(int));
if (!result)
return nil;
cgiFormResultType status = \
cgiCookieInteger(
(char *)[name cStringUsingEncoding:OCGI_ENCODING],
result,
[defaultV intValue]);
int _result = *result;
NSDictionary *out = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithOCGIFormResultType:status], @"status",
[NSNumber numberWithInt:_result], @"result", nil];
if (!out) {
free(result);
return nil;
}
free(result);
return out;
}
+(void) setStringBy:(NSString *)name to:(NSString *)value \
toLive:(NSNumber *)secondsToLive \
path:(NSString *)path domain:(NSString *)domain \
options:(OCGI_COOKIE_OPTIONS) options
{
cgiHeaderCookieSet(
(char *)[name cStringUsingEncoding:OCGI_ENCODING],
(char *)[value cStringUsingEncoding:OCGI_ENCODING],
[secondsToLive intValue],
(char *)[path cStringUsingEncoding:OCGI_ENCODING],
(char *)[domain cStringUsingEncoding:OCGI_ENCODING],
options);
}
+(void) setStringBy:(NSString *)name to:(NSString *)value \
toLive:(NSNumber *)secondsToLive \
path:(NSString *)path domain:(NSString *)domain
{
cgiHeaderCookieSetString(
(char *)[name cStringUsingEncoding:OCGI_ENCODING],
(char *)[value cStringUsingEncoding:OCGI_ENCODING],
[secondsToLive intValue],
(char *)[path cStringUsingEncoding:OCGI_ENCODING],
(char *)[domain cStringUsingEncoding:OCGI_ENCODING]);
}
+(void) setIntegerBy:(NSString *)name to:(NSNumber *)value \
toLive:(NSNumber *)secondsToLive \
path:(NSString *)path domain:(NSString *)domain
{
cgiHeaderCookieSetInteger(
(char *)[name cStringUsingEncoding:OCGI_ENCODING],
[value intValue],
[secondsToLive intValue],
(char *)[path cStringUsingEncoding:OCGI_ENCODING],
(char *)[domain cStringUsingEncoding:OCGI_ENCODING]);
}
@end