Refactoring

This commit is contained in:
Ahmed Yarub Hani Al Nuaimi
2021-09-09 10:08:30 -03:00
parent a552d1cc95
commit 9271886c7d
6 changed files with 40 additions and 28 deletions

View File

@@ -16,7 +16,8 @@ list(APPEND SRCS
watch/watch_util.c watch/watch_util.c
websocket/wsclient.c websocket/wsclient.c
websocket/kube_exec.c websocket/kube_exec.c
src/generic.c) src/generic.c
src/utils.c)
list(APPEND HDRS list(APPEND HDRS
config/kube_config_common.h config/kube_config_common.h
@@ -31,7 +32,8 @@ list(APPEND HDRS
watch/watch_util.h watch/watch_util.h
websocket/wsclient.h websocket/wsclient.h
websocket/kube_exec.h websocket/kube_exec.h
include/generic.h) include/generic.h
src/utils.c)
find_package(libwebsockets CONFIG REQUIRED) find_package(libwebsockets CONFIG REQUIRED)
find_package(yaml CONFIG REQUIRED) find_package(yaml CONFIG REQUIRED)

View File

@@ -1,5 +1,6 @@
#include "authn_plugin_util.h" #include "authn_plugin_util.h"
#include <errno.h> #include <errno.h>
#include "include/utils.h"
int shc_request(char **p_http_response, int *p_http_response_length, char *type, const char *url, sslConfig_t * sc, list_t * apiKeys, list_t * contentType, char *post_data) int shc_request(char **p_http_response, int *p_http_response_length, char *type, const char *url, sslConfig_t * sc, list_t * apiKeys, list_t * contentType, char *post_data)
{ {

View File

@@ -14,10 +14,6 @@ typedef struct genericClient_t {
char *resourcePlural; char *resourcePlural;
} genericClient_t; } genericClient_t;
#if !defined(HAVE_STRNDUP)
char *strndup(const char *s, size_t n);
#endif /* ! HAVE_STRNDUP */
genericClient_t* genericClient_create(apiClient_t *client, const char *apiGroup, const char* apiVersion, const char* resourcePlural); genericClient_t* genericClient_create(apiClient_t *client, const char *apiGroup, const char* apiVersion, const char* resourcePlural);
void genericClient_free(genericClient_t* client); void genericClient_free(genericClient_t* client);

View File

@@ -0,0 +1,9 @@
#ifndef UTILS_HPP
#define UTILS_HPP
#if !defined(HAVE_STRNDUP)
char *strndup(const char *s, size_t n);
#endif /* ! HAVE_STRNDUP */
#endif //UTILS_HPP

View File

@@ -1,27 +1,6 @@
#include "../include/apiClient.h" #include "../include/apiClient.h"
#include "../include/generic.h" #include "../include/generic.h"
#include "../include/utils.h"
// based on https://github.com/libssh/libssh-mirror/commit/247983e9820fd264cb5a59c14cc12846c028bd08#diff-744295d01685fa411dbfd78679ea20b51dfa4ac7d2d722df53f3d86d728493f8
#if !defined(HAVE_STRNDUP)
char *strndup(const char *s, size_t n)
{
char *x = NULL;
if (n + 1 < n) {
return NULL;
}
x = malloc(n + 1);
if (x == NULL) {
return NULL;
}
memcpy(x, s, n);
x[n] = '\0';
return x;
}
#endif /* ! HAVE_STRNDUP */
genericClient_t* genericClient_create(apiClient_t *client, const char *apiGroup, const char* apiVersion, const char* resourcePlural) { genericClient_t* genericClient_create(apiClient_t *client, const char *apiGroup, const char* apiVersion, const char* resourcePlural) {
genericClient_t *result = malloc(sizeof(genericClient_t)); genericClient_t *result = malloc(sizeof(genericClient_t));

25
kubernetes/src/utils.c Normal file
View File

@@ -0,0 +1,25 @@
#include <stdlib.h>
#include "../include/utils.h"
#include <string.h>
// based on https://github.com/libssh/libssh-mirror/commit/247983e9820fd264cb5a59c14cc12846c028bd08#diff-744295d01685fa411dbfd78679ea20b51dfa4ac7d2d722df53f3d86d728493f8
#if !defined(HAVE_STRNDUP)
char *strndup(const char *s, size_t n)
{
char *x = NULL;
if (n + 1 < n) {
return NULL;
}
x = malloc(n + 1);
if (x == NULL) {
return NULL;
}
memcpy(x, s, n);
x[n] = '\0';
return x;
}
#endif /* ! HAVE_STRNDUP */