aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xasterisk.c1
-rwxr-xr-xpbx.c4
-rwxr-xr-xutils.c125
3 files changed, 128 insertions, 2 deletions
diff --git a/asterisk.c b/asterisk.c
index 39a20ec40..e4ca793cc 100755
--- a/asterisk.c
+++ b/asterisk.c
@@ -1486,6 +1486,7 @@ int main(int argc, char *argv[])
ast_ulaw_init();
ast_alaw_init();
callerid_init();
+ ast_utils_init();
tdd_init();
if (getenv("HOME"))
snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
diff --git a/pbx.c b/pbx.c
index 4d9696244..7387d7c95 100755
--- a/pbx.c
+++ b/pbx.c
@@ -992,8 +992,8 @@ void pbx_substitute_variables_helper(struct ast_channel *c,const char *cp1,char
char *cp4;
const char *tmp, *whereweare;
int length;
- char workspace[256];
- char ltmp[256], var[256];
+ char workspace[4096];
+ char ltmp[4096], var[4096];
char *nextvar, *nextexp;
char *vars, *vare;
int pos, brackets, needsub, len;
diff --git a/utils.c b/utils.c
index 839b6f505..8d976fee2 100755
--- a/utils.c
+++ b/utils.c
@@ -15,6 +15,9 @@
#include <asterisk/lock.h>
#include <asterisk/utils.h>
+static char base64[64];
+static char b2a[256];
+
#if defined(__FreeBSD__) || defined(__OpenBSD__)
/* duh? ERANGE value copied from web... */
@@ -209,3 +212,125 @@ int test_for_thread_safety(void)
pthread_join(test_thread, NULL);
return(test_errors); /* return 0 on success. */
}
+
+int ast_base64decode(unsigned char *dst, char *src, int max)
+{
+ int cnt = 0;
+ unsigned int byte = 0;
+ unsigned int bits = 0;
+ int incnt = 0;
+#if 0
+ unsigned char *odst = dst;
+#endif
+ while(*src && (cnt < max)) {
+ /* Shift in 6 bits of input */
+ byte <<= 6;
+ byte |= (b2a[(int)(*src)]) & 0x3f;
+ bits += 6;
+#if 0
+ printf("Add: %c %s\n", *src, binary(b2a[(int)(*src)] & 0x3f, 6));
+#endif
+ src++;
+ incnt++;
+ /* If we have at least 8 bits left over, take that character
+ off the top */
+ if (bits >= 8) {
+ bits -= 8;
+ *dst = (byte >> bits) & 0xff;
+#if 0
+ printf("Remove: %02x %s\n", *dst, binary(*dst, 8));
+#endif
+ dst++;
+ cnt++;
+ }
+ }
+#if 0
+ dump(odst, cnt);
+#endif
+ /* Dont worry about left over bits, they're extra anyway */
+ return cnt;
+}
+
+int ast_base64encode(char *dst, unsigned char *src, int srclen, int max)
+{
+ int cnt = 0;
+ unsigned int byte = 0;
+ int bits = 0;
+ int index;
+ int cntin = 0;
+#if 0
+ char *odst = dst;
+ dump(src, srclen);
+#endif
+ /* Reserve one bit for end */
+ max--;
+ while((cntin < srclen) && (cnt < max)) {
+ byte <<= 8;
+#if 0
+ printf("Add: %02x %s\n", *src, binary(*src, 8));
+#endif
+ byte |= *(src++);
+ bits += 8;
+ cntin++;
+ while((bits >= 6) && (cnt < max)) {
+ bits -= 6;
+ /* We want only the top */
+ index = (byte >> bits) & 0x3f;
+ *dst = base64[index];
+#if 0
+ printf("Remove: %c %s\n", *dst, binary(index, 6));
+#endif
+ dst++;
+ cnt++;
+ }
+ }
+ if (bits && (cnt < max)) {
+ /* Add one last character for the remaining bits,
+ padding the rest with 0 */
+ byte <<= (6 - bits);
+ index = (byte) & 0x3f;
+ *(dst++) = base64[index];
+ cnt++;
+ }
+ *dst = '\0';
+ return cnt;
+}
+
+static void base64_init(void)
+{
+ int x;
+ memset(b2a, -1, sizeof(b2a));
+ /* Initialize base-64 Conversion table */
+ for (x=0;x<26;x++) {
+ /* A-Z */
+ base64[x] = 'A' + x;
+ b2a['A' + x] = x;
+ /* a-z */
+ base64[x + 26] = 'a' + x;
+ b2a['a' + x] = x + 26;
+ /* 0-9 */
+ if (x < 10) {
+ base64[x + 52] = '0' + x;
+ b2a['0' + x] = x + 52;
+ }
+ }
+ base64[62] = '+';
+ base64[63] = '/';
+ b2a[(int)'+'] = 62;
+ b2a[(int)'/'] = 63;
+#if 0
+ for (x=0;x<64;x++) {
+ if (b2a[(int)base64[x]] != x) {
+ fprintf(stderr, "!!! %d failed\n", x);
+ } else
+ fprintf(stderr, "--- %d passed\n", x);
+ }
+#endif
+}
+
+
+int ast_utils_init(void)
+{
+ base64_init();
+ return 0;
+}