Added more space for proxies
Fixed a bug in protoutils.h->string_to_bytes where an extra NULL caused memory errors.
This commit is contained in:
parent
36f4f4e1b8
commit
5bc0d88bf1
3 changed files with 114 additions and 138 deletions
11
multiaddr.h
11
multiaddr.h
|
@ -20,8 +20,8 @@ int strpos(char *haystack, char *needle)
|
|||
}
|
||||
struct maddr
|
||||
{
|
||||
char string[200];
|
||||
uint8_t bytes[100];
|
||||
char string[800];
|
||||
uint8_t bytes[400];
|
||||
int bsize[1];
|
||||
};
|
||||
struct maddr new_maddr_fb(uint8_t * byteaddress,int size)//Construct new address from bytes
|
||||
|
@ -39,14 +39,14 @@ struct maddr new_maddr_fb(uint8_t * byteaddress,int size)//Construct new address
|
|||
struct maddr new_maddr_fs(char * straddress)//Construct new address from string
|
||||
{
|
||||
struct maddr anewaddr;
|
||||
bzero(anewaddr.string, 100);
|
||||
bzero(anewaddr.string, 800);
|
||||
strcpy(anewaddr.string, straddress);
|
||||
anewaddr.bsize[0] = 0;
|
||||
if(string_to_bytes(anewaddr.bytes,anewaddr.bsize,anewaddr.string,sizeof(anewaddr.string))==1)
|
||||
{
|
||||
int betta;
|
||||
//printf("BSIZE: %u\n", anewaddr.bsize[0]);
|
||||
for(betta=anewaddr.bsize[0];betta<100;betta++)
|
||||
for(betta=anewaddr.bsize[0];betta<400;betta++)
|
||||
{
|
||||
anewaddr.bytes[betta] = '\0';
|
||||
}
|
||||
|
@ -58,7 +58,8 @@ int m_encapsulate(struct maddr * result, char * string)
|
|||
if(result!=NULL&&string!=NULL)
|
||||
{
|
||||
int success = 0;
|
||||
char pstr[100];
|
||||
char pstr[800];
|
||||
bzero(pstr,800);
|
||||
strcpy(pstr,result->string);
|
||||
strcat(pstr,string+1);
|
||||
if(string_to_bytes(result->bytes,result->bsize,pstr,sizeof(pstr)))
|
||||
|
|
169
protoutils.h
169
protoutils.h
|
@ -258,7 +258,7 @@ char * int2ip(int inputintip)
|
|||
//I didn't feel another address_bytes_to_string was necesarry sry guys
|
||||
int bytes_to_string(char * resultzx, uint8_t * catx,int xbsize)
|
||||
{
|
||||
bzero(resultzx,200);
|
||||
bzero(resultzx,800);
|
||||
uint8_t * bytes = NULL;
|
||||
int size = 0;
|
||||
size = xbsize;
|
||||
|
@ -348,8 +348,8 @@ int bytes_to_string(char * resultzx, uint8_t * catx,int xbsize)
|
|||
|
||||
char * address_string_to_bytes(struct protocol * xx, char * abc,size_t getsznow)
|
||||
{
|
||||
static char astb__stringy[200] = "\0";
|
||||
bzero(astb__stringy,200);
|
||||
static char astb__stringy[800] = "\0";
|
||||
bzero(astb__stringy,800);
|
||||
int code = 0;
|
||||
code = xx->deccode;
|
||||
switch(code)
|
||||
|
@ -381,8 +381,8 @@ char * address_string_to_bytes(struct protocol * xx, char * abc,size_t getsznow)
|
|||
{
|
||||
if(atoi(abc)<65536&&atoi(abc)>0)
|
||||
{
|
||||
static char himm_woot[4] = "\0";
|
||||
bzero(himm_woot, 4);
|
||||
static char himm_woot[5] = "\0";
|
||||
bzero(himm_woot, 5);
|
||||
strcpy(himm_woot, Int_To_Hex(atoi(abc)));
|
||||
if(himm_woot[2] == '\0')
|
||||
{//manual switch
|
||||
|
@ -406,6 +406,7 @@ char * address_string_to_bytes(struct protocol * xx, char * abc,size_t getsznow)
|
|||
himm_woot[2] = swap2;
|
||||
himm_woot[3] = swap3;
|
||||
}
|
||||
himm_woot[4]='\0';
|
||||
return himm_woot;
|
||||
}
|
||||
else
|
||||
|
@ -418,8 +419,8 @@ char * address_string_to_bytes(struct protocol * xx, char * abc,size_t getsznow)
|
|||
{
|
||||
if(atoi(abc)<65536&&atoi(abc)>0)
|
||||
{
|
||||
static char himm_woot2[4] = "\0";
|
||||
bzero(himm_woot2, 4);
|
||||
static char himm_woot2[5] = "\0";
|
||||
bzero(himm_woot2, 5);
|
||||
strcpy(himm_woot2, Int_To_Hex(atoi(abc)));
|
||||
if(himm_woot2[2] == '\0')
|
||||
{//Manual Switch2be
|
||||
|
@ -443,6 +444,7 @@ char * address_string_to_bytes(struct protocol * xx, char * abc,size_t getsznow)
|
|||
himm_woot2[2] = swap2;
|
||||
himm_woot2[3] = swap3;
|
||||
}
|
||||
himm_woot2[4]='\0';
|
||||
return himm_woot2;
|
||||
}
|
||||
else
|
||||
|
@ -474,6 +476,7 @@ char * address_string_to_bytes(struct protocol * xx, char * abc,size_t getsznow)
|
|||
case 42://IPFS - !!!
|
||||
{
|
||||
|
||||
return "ERR";
|
||||
break;
|
||||
}
|
||||
case 480://http
|
||||
|
@ -511,127 +514,99 @@ char * address_string_to_bytes(struct protocol * xx, char * abc,size_t getsznow)
|
|||
}
|
||||
int string_to_bytes(uint8_t * finalbytes,int * realbbsize,char * strx, size_t strsize)
|
||||
{
|
||||
static char xxx[200] = "\0";
|
||||
bzero(xxx,200);
|
||||
int sigmalf = 0;
|
||||
char * totpch;
|
||||
if(strx[0] != '/')
|
||||
{
|
||||
printf("Error, must start with '/'\n");
|
||||
return 0;
|
||||
}
|
||||
char xxx[800];
|
||||
bzero(xxx,800);
|
||||
//Getting total words
|
||||
int totalwords = 0;
|
||||
char * totp;
|
||||
char totalwordstest[strsize];
|
||||
bzero(totalwordstest,strsize);
|
||||
strcat(totalwordstest, strx);
|
||||
int totalwords = 0;
|
||||
totpch = strtok(totalwordstest, "/");
|
||||
while(totpch != NULL)
|
||||
totp = strtok(totalwordstest, "/");
|
||||
while(totp != NULL)
|
||||
{
|
||||
totpch = strtok (NULL, "/");
|
||||
totp = strtok (NULL, "/");
|
||||
totalwords++;
|
||||
}
|
||||
int processedwords = 0;
|
||||
char processedsofar[100];
|
||||
bzero(processedsofar,100);
|
||||
char str[strsize]; //This string will be bad later.
|
||||
bzero(str,strsize);
|
||||
nextproc:
|
||||
strcpy(str,strx);
|
||||
if(str[0] == '/')
|
||||
{
|
||||
char * pch;
|
||||
pch = strtok (str,"/");
|
||||
//Initializing variables to store our processed HEX in:
|
||||
int malf=0; //In case something goes wrong this will be 1.
|
||||
char processed[800];//HEX CONTAINER
|
||||
bzero(processed,800);
|
||||
//Now Setting up variables for calculating which is the first
|
||||
//and second word:
|
||||
int firstorsecond = 1; //1=Protocol && 2 = Address
|
||||
char pstring[800];//We do not want to harm the initial string.
|
||||
bzero(pstring,800);
|
||||
strcat(pstring,strx);
|
||||
//Starting to extract words and process them:
|
||||
char * wp;
|
||||
char * end;
|
||||
wp=strtok_r(pstring,"/",&end);
|
||||
load_protocols();
|
||||
for(int ax=0;ax<processedwords;ax++)
|
||||
{
|
||||
pch = strtok (NULL, "/");
|
||||
}
|
||||
while(pch != NULL)
|
||||
{
|
||||
if(proto_with_name(pch))
|
||||
{
|
||||
strcat(processedsofar, "/");
|
||||
strcat(processedsofar, pch);
|
||||
struct protocol * protx;
|
||||
//printf("PCH-P:%s\n",pch);
|
||||
protx = proto_with_name(pch);
|
||||
char cut[3]="\0";
|
||||
bzero(cut,3);
|
||||
strcat(cut,Int_To_Hex(protx->deccode));
|
||||
cut[2] = '\0';
|
||||
char finipbit[3] = "\0";
|
||||
bzero(finipbit,3);
|
||||
finipbit[0] = cut[0];
|
||||
finipbit[1] = cut[1];
|
||||
finipbit[2] = '\0';
|
||||
//Address
|
||||
pch = strtok (NULL, "/"); // Move to supposed address
|
||||
strcat(processedsofar, "/");
|
||||
strcat(processedsofar, pch);
|
||||
//printf("PCH-A:%s\n",pch);
|
||||
char addr[60] = "\0";
|
||||
bzero(addr,60);
|
||||
strcat(addr, pch);
|
||||
//If both are ok:
|
||||
strcat(xxx,finipbit);
|
||||
if(address_string_to_bytes(protx, addr,sizeof(addr)))
|
||||
while(wp)
|
||||
{
|
||||
if(address_string_to_bytes(protx, addr,sizeof(addr)) == "ERR")
|
||||
if(firstorsecond==1)//This is the Protocol
|
||||
{
|
||||
sigmalf = 1;
|
||||
if(proto_with_name(wp))
|
||||
{
|
||||
protx=proto_with_name(wp);
|
||||
//printf("PROTOCOL: %s\n",protx->name);
|
||||
strcat(processed, Int_To_Hex(protx->deccode));
|
||||
firstorsecond=2;//Since the next word will be an address
|
||||
}
|
||||
else
|
||||
{
|
||||
strcat(xxx,address_string_to_bytes(protx, addr,sizeof(addr)));
|
||||
printf("\nNo such protocol!\n\n");
|
||||
malf=1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else//This is the address
|
||||
{
|
||||
//printf("ADDRESS: %s\n",wp);
|
||||
if(address_string_to_bytes(protx, wp,strlen(wp)) == "ERR")
|
||||
{
|
||||
malf = 1;
|
||||
//printf("\n\nTRIGGERED!!!!!!!!!!!!!!!!!!!!!!!\n\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
sigmalf = 1;
|
||||
strcat(processed,address_string_to_bytes(protx, wp,strlen(wp)));
|
||||
//printf("Addressinbytes: %s\n",address_string_to_bytes(protx, wp,strlen(wp)));
|
||||
}
|
||||
pch = strtok (NULL, "/"); // Next step.
|
||||
processedwords++;
|
||||
processedwords++;
|
||||
protx=NULL;//Since right now it doesn't need that assignment anymore.
|
||||
firstorsecond=1;//Since the next word will be an protocol
|
||||
}
|
||||
wp=strtok_r(NULL,"/",&end);
|
||||
}
|
||||
protx=NULL;
|
||||
unload_protocols();
|
||||
//printf("Processed contains: %s \n",processed);
|
||||
|
||||
}
|
||||
else
|
||||
if(malf==1)
|
||||
{
|
||||
//This only gets triggered if the string has a wrong format
|
||||
//Or unknown protocol!
|
||||
printf("ERROR: MALFORMED STRING\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(processedwords != totalwords)
|
||||
else
|
||||
{
|
||||
goto nextproc;
|
||||
}
|
||||
unload_protocols();
|
||||
if(sigmalf != 1)
|
||||
{
|
||||
//printf("S2B_RESULT: %s\n", xxx);
|
||||
//static uint8_t finalbytes[100] = {0};
|
||||
bzero(finalbytes,100);
|
||||
bzero(finalbytes,400);
|
||||
//printf("XXX: %s\n",xxx);
|
||||
memcpy(finalbytes, Hex_To_Var(xxx), 100);
|
||||
memcpy(finalbytes, Hex_To_Var(processed), 400);
|
||||
realbbsize[0] = 0;
|
||||
for(int i=0;i<100;i++)
|
||||
for(int i=0;i<400;i++)
|
||||
{
|
||||
if(finalbytes[i])
|
||||
{
|
||||
realbbsize[0]++;
|
||||
}
|
||||
}
|
||||
//printf("FB2XXX: %s\nWith size: %u\n",Var_To_Hex(finalbytes), realbbsize[0]);
|
||||
//realbsize = realsize;
|
||||
//printf("REALbBSZIE: %d", realbbsize[0]);
|
||||
return 1;//success
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ERROR, MALFORMED STRING!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ERROR, Multiaddr needs to start with '/'\n");
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -52,7 +52,7 @@ uint32_t * Varint_To_Num_32(uint8_t TON32INPUT[60]) //VARINT TO UINT32_t
|
|||
//
|
||||
char * Int_To_Hex(uint64_t int2hex) //VAR[binformat] TO HEX
|
||||
{
|
||||
static char int2hex_result[200]="\0";
|
||||
static char int2hex_result[800]="\0";
|
||||
memset(int2hex_result,0,sizeof(int2hex_result));
|
||||
sprintf (int2hex_result, "%02lX", int2hex);
|
||||
return int2hex_result;
|
||||
|
@ -78,8 +78,8 @@ uint64_t Hex_To_Int(char * hax)
|
|||
//
|
||||
void vthconvert(int size, char * crrz01, uint8_t * xbuf)
|
||||
{
|
||||
uint8_t buf[100];
|
||||
bzero(buf,100);
|
||||
uint8_t buf[400];
|
||||
bzero(buf,400);
|
||||
|
||||
//fixing the buf
|
||||
for(int cz=0; cz<size;cz++)
|
||||
|
@ -91,7 +91,7 @@ void vthconvert(int size, char * crrz01, uint8_t * xbuf)
|
|||
{
|
||||
char * crrz1 = NULL;
|
||||
crrz1 = crrz01;
|
||||
char conv_proc[200]="\0";
|
||||
char conv_proc[800]="\0";
|
||||
int i;
|
||||
for(i=0; i < (size*2); i++)
|
||||
{
|
||||
|
@ -107,32 +107,32 @@ void vthconvert(int size, char * crrz01, uint8_t * xbuf)
|
|||
}
|
||||
char * Var_To_Hex(int realsize, uint8_t * TOHEXINPUT) //VAR[binformat] TO HEX
|
||||
{
|
||||
for(int ix=realsize;ix<100;ix++)
|
||||
for(int ix=realsize;ix<400;ix++)
|
||||
{
|
||||
TOHEXINPUT[ix] = '\0';
|
||||
}
|
||||
if(TOHEXINPUT != NULL)
|
||||
{
|
||||
static char convert_resultz1[200]="\0";
|
||||
bzero(convert_resultz1,200);
|
||||
static char convert_resultz1[800]="\0";
|
||||
bzero(convert_resultz1,800);
|
||||
vthconvert(realsize, convert_resultz1, TOHEXINPUT);
|
||||
return convert_resultz1;
|
||||
}
|
||||
}
|
||||
uint8_t * Hex_To_Var(char * Hexstr) //HEX TO VAR[BINFORMAT]
|
||||
{
|
||||
static uint8_t buffy_HEX[100] = {0};
|
||||
bzero(buffy_HEX,100);
|
||||
static uint8_t buffy_HEX[400] = {0};
|
||||
bzero(buffy_HEX,400);
|
||||
int i;
|
||||
char codo[200] = "\0";
|
||||
bzero(codo,200);
|
||||
char codo[800] = "\0";
|
||||
bzero(codo,800);
|
||||
strcpy(codo, Hexstr);
|
||||
char code[3];
|
||||
bzero(code,3);
|
||||
code[3]='\0';
|
||||
int x = 0;
|
||||
int fori001=0;
|
||||
for(fori001=0;fori001<200;fori001++)
|
||||
for(fori001=0;fori001<800;fori001++)
|
||||
{
|
||||
strncpy(&code[0],&codo[fori001],1);
|
||||
strncpy(&code[1],&codo[fori001+1],1);
|
||||
|
@ -149,8 +149,8 @@ uint8_t * Hex_To_Var(char * Hexstr) //HEX TO VAR[BINFORMAT]
|
|||
//
|
||||
void convert(char * convert_result, uint8_t * buf) //Both of them read them properly.
|
||||
{
|
||||
char conv_proc[200]="\0";
|
||||
bzero(conv_proc,200);
|
||||
char conv_proc[800]="\0";
|
||||
bzero(conv_proc,800);
|
||||
int i;
|
||||
for(i=0; i < 10; i++)
|
||||
{
|
||||
|
@ -161,12 +161,12 @@ void convert(char * convert_result, uint8_t * buf) //Both of them read them
|
|||
}
|
||||
char * Num_To_HexVar_64(uint64_t TOHVINPUT) //UINT64 TO HEXIFIED VAR
|
||||
{ //Code to varint - py
|
||||
static char convert_result[200]="\0";//Note that the hex resulted from this will differ from py
|
||||
bzero(convert_result,200);
|
||||
static char convert_result[800]="\0";//Note that the hex resulted from this will differ from py
|
||||
bzero(convert_result,800);
|
||||
memset(convert_result,0,sizeof(convert_result));//But if you make sure the string is always 20 chars in size
|
||||
uint8_t buf[100] = {0};
|
||||
bzero(buf,100);
|
||||
uvarint_encode64(TOHVINPUT, buf, 200);
|
||||
uint8_t buf[400] = {0};
|
||||
bzero(buf,400);
|
||||
uvarint_encode64(TOHVINPUT, buf, 800);
|
||||
convert(convert_result,buf);
|
||||
return convert_result;
|
||||
}
|
||||
|
@ -201,13 +201,13 @@ char * Num_To_HexVar_32(uint32_t TOHVINPUT) //UINT32 TO HEXIFIED VAR
|
|||
|
||||
uint64_t HexVar_To_Num_64(char * theHEXstring) //HEXIFIED VAR TO UINT64_T
|
||||
{ //Varint to code - py
|
||||
uint8_t buffy[100] = {0};
|
||||
char codo[200] = "\0";
|
||||
bzero(codo,200);
|
||||
uint8_t buffy[400] = {0};
|
||||
char codo[800] = "\0";
|
||||
bzero(codo,800);
|
||||
strcpy(codo, theHEXstring);
|
||||
char code[3] = "\0";
|
||||
int x = 0;
|
||||
for(int i= 0;i<199;i++)
|
||||
for(int i= 0;i<399;i++)
|
||||
{
|
||||
strncpy(&code[0],&codo[i],1);
|
||||
strncpy(&code[1],&codo[i+1],1);
|
||||
|
@ -219,21 +219,21 @@ uint64_t HexVar_To_Num_64(char * theHEXstring) //HEXIFIED VAR TO UINT64_T
|
|||
x++;
|
||||
}
|
||||
static uint64_t decoded;
|
||||
uvarint_decode64 (buffy, 100, &decoded);
|
||||
uvarint_decode64 (buffy, 400, &decoded);
|
||||
return decoded;
|
||||
}
|
||||
uint32_t HexVar_To_Num_32(char theHEXstring[]) //HEXIFIED VAR TO UINT32_T
|
||||
{ //Varint to code py
|
||||
uint8_t buffy[100] = {0};
|
||||
bzero(buffy,100);
|
||||
char codo[200] = "\0";
|
||||
bzero(codo,200);
|
||||
uint8_t buffy[400] = {0};
|
||||
bzero(buffy,400);
|
||||
char codo[800] = "\0";
|
||||
bzero(codo,800);
|
||||
strcpy(codo, theHEXstring);
|
||||
char code[3] = "\0";
|
||||
bzero(code,3);
|
||||
code[3] = '\0';
|
||||
int x = 0;
|
||||
for(int i= 0;i<199;i++)
|
||||
for(int i= 0;i<399;i++)
|
||||
{
|
||||
strncpy(&code[0],&codo[i],1);
|
||||
strncpy(&code[1],&codo[i+1],1);
|
||||
|
|
Loading…
Reference in a new issue