example: rename callbacks
[project/uclient.git] / uclient-example.c
index 144696c00fd94a1c3f6486e07bdeb3197d9e3e58..9040f84fa7588e13fe6a4d5f5bb0b04e70aab2d9 100644 (file)
@@ -86,7 +86,7 @@ static int open_output_file(const char *path, bool create)
 
 static void request_done(struct uclient *cl)
 {
-       if (output_fd >= 0) {
+       if (output_fd >= 0 && !output_file) {
                close(output_fd);
                output_fd = -1;
        }
@@ -94,7 +94,7 @@ static void request_done(struct uclient *cl)
        uloop_end();
 }
 
-static void example_header_done(struct uclient *cl)
+static void header_done_cb(struct uclient *cl)
 {
        static int retries;
 
@@ -136,7 +136,7 @@ static void example_header_done(struct uclient *cl)
        }
 }
 
-static void example_read_data(struct uclient *cl)
+static void read_data_cb(struct uclient *cl)
 {
        char buf[256];
        int len;
@@ -173,7 +173,7 @@ static void init_request(struct uclient *cl)
        uclient_request(cl);
 }
 
-static void example_eof(struct uclient *cl)
+static void eof_cb(struct uclient *cl)
 {
        request_done(cl);
 }
@@ -213,9 +213,9 @@ static void handle_uclient_error(struct uclient *cl, int code)
 }
 
 static const struct uclient_cb cb = {
-       .header_done = example_header_done,
-       .data_read = example_read_data,
-       .data_eof = example_eof,
+       .header_done = header_done_cb,
+       .data_read = read_data_cb,
+       .data_eof = eof_cb,
        .error = handle_uclient_error,
 };
 
@@ -224,6 +224,7 @@ static int usage(const char *progname)
        fprintf(stderr,
                "Usage: %s [options] <URL>\n"
                "Options:\n"
+               "       -q:                             Turn off status messages\n"
                "       -O <file>:                      Redirect output to file (use \"-\" for stdout)\n"
                "\n"
                "HTTPS options:\n"
@@ -327,6 +328,9 @@ int main(int argc, char **argv)
 
        uclient_free(cl);
 
+       if (output_fd >= 0 && output_fd != STDOUT_FILENO)
+               close(output_fd);
+
        if (ssl_ctx)
                ssl_ops->context_free(ssl_ctx);