]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/simpleUrlAccess/simpleUrlAccess.c
2 * URLSimpleDownload test, X version.
6 #include <Carbon/Carbon.h>
11 #define DEFAULT_HOST "gss.cdnow.com"
12 #define DEFAULT_PATH "/"
13 #define DEFAULT_SSL 0 /* 0 --> http, 1 --> https */
15 #define COMP_LENGTH 80
16 #define URL_LENGTH 256
19 /* shouldn't be needed if no kURLDisplayProgressFlag */
20 static void Initialize()
22 //InitGraf(&qd.thePort);
32 static time_t lastTime
= (time_t)0;
33 #define TIME_INTERVAL 3
35 * Just keep UI alive in case we want to quit the app
37 static pascal OSStatus
eventCallback(
41 time_t thisTime
= time(0);
43 if((thisTime
- lastTime
) >= TIME_INTERVAL
) {
44 printf("."); fflush(stdout
);
52 * Assuming *h contains ASCII text, dump it 'til the user cries uncle.
54 #define BYTES_PER_SPURT 128
60 Size bytesWritten
= 0;
69 totalBytes
= GetHandleSize(h
);
71 printf("*** Zero bytes obtained\n");
75 while(bytesWritten
< totalBytes
) {
76 thisWrite
= totalBytes
- bytesWritten
;
77 if(thisWrite
> BYTES_PER_SPURT
) {
78 thisWrite
= BYTES_PER_SPURT
;
80 for(i
=0; i
<thisWrite
; i
++) {
90 printf("%02X|", (unsigned)c
& 0xff);
94 totalBytes
+= thisWrite
;
95 if(totalBytes
== bytesWritten
) {
99 printf("\nMore (y/anything)? ");
113 char hostName
[COMP_LENGTH
];
114 char path
[COMP_LENGTH
];
115 char url
[URL_LENGTH
];
116 char scheme
[10]; /* http, https */
117 char isSsl
= DEFAULT_SSL
;
122 strcpy(hostName
, DEFAULT_HOST
);
123 strcpy(path
, DEFAULT_PATH
);
125 strcpy(scheme
, "https");
128 strcpy(scheme
, "http");
131 printf(" h Set Host (current = %s)\n", hostName
);
132 printf(" p Set path (current = %s)\n", path
);
133 printf(" s Set SSL true (current = %d)\n", isSsl
);
134 printf(" S Set SSL false\n");
135 printf(" g Get the URL\n");
137 printf("\nEnter command: ");
142 printf("Enter host name: ");
143 scanf("%s", hostName
);
146 printf("Enter path: ");
151 strcpy(scheme
, "https");
155 strcpy(scheme
, "http");
158 sprintf(url
, "%s://%s%s", scheme
, hostName
, path
);
159 printf("...url = %s\n", url
);
160 h
= NewHandle(0); /* what the spec says */
161 ortn
= URLSimpleDownload(url
,
164 0, //kURLDisplayProgressFlag, // URLOpenFlags
165 NULL
, //eventCallback,
166 NULL
); // userContext
168 printf("URLSimpleDownload returned %d\n", (int)ortn
);