Inital commit
FossilOrigin-Name: 39e7097bc6ff122072d11fd7d282ec9624a223313d12f944dbca3e50e3676cba
This commit is contained in:
		
							
								
								
									
										65
									
								
								src/capwap/bstr_create_from_cfgstr.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								src/capwap/bstr_create_from_cfgstr.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,65 @@
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "bstr.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
uint8_t * bstr_create_from_cfgstr(const char * s)
 | 
			
		||||
{
 | 
			
		||||
	int l = strlen(s);
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
	if (s[0]!='.')
 | 
			
		||||
		return bstr_create((uint8_t*)s,l+1);
 | 
			
		||||
 | 
			
		||||
	if (l<=2)
 | 
			
		||||
		return bstr_create((uint8_t*)s,l+1);
 | 
			
		||||
 | 
			
		||||
	if (s[1]=='.'){
 | 
			
		||||
		return bstr_create((uint8_t*)s+1,l);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (s[1]=='x'){
 | 
			
		||||
		uint8_t * ns=0;
 | 
			
		||||
		int len=0;
 | 
			
		||||
 | 
			
		||||
		int ch,cl;
 | 
			
		||||
		const char *ss = s+2;
 | 
			
		||||
		int rc ;
 | 
			
		||||
		do {
 | 
			
		||||
			rc = sscanf(ss,"%01X",&ch);
 | 
			
		||||
			if (rc!=1)
 | 
			
		||||
				break;
 | 
			
		||||
			ss++;
 | 
			
		||||
			rc = sscanf(ss,"%01X",&cl);
 | 
			
		||||
			if (rc!=1)
 | 
			
		||||
				cl=0;
 | 
			
		||||
			ss++;
 | 
			
		||||
			int c=(ch<<4) | cl;
 | 
			
		||||
			
 | 
			
		||||
			len++;
 | 
			
		||||
			ns = realloc(ns,len);
 | 
			
		||||
			ns[len-1]=c;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		}while (rc==1);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		return bstr_create(ns,len);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
/*	if (strcmp(s,".reflect")==0){
 | 
			
		||||
		free(*si);
 | 
			
		||||
		*si=0;
 | 
			
		||||
		*l=0;
 | 
			
		||||
		return 1;
 | 
			
		||||
	}
 | 
			
		||||
*/
 | 
			
		||||
	return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										12
									
								
								src/capwap/bstr_replace.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/capwap/bstr_replace.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,12 @@
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#include "bstr.h"
 | 
			
		||||
 | 
			
		||||
uint8_t * bstr_replace( uint8_t ** str, uint8_t * data, int len)
 | 
			
		||||
{
 | 
			
		||||
	if (str)
 | 
			
		||||
		free(str);
 | 
			
		||||
	
 | 
			
		||||
	*str = bstr_create(data,len);	
 | 
			
		||||
	return *str;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user