Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
Jianhui Zhao committed Jan 17, 2018
1 parent 82b2e3e commit ffa221f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
13 changes: 11 additions & 2 deletions example/helloworld.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libubox/ulog.h>

struct uwsc_client *gcl;
struct uloop_fd fd;
Expand Down Expand Up @@ -78,18 +79,20 @@ static void usage(const char *prog)
" -u url # ws://localhost:8080/ws\n"
" -c file # Load CA certificates from file\n"
" -n # don't validate the server's certificate\n"
" -v # verbose\n"
, prog);
exit(1);
}

int main(int argc, char **argv)
{
int opt;
static bool verify = true;
const char *url = "ws://localhost:8080/ws";
const char *crt_file = NULL;
bool verify = true;
bool verbose = false;

while ((opt = getopt(argc, argv, "u:nc:")) != -1) {
while ((opt = getopt(argc, argv, "u:nc:v")) != -1) {
switch (opt)
{
case 'u':
Expand All @@ -101,11 +104,17 @@ int main(int argc, char **argv)
case 'c':
crt_file = optarg;
break;
case 'v':
verbose = true;
break;
default: /* '?' */
usage(argv[0]);
}
}

if (!verbose)
ulog_threshold(LOG_ERR);

uloop_init();

gcl = uwsc_new_ssl(url, crt_file, verify);
Expand Down
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/config.h
${CMAKE_CURRENT_SOURCE_DIR}/uwsc.h
${CMAKE_CURRENT_SOURCE_DIR}/log.h
DESTINATION
include/uwsc
)
Expand Down
5 changes: 3 additions & 2 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "log.h"

#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>

#include "log.h"

void __uwsc_log(const char *filename, int line, int priority, const char *fmt, ...)
{
va_list ap;
Expand Down
18 changes: 18 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
/*
* Copyright (C) 2017 Jianhui Zhao <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "log.h"
#include "utils.h"

Expand Down
1 change: 1 addition & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <inttypes.h>
#include <stdbool.h>

#include "config.h"

#if (UWSC_SSL_SUPPORT)
Expand Down

0 comments on commit ffa221f

Please sign in to comment.