Skip to content

Commit

Permalink
seas: 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 7c94156 commit ba2cbf2
Show file tree
Hide file tree
Showing 45 changed files with 6,071 additions and 5,544 deletions.
268 changes: 136 additions & 132 deletions src/modules/seas/cluster.c
Expand Up @@ -29,9 +29,10 @@

char *cluster_cfg;

#define eat_spaces(_p) \
while( *(_p)==' ' || *(_p)=='\t' ){\
(_p)++;}
#define eat_spaces(_p) \
while(*(_p) == ' ' || *(_p) == '\t') { \
(_p)++; \
}


/**
Expand All @@ -48,136 +49,139 @@ char *cluster_cfg;
*/
int parse_cluster_cfg(void)
{
char *p,*start;
int n,k;
struct as_entry **entry,*tmp,*tmp2;
char *p, *start;
int n, k;
struct as_entry **entry, *tmp, *tmp2;

if((p=cluster_cfg)==0 || *cluster_cfg==0){
return 0;
}
entry=&as_list;
if((p = cluster_cfg) == 0 || *cluster_cfg == 0) {
return 0;
}
entry = &as_list;

while (*p)
{
eat_spaces(p);
/*get cluster name*/
start = p;
while (*p!=' ' && *p!='\t' && *p!='[' && *p!=0)
p++;
if ( p==start || *p==0 ){
LM_ERR("cluster names must only contain alphanumeric chars\n");
goto error;
}
if (!((*entry)=(struct as_entry*)shm_malloc(sizeof(struct as_entry)))) {
LM_ERR("Out of shm mem for as_entry\n");
goto error;
}
memset(*entry,0,sizeof(struct as_entry));
if (!((*entry)->name.s=shm_malloc(p-start))) {
LM_ERR("Out of shm malloc for cluster name\n");
goto error;
}
memcpy((*entry)->name.s, start, p-start);
(*entry)->name.len=p-start;
(*entry)->connected=0;
(*entry)->type=CLUSTER_TYPE;
(*entry)->u.cs.name=(*entry)->name;
/*get as names*/
eat_spaces(p);
if (*p!='['){
LM_ERR("Malformed cluster cfg string %s\n",cluster_cfg);
goto error;
}
p++;
n=0;
while (*p!=']')
{
eat_spaces(p);
start = p;
while(*p!=' ' && *p!='\t' && *p!=']' && *p!=',' && *p!=0)
p++;
if ( p==start || *p==0 )
goto error;
if (!((*entry)->u.cs.as_names[n].s=shm_malloc(p-start))) {
LM_ERR("Out of shm_mem for AS name in cluster\n");
goto error;
}
(*entry)->u.cs.as_names[n].len=p-start;
memcpy((*entry)->u.cs.as_names[n].s,start,p-start);
n++;
if(n>=MAX_AS_PER_CLUSTER){
LM_ERR("too many AS per cluster\n");
goto error;
}
eat_spaces(p);
if (*p==',') {
p++;
eat_spaces(p);
}
}
p++;
(*entry)->u.cs.num=n;
/* end of element */
eat_spaces(p);
if (*p==',')
p++;
eat_spaces(p);
entry=&((*entry)->next);
}
for (tmp=as_list;tmp->next;tmp=tmp->next){
LM_DBG("%.*s\n",tmp->name.len,tmp->name.s);
}
LM_DBG("%.*s\n",tmp->name.len,tmp->name.s);
entry=&(tmp->next);
for(tmp=as_list;tmp;tmp=tmp->next){
if (tmp->type!=CLUSTER_TYPE)
continue;
LM_DBG("cluster:[%.*s]\n",tmp->name.len,tmp->name.s);
for(k=0;k<tmp->u.cs.num;k++){
LM_DBG("\tAS:[%.*s]\n",tmp->u.cs.as_names[k].len,tmp->u.cs.as_names[k].s);
for (tmp2=as_list;tmp2;tmp2=tmp2->next) {
if (tmp2->type== AS_TYPE && tmp->u.cs.as_names[k].len == tmp2->name.len &&
!memcmp(tmp->u.cs.as_names[k].s,tmp2->name.s,tmp2->name.len)) {
tmp->u.cs.servers[k]=&tmp2->u.as;
break;
}
}
if(tmp2)
continue;
if (!((*entry)=shm_malloc(sizeof(struct as_entry)))) {
LM_ERR("Out of shm mem \n");
goto error;
}
memset(*entry,0,sizeof(struct as_entry));
(*entry)->type=AS_TYPE;
if (!((*entry)->name.s=shm_malloc(tmp->u.cs.as_names[k].len))) {
LM_ERR("out of shm mem\n");
goto error;
}
memcpy((*entry)->name.s,tmp->u.cs.as_names[k].s,tmp->u.cs.as_names[k].len);
(*entry)->name.len=tmp->u.cs.as_names[k].len;
(*entry)->u.as.name=(*entry)->name;
tmp->u.cs.servers[k]=&(*entry)->u.as;
entry=&((*entry)->next);
}
}
for(tmp=as_list;tmp;tmp=tmp->next){
LM_DBG("%.*s %s",tmp->name.len,tmp->name.s,tmp->next?"":"\n");
}
return 1;
while(*p) {
eat_spaces(p);
/*get cluster name*/
start = p;
while(*p != ' ' && *p != '\t' && *p != '[' && *p != 0)
p++;
if(p == start || *p == 0) {
LM_ERR("cluster names must only contain alphanumeric chars\n");
goto error;
}
if(!((*entry) = (struct as_entry *)shm_malloc(
sizeof(struct as_entry)))) {
LM_ERR("Out of shm mem for as_entry\n");
goto error;
}
memset(*entry, 0, sizeof(struct as_entry));
if(!((*entry)->name.s = shm_malloc(p - start))) {
LM_ERR("Out of shm malloc for cluster name\n");
goto error;
}
memcpy((*entry)->name.s, start, p - start);
(*entry)->name.len = p - start;
(*entry)->connected = 0;
(*entry)->type = CLUSTER_TYPE;
(*entry)->u.cs.name = (*entry)->name;
/*get as names*/
eat_spaces(p);
if(*p != '[') {
LM_ERR("Malformed cluster cfg string %s\n", cluster_cfg);
goto error;
}
p++;
n = 0;
while(*p != ']') {
eat_spaces(p);
start = p;
while(*p != ' ' && *p != '\t' && *p != ']' && *p != ',' && *p != 0)
p++;
if(p == start || *p == 0)
goto error;
if(!((*entry)->u.cs.as_names[n].s = shm_malloc(p - start))) {
LM_ERR("Out of shm_mem for AS name in cluster\n");
goto error;
}
(*entry)->u.cs.as_names[n].len = p - start;
memcpy((*entry)->u.cs.as_names[n].s, start, p - start);
n++;
if(n >= MAX_AS_PER_CLUSTER) {
LM_ERR("too many AS per cluster\n");
goto error;
}
eat_spaces(p);
if(*p == ',') {
p++;
eat_spaces(p);
}
}
p++;
(*entry)->u.cs.num = n;
/* end of element */
eat_spaces(p);
if(*p == ',')
p++;
eat_spaces(p);
entry = &((*entry)->next);
}
for(tmp = as_list; tmp->next; tmp = tmp->next) {
LM_DBG("%.*s\n", tmp->name.len, tmp->name.s);
}
LM_DBG("%.*s\n", tmp->name.len, tmp->name.s);
entry = &(tmp->next);
for(tmp = as_list; tmp; tmp = tmp->next) {
if(tmp->type != CLUSTER_TYPE)
continue;
LM_DBG("cluster:[%.*s]\n", tmp->name.len, tmp->name.s);
for(k = 0; k < tmp->u.cs.num; k++) {
LM_DBG("\tAS:[%.*s]\n", tmp->u.cs.as_names[k].len,
tmp->u.cs.as_names[k].s);
for(tmp2 = as_list; tmp2; tmp2 = tmp2->next) {
if(tmp2->type == AS_TYPE
&& tmp->u.cs.as_names[k].len == tmp2->name.len
&& !memcmp(tmp->u.cs.as_names[k].s, tmp2->name.s,
tmp2->name.len)) {
tmp->u.cs.servers[k] = &tmp2->u.as;
break;
}
}
if(tmp2)
continue;
if(!((*entry) = shm_malloc(sizeof(struct as_entry)))) {
LM_ERR("Out of shm mem \n");
goto error;
}
memset(*entry, 0, sizeof(struct as_entry));
(*entry)->type = AS_TYPE;
if(!((*entry)->name.s = shm_malloc(tmp->u.cs.as_names[k].len))) {
LM_ERR("out of shm mem\n");
goto error;
}
memcpy((*entry)->name.s, tmp->u.cs.as_names[k].s,
tmp->u.cs.as_names[k].len);
(*entry)->name.len = tmp->u.cs.as_names[k].len;
(*entry)->u.as.name = (*entry)->name;
tmp->u.cs.servers[k] = &(*entry)->u.as;
entry = &((*entry)->next);
}
}
for(tmp = as_list; tmp; tmp = tmp->next) {
LM_DBG("%.*s %s", tmp->name.len, tmp->name.s, tmp->next ? "" : "\n");
}
return 1;
error:
tmp=as_list;
while(tmp){
for(k=0;k<tmp->u.cs.num;k++){
if(tmp->u.cs.as_names[k].s)
shm_free(tmp->u.cs.as_names[k].s);
}
if(tmp->name.s)
shm_free(tmp->name.s);
tmp2=tmp;
tmp=tmp->next;
shm_free(tmp2);
}
as_list=(struct as_entry *)0;
return -1;
tmp = as_list;
while(tmp) {
for(k = 0; k < tmp->u.cs.num; k++) {
if(tmp->u.cs.as_names[k].s)
shm_free(tmp->u.cs.as_names[k].s);
}
if(tmp->name.s)
shm_free(tmp->name.s);
tmp2 = tmp;
tmp = tmp->next;
shm_free(tmp2);
}
as_list = (struct as_entry *)0;
return -1;
}
43 changes: 23 additions & 20 deletions src/modules/seas/encode_allow.c
Expand Up @@ -46,35 +46,38 @@
#include "../../core/parser/msg_parser.h"
#include "encode_allow.h"

