/*-------------------------------------------------- FUNCTION: httpc_close_free DESC: Close and free the given http client object. ----------------------------------------------------*/ void httpc_close_free(httpc_conn_t * conn) { if (conn == NULL) return; hsocket_close(&(conn->sock)); httpc_free(conn); return; }
int main(int argc, char **argv) { httpc_conn_t *conn; /* Client connection object */ hresponse_t *res; /* Response object **/ herror_t status; FILE *f; size_t size; char url[50], file[50], id[50], content_type[50]; char buffer[MAX_BUFFER_SIZE+1]; /* Check usage */ if (argc < 5) { fprintf(stderr, "usage %s <url> <file> <id> <content-type>\n", argv[0]); exit(1); } /* Set log level to see more information written by the library */ // log_set_level(NANOHTTP_LOG_VERBOSE); /* Initialize httpc module */ if ((status = httpc_init(argc, argv)) != H_OK) { fprintf(stderr, "Cannot init httpc (%s)\n", herror_message(status)); herror_release(status); return 1; } /* Create the client connection object */ conn = httpc_new(); httpc_set_header(conn, HEADER_TRANSFER_ENCODING, TRANSFER_ENCODING_CHUNKED); /* Open connection for mime */ if ((status = httpc_mime_begin(conn, argv[1], argv[3], "", argv[4])) != H_OK) { fprintf(stderr, "Can not start MIME: %s\n", herror_message(status)); herror_release(status); exit(1); } if (!send_file(conn, argv[2], argv[3], argv[4])) { fprintf(stderr, "send_file failed\n"); exit(1); } while (1) { printf("Enter filename ['.' for finish]: "); gets(file); if (!strcmp(file, ".")) break; printf("Enter part id:"); gets(id); printf("Enter content-type:"); gets(content_type); if (!send_file(conn, file, id, content_type)) exit(1); } if ((status = httpc_mime_end(conn, &res)) != H_OK) { fprintf(stderr, "httpc_mime_end failed (%s)\n", herror_message(status)); herror_release(status); exit(1); } /* Show response */ show_response(res); /* clean up*/ hresponse_free(res); httpc_free(conn); return 0; }