tls_buffer_append(hdr, "\r\n", 2);
}
+char *pathlast(char *path) {
+ char *last = 0;
+ size_t len = 0;
+
+ if (path == 0) {
+ return 0;
+ }
+
+ while (*path == '/') {
+ path++;
+ }
+
+ do {
+ last = path;
+ len = 0;
+ while (*path && *path != '/') {
+ path++;
+ len++;
+ }
+ while (*path == '/') {
+ path++;
+ }
+ } while (*path);
+
+ if (len == 0) {
+ return 0;
+ }
+
+ return strndup(last, len);
+}
+
int main(int ac, char *av[]) {
int sockfd, port = -1, rv;
ssize_t ret;
#endif
char *req_file = 0;
char *host = 0;
- struct tls_uri uri;
+ struct tls_uri uri = { 0 };
char *outfile = 0;
int raw = 0, head = 0;
int out = 1;
size_t header_len;
char *url = 0;
int redirs = 0, redirlimit = 50, printstatus = 0;
- int verifypolicy = 1;
+ int verifypolicy = 1, calcoutfile = 0;
ltc_mp = tfm_desc;
- while ((option = getopt(ac, av, "o:rIfz:#R:SkK")) != -1) {
+ while ((option = getopt(ac, av, "o:OrIfz:#R:SkK")) != -1) {
switch (option) {
case 'o': outfile = optarg; break;
+ case 'O': calcoutfile = 1; break;
case 'S': printstatus = 1; head = 1; break;
case 'k': verifypolicy = 0; break;
case 'K': verifypolicy = 2; break;
exit(EXIT_FAILURE);
}
+ if (calcoutfile && !outfile) {
+ tls_parse_uri(url, &uri);
+ outfile = pathlast(uri.path);
+ /* outfile leaks memory here, so if this
+ * were turned into a library function,
+ * we'd need to track it
+ */
+ if (!outfile) {
+ fprintf(stderr, "unable to determine outfile\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+
if (outfile) {
out = open(outfile, O_WRONLY|O_CREAT, 0600);
if (out == -1) {
port = atoi(uri.port);
req_file = uri.path;
+
/* construct request */
if (head) {
tls_buffer_append(&request, "HEAD ", 5);