[Asterisk-cvs] asterisk asterisk.c,1.96,1.97 pbx.c,1.129,1.130 utils.c,1.11,1.12
markster at lists.digium.com
markster at lists.digium.com
Fri Jun 25 00:21:58 CDT 2004
Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv7259
Modified Files:
asterisk.c pbx.c utils.c
Log Message:
Commit remaining changes
Index: asterisk.c
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.c,v
retrieving revision 1.96
retrieving revision 1.97
diff -u -d -r1.96 -r1.97
--- asterisk.c 22 Jun 2004 17:42:13 -0000 1.96
+++ asterisk.c 25 Jun 2004 04:07:52 -0000 1.97
@@ -1486,6 +1486,7 @@
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"));
Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.129
retrieving revision 1.130
diff -u -d -r1.129 -r1.130
--- pbx.c 23 Jun 2004 20:46:58 -0000 1.129
+++ pbx.c 25 Jun 2004 04:07:52 -0000 1.130
@@ -992,8 +992,8 @@
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;
Index: utils.c
===================================================================
RCS file: /usr/cvsroot/asterisk/utils.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- utils.c 22 Jun 2004 20:11:15 -0000 1.11
+++ utils.c 25 Jun 2004 04:07:52 -0000 1.12
@@ -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 @@
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;
+}
More information about the svn-commits
mailing list