Example #1
0
static void SaveLDIFText(FILE *file, const char *Name, const unsigned char *Value)
{
	unsigned char Buffer[1000],Buffer2[1000];

	if (EncodeUTF8(Buffer, Value)) {
		EncodeBASE64(Buffer, Buffer2, strlen(Buffer));
		fprintf(file,"%s:: %s%c%c",Name,Buffer2,13,10);
	} else {
		fprintf(file,"%s: %s%c%c",Name,DecodeUnicodeString(Value),13,10);
	}
}
Example #2
0
GSM_Error VC_StoreBase64(char *Buffer, const size_t buff_len, size_t *Pos, const unsigned char *data, const size_t length)
{
	char *buffer=NULL, *pos=NULL, linebuffer[80]={0};
	size_t len=0, current=0;
	char spacer[2]={0};
	GSM_Error error;

	/*
	 * Need to be big enough to store base64 (what is *4/3, but *2 is safer
	 * and we don't have to care about rounding and padding).
	 */
	buffer = (char *)malloc(length * 2);
	if (buffer == NULL) return ERR_MOREMEMORY;

	spacer[0] = 0;
	spacer[1] = 0;


	EncodeBASE64(data, buffer, length);

	len = strlen(buffer);
	pos = buffer;

	/* Write at most 76 chars per line */
	while (len > 0) {
		current = MIN(len, 76);
		strncpy(linebuffer, pos, current);
		linebuffer[current] = 0;
		error =  VC_StoreLine(Buffer, buff_len, Pos, "%s%s", spacer, linebuffer);
		if (error != ERR_NONE) {
			free(buffer);
			buffer=NULL;
			return error;
		}
		spacer[0] = ' ';
		len -= current;
		pos += current;
	}

	free(buffer);
	buffer=NULL;
	return ERR_NONE;
}