summaryrefslogtreecommitdiff
path: root/src/login_sql/strlib.c
blob: b1cb79b7131148446f284fd3924370d1c3be7e5d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "strlib.h"
#include "utils.h"

//-----------------------------------------------
// string lib.
unsigned char* jstrescape (unsigned char* pt) {
	//copy from here
	unsigned char * ptr;
	int i =0, j=0;

	//copy string to temporary
	CREATE(ptr, char, J_MAX_MALLOC_SIZE);
	strcpy (ptr,pt);

	while (ptr[i] != '\0') {
		switch (ptr[i]) {
			case '\'':
				pt[j++] = '\\';
				pt[j++] = ptr[i++];
				break;
			case '\\':
				pt[j++] = '\\';
				pt[j++] = ptr[i++];
				break;
			default:
				pt[j++] = ptr[i++];
		}
	}
	pt[j++] = '\0';
	free (ptr);
	return (unsigned char*) &pt[0];
}

unsigned char* jstrescapecpy (unsigned char* pt,unsigned char* spt) {
	//copy from here
	int i =0, j=0;

	while (spt[i] != '\0') {
		switch (spt[i]) {
			case '\'':
				pt[j++] = '\\';
				pt[j++] = spt[i++];
				break;
			case '\\':
				pt[j++] = '\\';
				pt[j++] = spt[i++];
				break;
			default:
				pt[j++] = spt[i++];
		}
	}
	pt[j++] = '\0';
	return (unsigned char*) &pt[0];
}