mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-19 22:46:14 -05:00
style: format code for consistency and readability
This commit is contained in:
4 files changed
+37
-23
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
BasedOnStyle: LLVM
|
||||||
|
IndentWidth: 8
|
||||||
|
TabWidth: 8
|
||||||
|
UseTab: Always
|
||||||
|
ColumnLimit: 80
|
||||||
|
BreakBeforeBraces: Linux
|
||||||
@@ -8,5 +8,9 @@ end_of_line = lf
|
|||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[{*.c,*.h}]
|
||||||
|
indent_style = tab
|
||||||
|
indent_size = 8
|
||||||
|
|
||||||
[{Makefile,Makefile.in}]
|
[{Makefile,Makefile.in}]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
|
#include <openconnect.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/utsname.h>
|
#include <sys/utsname.h>
|
||||||
#include <openconnect.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "vpn.h"
|
#include "vpn.h"
|
||||||
|
|
||||||
@@ -15,14 +15,16 @@ static const char *g_vpnc_interface;
|
|||||||
static vpn_connected_callback on_vpn_connected;
|
static vpn_connected_callback on_vpn_connected;
|
||||||
|
|
||||||
/* Validate the peer certificate */
|
/* Validate the peer certificate */
|
||||||
static int validate_peer_cert(__attribute__((unused)) void *_vpninfo, const char *reason)
|
static int validate_peer_cert(__attribute__((unused)) void *_vpninfo,
|
||||||
|
const char *reason)
|
||||||
{
|
{
|
||||||
INFO("Accepting the server certificate though %s", reason);
|
INFO("Accepting the server certificate though %s", reason);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print progress messages */
|
/* Print progress messages */
|
||||||
static void print_progress(__attribute__((unused)) void *_vpninfo, int level, const char *format, ...)
|
static void print_progress(__attribute__((unused)) void *_vpninfo, int level,
|
||||||
|
const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
@@ -39,7 +41,8 @@ static void print_progress(__attribute__((unused)) void *_vpninfo, int level, co
|
|||||||
|
|
||||||
static void setup_tun_handler(void *_vpninfo)
|
static void setup_tun_handler(void *_vpninfo)
|
||||||
{
|
{
|
||||||
int ret = openconnect_setup_tun_device(_vpninfo, g_vpnc_script, g_vpnc_interface);
|
int ret = openconnect_setup_tun_device(_vpninfo, g_vpnc_script,
|
||||||
|
g_vpnc_interface);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
on_vpn_connected(g_cmd_pipe_fd, g_user_data);
|
on_vpn_connected(g_cmd_pipe_fd, g_user_data);
|
||||||
}
|
}
|
||||||
@@ -68,7 +71,9 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
|||||||
INFO("NO_DTLS: %d", options->no_dtls);
|
INFO("NO_DTLS: %d", options->no_dtls);
|
||||||
INFO("DPD_INTERVAL: %d", options->dpd_interval);
|
INFO("DPD_INTERVAL: %d", options->dpd_interval);
|
||||||
|
|
||||||
vpninfo = openconnect_vpninfo_new(options->user_agent, validate_peer_cert, NULL, NULL, print_progress, NULL);
|
vpninfo =
|
||||||
|
openconnect_vpninfo_new(options->user_agent, validate_peer_cert,
|
||||||
|
NULL, NULL, print_progress, NULL);
|
||||||
|
|
||||||
if (!vpninfo) {
|
if (!vpninfo) {
|
||||||
ERROR("openconnect_vpninfo_new failed");
|
ERROR("openconnect_vpninfo_new failed");
|
||||||
@@ -87,7 +92,8 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
|||||||
|
|
||||||
if (options->certificate) {
|
if (options->certificate) {
|
||||||
INFO("Setting client certificate: %s", options->certificate);
|
INFO("Setting client certificate: %s", options->certificate);
|
||||||
openconnect_set_client_cert(vpninfo, options->certificate, options->sslkey);
|
openconnect_set_client_cert(vpninfo, options->certificate,
|
||||||
|
options->sslkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->key_password) {
|
if (options->key_password) {
|
||||||
@@ -95,7 +101,8 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (options->csd_wrapper) {
|
if (options->csd_wrapper) {
|
||||||
openconnect_setup_csd(vpninfo, options->csd_uid, 1, options->csd_wrapper);
|
openconnect_setup_csd(vpninfo, options->csd_uid, 1,
|
||||||
|
options->csd_wrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->mtu > 0) {
|
if (options->mtu > 0) {
|
||||||
@@ -135,7 +142,8 @@ int vpn_connect(const vpn_options *options, vpn_connected_callback callback)
|
|||||||
openconnect_set_setup_tun_handler(vpninfo, setup_tun_handler);
|
openconnect_set_setup_tun_handler(vpninfo, setup_tun_handler);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
int ret = openconnect_mainloop(vpninfo, options->reconnect_timeout, 10);
|
int ret = openconnect_mainloop(vpninfo,
|
||||||
|
options->reconnect_timeout, 10);
|
||||||
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
INFO("openconnect_mainloop returned %d, exiting", ret);
|
INFO("openconnect_mainloop returned %d, exiting", ret);
|
||||||
@@ -155,6 +163,7 @@ void vpn_disconnect()
|
|||||||
INFO("Stopping VPN connection: %d", g_cmd_pipe_fd);
|
INFO("Stopping VPN connection: %d", g_cmd_pipe_fd);
|
||||||
|
|
||||||
if (write(g_cmd_pipe_fd, &cmd, 1) < 0) {
|
if (write(g_cmd_pipe_fd, &cmd, 1) < 0) {
|
||||||
ERROR("Failed to write to command pipe, VPN connection may not be stopped");
|
ERROR("Failed to write to command pipe, VPN connection may not "
|
||||||
|
"be stopped");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
|
#include <openconnect.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
|
||||||
#include <openconnect.h>
|
|
||||||
|
|
||||||
typedef void (*vpn_connected_callback)(int cmd_pipe_fd, void *user_data);
|
typedef void (*vpn_connected_callback)(int cmd_pipe_fd, void *user_data);
|
||||||
|
|
||||||
typedef struct vpn_options
|
typedef struct vpn_options {
|
||||||
{
|
|
||||||
void *user_data;
|
void *user_data;
|
||||||
const char *server;
|
const char *server;
|
||||||
const char *cookie;
|
const char *cookie;
|
||||||
@@ -43,9 +42,8 @@ static char *format_message(const char *format, va_list args)
|
|||||||
int len = vsnprintf(NULL, 0, format, args_copy);
|
int len = vsnprintf(NULL, 0, format, args_copy);
|
||||||
va_end(args_copy);
|
va_end(args_copy);
|
||||||
|
|
||||||
char *buffer = (char*)malloc(len + 1);
|
char *buffer = (char *)malloc(len + 1);
|
||||||
if (buffer == NULL)
|
if (buffer == NULL) {
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,12 +61,9 @@ static void _log(int level, ...)
|
|||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
if (message == NULL)
|
if (message == NULL) {
|
||||||
{
|
|
||||||
vpn_log(PRG_ERR, "Failed to format log message");
|
vpn_log(PRG_ERR, "Failed to format log message");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
vpn_log(level, message);
|
vpn_log(level, message);
|
||||||
free(message);
|
free(message);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user