vvopensource
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Groups Pages
VVCURLDL.h
1 
2 /*
3  this class offers a very limited, very simple cocoa interface to libcurl for doing extremely
4  basic http transfer ops
5 
6  basically, this class exists because at this time NSURLConnection is problematic and
7  top-heavy, and i wanted an easy, effective, and reliable interface for handling the extremely
8  limited set of http data transfer operations required by my frameworks/apps.
9 
10  this class was meant to be used as a one-shot throwaway; that is, you're meant to create an
11  instance of this class which will be auto-released as soon as the autorelease pool is
12  popped. the instance you create is meant to be used once, and then thrown away- THIS WILL
13  PROBABLY BREAK IF YOU TRY TO USE THE SAME INSTANCE TO PERFORM MORE THAN ONE TRANSFER.
14 */
15 
16 
17 #import <Cocoa/Cocoa.h>
18 #import <curl/curl.h>
19 
20 
21 
22 
23 @protocol VVCURLDLDelegate
24 - (void) dlFinished:(id)h;
25 @end
26 
27 
28 
29 
30 @interface VVCURLDL : NSObject {
31  NSString *urlString;
32  CURL *curlHandle;
33 
34  NSString *log;
35  NSString *pass;
36 
37  NSMutableData *responseData;
38 
39  struct curl_slist *headerList; // nil by default- if non-nil, supplied to the handle as CURLOPT_HTTPHEADER
40  NSMutableData *postData; // if non-nil, simply posted as CURLOPT_POSTFIELDS
41  struct curl_httppost *firstFormPtr; // if postData was nil but this isn't, posted as CURLOPT_HTTPPOST
42  struct curl_httppost *lastFormPtr;
43 
44  BOOL returnOnMain;
45  BOOL performing;
46  CURLcode err;
47 }
48 
49 + (id) createWithAddress:(NSString *)a;
50 - (id) initWithAddress:(NSString *)a;
51 
52 - (void) perform;
53 - (void) performAsync:(BOOL)as withDelegate:(id <VVCURLDLDelegate>)d;
54 - (void) _performAsyncWithDelegate:(id <VVCURLDLDelegate>)d;
55 - (void) _performWithDelegate:(id <VVCURLDLDelegate>)d;
56 
57 - (void) performAsync:(BOOL)as withBlock:(void (^)(VVCURLDL *completedDL))b;
58 - (void) _performAsyncWithBlock:(void (^)(VVCURLDL *completedDL))b;
59 - (void) _performWithBlock:(void (^)(VVCURLDL *completedDL))b;
60 
61 - (void) _execute;
62 
63 //- (struct curl_slist *) headerList;
64 //- (struct curl_httppost *) firstFormPtr;
65 //- (struct curl_httppost *) lastFormPtr;
66 - (void) appendDataToPOST:(NSData *)d;
67 - (void) appendStringToPOST:(NSString *)s;
68 - (void) setLogin:(NSString *)user password:(NSString *)pass;
69 
70 - (void) writePtr:(void *)ptr size:(size_t)s;
71 - (void) appendStringToHeader:(NSString *)s;
72 - (void) addFormNSString:(NSString *)s forName:(NSString *)n;
73 - (void) addFormZipData:(NSData *)d forName:(NSString *)n;
74 
75 @property (assign,readwrite) struct curl_slist *headerList;
76 @property (assign,readwrite) struct curl_httppost *firstFormPtr;
77 @property (assign,readwrite) struct curl_httppost *lastFormPtr;
78 @property (assign,readwrite) BOOL returnOnMain;
79 @property (readonly) NSMutableData *responseData;
80 @property (readonly) NSString *responseString;
81 @property (readonly) CURLcode err;
82 
83 @end
84 
85 size_t vvcurlWriteFunction(void *ptr, size_t size, size_t nmemb, void *stream);