char *mismetodos[]={"UNDEF","INVITE","CANCEL","ACK","BYE","INFO","OPTIONS","UPDATE","REGISTER","MESSAGE","SUBSCRIBE","NOTIFY","PRACK","REFER","OTHER"};
char *mismetodos[] = {"UNDEF", "INVITE", "CANCEL", "ACK", "BYE", "INFO",
"OPTIONS", "UPDATE", "REGISTER", "MESSAGE", "SUBSCRIBE", "NOTIFY",
"PRACK", "REFER", "OTHER"};

/**
* Encodes allow header.
*
* TODO: Does not support the UNDEFINED header type !!!
*/
int encode_allow(char *hdrstart,int hdrlen,unsigned int *bodi,char *where)
int encode_allow(char *hdrstart, int hdrlen, unsigned int *bodi, char *where)
{
unsigned int i;
memcpy(&i,bodi,4);
i=htonl(i);
memcpy(where,&i,4);
return 4;
unsigned int i;
memcpy(&i, bodi, 4);
i = htonl(i);
memcpy(where, &i, 4);
return 4;
}

int print_encoded_allow(FILE *fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix)
int print_encoded_allow(FILE *fd, char *hdr, int hdrlen, unsigned char *payload,
int paylen, char *prefix)
{
unsigned int i,j=0,body;
unsigned int i, j = 0, body;

memcpy(&body,payload,4);
body=ntohl(body);
fprintf(fd,"%sMETHODS=",prefix);
if(body==0)
fprintf(fd,"UNKNOWN");
for(i=0;i<32;j=(0x01<<i),i++){
if(body & (j<15))
fprintf(fd,",%s",mismetodos[i]);
}
fprintf(fd,"\n");
return 1;
memcpy(&body, payload, 4);
body = ntohl(body);
fprintf(fd, "%sMETHODS=", prefix);
if(body == 0)
fprintf(fd, "UNKNOWN");
for(i = 0; i < 32; j = (0x01 << i), i++) {
if(body & (j < 15))
fprintf(fd, ",%s", mismetodos[i]);
}
fprintf(fd, "\n");
return 1;
}
5 changes: 3 additions & 2 deletions src/modules/seas/encode_allow.h
Expand Up @@ -21,6 +21,7 @@

#ifndef __ENCODE_ALLOW_H__
#define __ENCODE_ALLOW_H__
int encode_allow(char *hdrstart,int hdrlen,unsigned int *bodi,char *where);
int print_encoded_allow(FILE *fd,char *hdr,int hdrlen,unsigned char* payload,int paylen,char *prefix);
int encode_allow(char *hdrstart, int hdrlen, unsigned int *bodi, char *where);
int print_encoded_allow(FILE *fd, char *hdr, int hdrlen, unsigned char *payload,
int paylen, char *prefix);
#endif

0 comments on commit ba2cbf2

Please sign in to comment.