Skip to content

Commit

Permalink
ipops: clang-format for coherent indentation and coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed May 18, 2023
1 parent 874e915 commit f8c6f3d
Show file tree
Hide file tree
Showing 10 changed files with 8,264 additions and 7,028 deletions.
35 changes: 20 additions & 15 deletions src/modules/ipops/api.c
Expand Up @@ -26,8 +26,10 @@
#include "api.h"
#include "ip_parser.h"

extern int _compare_ips(char*, size_t, enum enum_ip_type, char*, size_t, enum enum_ip_type);
extern int _ip_is_in_subnet(char *ip1, size_t len1, enum enum_ip_type ip1_type, char *ip2, size_t len2, enum enum_ip_type ip2_type, int netmask);
extern int _compare_ips(
char *, size_t, enum enum_ip_type, char *, size_t, enum enum_ip_type);
extern int _ip_is_in_subnet(char *ip1, size_t len1, enum enum_ip_type ip1_type,
char *ip2, size_t len2, enum enum_ip_type ip2_type, int netmask);
/**
*
*/
Expand Down Expand Up @@ -62,7 +64,8 @@ int ipopsapi_compare_ips(const str *const ip1, const str *const ip2)
break;
}

if (_compare_ips(string1.s, string1.len, ip1_type, string2.s, string2.len, ip2_type))
if(_compare_ips(string1.s, string1.len, ip1_type, string2.s, string2.len,
ip2_type))
return 1;
else
return -1;
Expand Down Expand Up @@ -90,14 +93,15 @@ int ipopsapi_ip_is_in_subnet(const str *const ip1, const str *const ip2)
break;
}
cidr_pos = string2.s + string2.len - 1;
while (cidr_pos > string2.s)
{
if (*cidr_pos == '/') break;
while(cidr_pos > string2.s) {
if(*cidr_pos == '/')
break;
cidr_pos--;
}
if (cidr_pos == string2.s) return -1;
if(cidr_pos == string2.s)
return -1;
string2.len = (cidr_pos - string2.s);
netmask = atoi(cidr_pos+1);
netmask = atoi(cidr_pos + 1);
switch(ip2_type = ip_parser_execute(string2.s, string2.len)) {
case(ip_type_error):
return -1;
Expand All @@ -109,7 +113,8 @@ int ipopsapi_ip_is_in_subnet(const str *const ip1, const str *const ip2)
break;
}

if (_ip_is_in_subnet(string1.s, string1.len, ip1_type, string2.s, string2.len, ip2_type, netmask))
if(_ip_is_in_subnet(string1.s, string1.len, ip1_type, string2.s,
string2.len, ip2_type, netmask))
return 1;
else
return -1;
Expand All @@ -118,9 +123,9 @@ int ipopsapi_ip_is_in_subnet(const str *const ip1, const str *const ip2)
/**
*
*/
int ipopsapi_is_ip(const str * const ip)
int ipopsapi_is_ip(const str *const ip)
{
if (ip_parser_execute(ip->s, ip->len) != ip_type_error)
if(ip_parser_execute(ip->s, ip->len) != ip_type_error)
return 1;
else
return -1;
Expand All @@ -129,15 +134,15 @@ int ipopsapi_is_ip(const str * const ip)
/**
*
*/
int bind_ipops(ipops_api_t* api)
int bind_ipops(ipops_api_t *api)
{
if (!api) {
if(!api) {
ERR("Invalid parameter value\n");
return -1;
}
api->compare_ips = ipopsapi_compare_ips;
api->compare_ips = ipopsapi_compare_ips;
api->ip_is_in_subnet = ipopsapi_ip_is_in_subnet;
api->is_ip = ipopsapi_is_ip;
api->is_ip = ipopsapi_is_ip;

return 0;
}
20 changes: 10 additions & 10 deletions src/modules/ipops/api.h
Expand Up @@ -34,19 +34,20 @@ int ipopsapi_compare_ips(const str *const ip1, const str *const ip2);
typedef int (*ip_is_in_subnet_f)(const str *const, const str *const);
int ipopsapi_ip_is_in_subnet(const str *const ip1, const str *const ip2);

typedef int (*is_ip_f)(const str * const ip);
int ipopsapi_is_ip(const str * const ip);
typedef int (*is_ip_f)(const str *const ip);
int ipopsapi_is_ip(const str *const ip);
/**
* @brief IPOPS API structure
*/
typedef struct ipops_api {
compare_ips_f compare_ips;
ip_is_in_subnet_f ip_is_in_subnet;
is_ip_f is_ip;
typedef struct ipops_api
{
compare_ips_f compare_ips;
ip_is_in_subnet_f ip_is_in_subnet;
is_ip_f is_ip;
} ipops_api_t;

typedef int (*bind_ipops_f)(ipops_api_t* api);
int bind_ipops(ipops_api_t* api);
typedef int (*bind_ipops_f)(ipops_api_t *api);
int bind_ipops(ipops_api_t *api);

/**
* @brief Load the IPOPS API
Expand All @@ -60,8 +61,7 @@ static inline int ipops_load_api(ipops_api_t *api)
LM_ERR("cannot find bind_ipops\n");
return -1;
}
if (bindipops(api) < 0)
{
if(bindipops(api) < 0) {
LM_ERR("cannot bind ipops api\n");
return -1;
}
Expand Down

0 comments on commit f8c6f3d

Please sign in to comment.