[esnacc-dev] [PATCH] c-lib: strip some old code

Aaron Conole aconole at bytheb.org
Fri Jan 13 14:44:10 UTC 2017


Signed-off-by: Aaron Conole <aconole at bytheb.org>
---
 c-lib/src/asn-UTF8String.c | 307 ---------------------------------------------
 1 file changed, 307 deletions(-)

diff --git a/c-lib/src/asn-UTF8String.c b/c-lib/src/asn-UTF8String.c
index 9f7dd7f..7c55379 100644
--- a/c-lib/src/asn-UTF8String.c
+++ b/c-lib/src/asn-UTF8String.c
@@ -295,310 +295,3 @@ int CvtWchar2UTF8(wchar_t *inStr, char **utf8Str)
 
 	return 0;
 } /* end of CvtWchar2UTF8() */
-
-
-
-
-
-#ifdef OLD_CODE_
-	/*
-	 * Convert a ISO10646 stream to UTF-8 wide character
-	 * Used only by UniversalStrings, BMPStrings, etc
-	 */
-	int CvtToUTFStr(AsnOcts *Octsinputstr, wchar_t  **wchar_ptr)
-	{
-	int encodelen = Octsinputstr->octetLen;
-	int newlen = 0;
-	int flip = 1;
-	wchar_t c = 0;
-	char *inputstr = (char *)Octsinputstr->octs;
-	int pos = encodelen;
-	wchar_t *newbuf = (wchar_t *)calloc (1, encodelen*4);
-	
-		memset (newbuf, 0, encodelen*4);
-		while (pos > 0) {
-			memcpy ((wchar_t *)&c, inputstr, sizeof (wchar_t));
-		   if(*(char *)&flip == 1)
-		   {
-			   c = (c << 8) | (c >> 8);
-		   }
-	
-			if (c < 0x80)
-			{
-				newbuf[newlen++] = c;
-			}
-			else if (c < 0x800)
-			{
-				/* Produce the 2 byte encoding */
-	            newbuf[newlen++] = ((0xc0 | (c >>6))<<8) | 
-									(0x80 | (c & 0x3f));
-			}
-			else if (c < 0x10000)
-			{
-				/* Produce the 3 byte encoding */
-				newbuf[newlen++] = ((0xe0 | (c >>12)) <<8) |
-									(0x80 | ((c >>6) & 0x3f));
-				newbuf[newlen++] = (0x80 | (c & 0x3f));
-	
-			}
-			else if (c < 0x200000)
-			{
-				/* Not currently supported */
-				return (-1);
-			}
-			pos -= sizeof (wchar_t);
-			inputstr += sizeof (wchar_t);
-	    }
-		*wchar_ptr = (wchar_t *)newbuf;
-		return (newlen);
-	
-	}
-	
-	/*
-	 * Converts a UTF-8 String into a ISO-10646 string
-	 */
-	int  CvtUTFToISO (AsnOcts *utf_stringa, wchar_t  **wchar_ptr)
-	{
-	int count;
-	char *utf_string = (char *)utf_stringa->octs; 
-	int UTF8Len = utf_stringa->octetLen;
-	wchar_t *work_buffer  = (wchar_t *)calloc (1, UTF8Len*sizeof(wchar_t));
-	int newlen = 0;
-	unsigned short enc_sequence;
-	wchar_t enc_value = 0;
-	int encoded_length = 0;
-	/*	memset (work_buffer, 0, (UTF8Len*sizeof(wchar_t))); */
-		count = UTF8Len;
-	    while (count > 0)
-	    {
-	                /* Analyze the UTF encodings */
-	                enc_sequence = (unsigned char)(*utf_string);
-	                if (enc_sequence >= FOUR_BYTE_ENCODING)
-	                { 
-						free (work_buffer);
-						return (-1);
-	                } 
-	                else if (enc_sequence >= THREE_BYTE_ENCODING) 
-	                { 
-	                       /* three bytes encoded, 16 bits */
-	                        enc_value = ((utf_string[0] & 0x3f)<<12) | 
-										((utf_string[1] & 0x3f)<<6)  | 
-										 (utf_string[2] & 0x3f);
-	                        utf_string += 3;
-	                        count -= 3;
-							encoded_length = 2; 
-	                }
-	                else if (enc_sequence >= TWO_BYTE_ENCODING) 
-	                { 
-							/* two bytes encoded, 11 bits */
-	                        enc_value = ((utf_string[0] & 0x3f)<<6) | 
-										(utf_string[1] & 0x3f);
-	
-	                        utf_string += 2;
-	                        count -= 2;
-							encoded_length = 2;
-	                } 
-	                else 
-	                {
-	                       /* Simple - no encoding needed */
-							enc_value = enc_sequence;
-	                        utf_string++;
-	                        count--;
-							encoded_length = 1;
-	                 }
-	
-					work_buffer[newlen] = enc_value;
-					newlen ++;
-	          }
-	         /* NULL Terminate it */\
-		
-	         work_buffer[newlen] = (wchar_t)NULL;
-	         /* Update the caller's pointer (may want to realloc it) */
-			*wchar_ptr = (wchar_t *)work_buffer;
-			
-	        /* Return the length */
-	         return (newlen);
-	}
-	/* Format char pointer to RFC 2253
-	 * The flip argument specifies if you want to check for Endian-ness
-	 * such as on BMPStrings they are already checked for Endian-ness
-	 */
-	int cvt_WCStrtoLDAP  (wchar_t *in_string, char  **char_ptr, int flip)
-	{
-	
-		bool quoted = false;	  /* Flag telling us if we are in a quoted string */
-		int hex_val = 0;	 	  /* Temporary hex value returned from sprintf */
-		int quote_count = 0;	  /* Quote counter */
-		int nullcount = 0;		  /* The terminating NULL Counter (related to the sizeof wchar_t) */
-		int count = 0;			  /* The input byte counter */
-		int to_count = 0;		  /* The destination counter */
-		int buf_len = 0;
-		char *wrkbf = (char *)NULL;
-		wchar_t *lptr = in_string;
-		for (buf_len=0; in_string[buf_len] != (wchar_t)NULL; buf_len++);
-	
-		wrkbf = (char *)calloc (1, buf_len*6);
-		while ((wchar_t)lptr[count] != (wchar_t)NULL)
-		{
-			wchar_t the_string = (wchar_t)lptr[count];
-			/* Make platform independent */
-		   if(*(char *)&flip == 1)
-		   {
-			  the_string = (the_string << 8) | (the_string >> 8);
-		   }
-	
-			if (the_string != 0)
-			{
-				nullcount = 0;
-				if ((to_count == 0) && (the_string == '#') ||
-					(the_string == ' '))
-				{
-					/* A # or a Space in the first position must be escaped */
-					wrkbf[to_count] = '\\';
-				}
-				/* Check the character for Quote */
-				if ((the_string == '\"') && 
-					(!quoted))
-				{
-					memcpy ((char *)&wrkbf[to_count], (char *)"\\", 1);
-					to_count += 1;
-					quoted = true;
-				}
-				else if ((the_string == '\"') && (quoted))
-				{
-					/* End the Quoted */
-					memcpy ((char *)&wrkbf[to_count], (char *)"\\", 1);
-					to_count += 1;
-					quoted = false;
-				}
-				/* Check non printable characters */
-				if ((the_string < ' ') ||
-					(the_string > 0x7E))
-				{
-					int len = 0;
-					int hex_val = 0;  /* Temporary hex value returned from sprintf */
-					char csprintf[4]; /* Sprintf Buffer */
-	
-					/* Check for non-ascii values SPACE and DEL */
-	 				/* Escape the value */
-					wrkbf[to_count] = '\\';  /* Backslash */
-					to_count++;
-					hex_val = the_string;
-					len = sprintf (csprintf,"%2x", hex_val);
-					memcpy ((char *)&wrkbf[to_count], &csprintf[0], 2);
-					to_count += 2;
-					if (len == 4)
-					{
-						/* Check for "00" */
-						if (memcmp (&csprintf[2], "00", 2) != 0)
-						{
-							wrkbf[to_count] = '\\';  /* Backslash */
-							to_count++;
-							memcpy ((char *)&wrkbf[to_count], &csprintf[2], 2);
-							to_count += 2;
-						}
-					}
-				}
-				else 
-				{
-					if (!quoted)
-					{
-						/*
-						 * Escape the following characters if not quoted
-						 */
-						if ((the_string == ',') ||
-							(the_string == '=') ||
-							(the_string == '+') ||
-							(the_string == '<') ||
-							(the_string == '>') ||
-							(the_string == '#') ||
-							(the_string == ';'))
-						{
-							/* Add the escape character to the work buffer */
-							wrkbf[to_count] = '\\';
-							to_count ++;
-						}
-					}
-					wrkbf[to_count] = (char)the_string;
-					to_count++;
-				}
-			}
-			else
-			{
-				nullcount ++;
-			}
-		
-			count ++;
-		}
-			/* Check the last character for a SPACE */
-		if (wrkbf[to_count-1] == ' ')
-		{
-			/* Must be escaped */
-			wrkbf[to_count] = wrkbf[to_count-1];
-			wrkbf[to_count-1] = '\\';
-		}
-		*char_ptr = wrkbf;
-		return (to_count);
-	}
-	
-	/* Format char pointer with RFC 2253 to a char pointer */
-	int cvt_LDAPtoStr  (char *in_string, char  **char_ptr)
-	{
-	
-		bool quoted = false;	  /* Flag telling us if we are in a quoted string */
-		int hex_val = 0;	 	  /* Temporary hex value returned from sprintf */
-		int quote_count = 0;	  /* Quote counter */
-		char hex_str[4];		  /* Sprintf Buffer */
-		char *the_string;		  /* The character to parse	*/
-		char *wrkbf, *buf_ptr;	  /* Our work buffer */
-		int nullcount = 0;		  /* The terminating NULL Counter (related to the sizeof wchar_t) */
-		int count = 0;			  /* The input byte counter */
-		int to_count = 0;		  /* The destination counter */
-		int len = 0;
-		int buf_len = 0;
-	
-		char *lptr = (char *)in_string;
-		for (buf_len=0; in_string[buf_len] != (wchar_t)NULL; buf_len++);
-		buf_ptr = (char *)calloc (1, buf_len*6);
-		wrkbf = buf_ptr;
-		the_string = lptr;
-		while (nullcount < sizeof (wchar_t))
-		{
-			if (the_string != NULL)
-			{
-				if (the_string == (char *)'\\')
-				{
-					if ((the_string >= (char *)'0') && (the_string <= (char *)'9'))
-					{
-						memset (&hex_str, 0, 4);
-						memcpy (hex_str, (char *)&the_string+1, 2);
-						/* Escaped hex value - convert */
-						hex_val = strtol (hex_str, NULL, 10);
-						/* Copy then to the buffer */
-						memcpy ((char *)wrkbf[to_count], (char *)&hex_val, 2);
-						the_string++;
-					}
-					else
-					{
-						/* Just skip over the backslash and add the data to the buffer */
-						wrkbf = (char *)&the_string+1;
-						memcpy ((char *)wrkbf[to_count], (char *)the_string+1, 1);
-					the_string ++;
-				}
-			}
-			else
-			{
-				wrkbf = the_string;
-			}
-			the_string ++;
-			wrkbf++;
-		}
-	}
-    if (to_count < buf_len*6)
-		realloc (wrkbf, to_count+1);
-	*char_ptr = wrkbf;
-	return (to_count);
-}
-
-
-#endif /* OLD_CODE_ */
-- 
2.7.4



More information about the dev mailing list