sxmp: old base64 code removed;
This commit is contained in:
parent
d62181e280
commit
cc5cd0a1e0
@ -1,5 +1,4 @@
|
|||||||
nobase_include_HEADERS = sxmp/sxmp.h sxmp/errno.h sxmp/limits.h sxmp/version.h \
|
nobase_include_HEADERS = sxmp/sxmp.h sxmp/errno.h sxmp/limits.h sxmp/version.h \
|
||||||
sxmp/base64.h \
|
|
||||||
sexpr/cstring.h sexpr/faststack.h sexpr/sexp_errors.h sexpr/sexp.h \
|
sexpr/cstring.h sexpr/faststack.h sexpr/sexp_errors.h sexpr/sexp.h \
|
||||||
sexpr/sexp_memory.h sexpr/sexp_ops.h sexpr/sexp_vis.h \
|
sexpr/sexp_memory.h sexpr/sexp_ops.h sexpr/sexp_vis.h \
|
||||||
tdata/bitwise.h tdata/idx_allocator.h tdata/macro.h tdata/tree.h \
|
tdata/bitwise.h tdata/idx_allocator.h tdata/macro.h tdata/tree.h \
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
/*
|
|
||||||
* Base64 encode/decode functions used in sxmp
|
|
||||||
* openssl stuff wasn't used to avoid additional memleaks and allocation,
|
|
||||||
* deallocation of BIO.
|
|
||||||
*
|
|
||||||
* (c) Alexander Vdolainen 2016 <avdolainen@zoho.com>
|
|
||||||
*
|
|
||||||
* libsxmp is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU Lesser General Public License as published
|
|
||||||
* by the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* libsxmp is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __SXMP_BASE64_H__
|
|
||||||
#define __SXMP_BASE64_H__
|
|
||||||
|
|
||||||
size_t sx_rawlen2b64len(size_t raw_length);
|
|
||||||
|
|
||||||
size_t sx_b64encode_in(const char *data, char *bdata, size_t data_len);
|
|
||||||
|
|
||||||
char *sx_b64encode(const char *data, size_t data_len);
|
|
||||||
|
|
||||||
size_t sx_b64decode_in(const char *idata, size_t idata_len, char *data, size_t data_len);
|
|
||||||
|
|
||||||
#endif /* __SXMP_BASE64_H__ */
|
|
@ -16,7 +16,7 @@ lib_LTLIBRARIES = libsxmp.la
|
|||||||
libsxmp_la_SOURCES = \
|
libsxmp_la_SOURCES = \
|
||||||
sxmplv2.c hub.c channel.c message.c rpc.c \
|
sxmplv2.c hub.c channel.c message.c rpc.c \
|
||||||
uuid.c stream_generic_listops.c stream.c \
|
uuid.c stream_generic_listops.c stream.c \
|
||||||
base64.c error.c
|
error.c
|
||||||
|
|
||||||
libsxmp_la_LDFLAGS =
|
libsxmp_la_LDFLAGS =
|
||||||
|
|
||||||
@ -29,7 +29,8 @@ libsxmp_la_LIBADD += -lmman -luuid /mingw64/lib/libsexpr.a /mingw64/lib/libtdata
|
|||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
libsxmp_la_LIBADD += $(LIBUUID_LIBS) ../tdata/.libs/libtdata.la ../sexpr/.libs/libsexpr.la
|
libsxmp_la_LIBADD += $(LIBUUID_LIBS) ../tdata/.libs/libtdata.la \
|
||||||
|
../sexpr/.libs/libsexpr.la ../sxt/.libs/libsxt.la
|
||||||
|
|
||||||
endif !COND_WIN32
|
endif !COND_WIN32
|
||||||
|
|
||||||
|
110
sxmp/base64.c
110
sxmp/base64.c
@ -1,110 +0,0 @@
|
|||||||
/*
|
|
||||||
* Base64 encode/decode functions used in sxmp
|
|
||||||
* openssl stuff wasn't used to avoid additional memleaks and allocation,
|
|
||||||
* deallocation of BIO.
|
|
||||||
*
|
|
||||||
* (c) Alexander Vdolainen 2016 <avdolainen@zoho.com>
|
|
||||||
*
|
|
||||||
* libsxmp is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU Lesser General Public License as published
|
|
||||||
* by the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* libsxmp is distributed in the hope that it will be useful, but
|
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
* See the GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.";
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
|
|
||||||
#include <sxmp/base64.h>
|
|
||||||
|
|
||||||
static const char b64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
||||||
|
|
||||||
static inline void encodeblock(unsigned char *in, unsigned char *out, int len)
|
|
||||||
{
|
|
||||||
out[0] = (unsigned char) b64[ (int)(in[0] >> 2) ];
|
|
||||||
out[1] = (unsigned char) b64[ (int)(((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4)) ];
|
|
||||||
out[2] = (unsigned char) (len > 1 ? b64[ (int)(((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6)) ] : '=');
|
|
||||||
out[3] = (unsigned char) (len > 2 ? b64[ (int)(in[2] & 0x3f) ] : '=');
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void decodeblock(unsigned char *in, unsigned char *out)
|
|
||||||
{
|
|
||||||
out[0] = (unsigned char) (in[0] << 2 | in[1] >> 4);
|
|
||||||
out[1] = (unsigned char) (in[1] << 4 | in[2] >> 2);
|
|
||||||
out[2] = (unsigned char) (((in[2] << 6) & 0xc0) | in[3]);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t sx_rawlen2b64len(size_t raw_length)
|
|
||||||
{
|
|
||||||
return 4 * ((raw_length + 2) / 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t sx_b64encode_in(const char *data, char *bdata, size_t data_len)
|
|
||||||
{
|
|
||||||
size_t bdata_len = 0, c = 0, n = 0;
|
|
||||||
int len = 0, nil = 0, i;
|
|
||||||
unsigned char ib[4];
|
|
||||||
|
|
||||||
if(!bdata) return -1;
|
|
||||||
if(!data || !data_len) return -1;
|
|
||||||
else bdata_len = sx_rawlen2b64len(data_len);
|
|
||||||
|
|
||||||
while(n != bdata_len) {
|
|
||||||
if((c + 3) <= data_len) {
|
|
||||||
len = 3;
|
|
||||||
encodeblock((unsigned char *)data + c, (unsigned char *)bdata + n, len);
|
|
||||||
n += 4; c += 3;
|
|
||||||
} else {
|
|
||||||
nil = (c + 3) - data_len;
|
|
||||||
len = 0;
|
|
||||||
for(i = 0; i < 3; i++) {
|
|
||||||
if(i < nil) {
|
|
||||||
ib[i] = *((unsigned char *)data + (c + i));
|
|
||||||
len++;
|
|
||||||
} else ib[i] = (unsigned char)0;
|
|
||||||
}
|
|
||||||
encodeblock(ib, (unsigned char *)bdata + n, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bdata_len;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *sx_b64encode(const char *data, size_t data_len)
|
|
||||||
{
|
|
||||||
char *bdata = NULL;
|
|
||||||
size_t bdata_len = 0;
|
|
||||||
|
|
||||||
if(!data || !data_len) return NULL;
|
|
||||||
else bdata_len = sx_rawlen2b64len(data_len);
|
|
||||||
|
|
||||||
if(!(bdata = malloc(bdata_len))) return NULL;
|
|
||||||
|
|
||||||
sx_b64encode_in(data, bdata, data_len);
|
|
||||||
|
|
||||||
return bdata;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t sx_b64decode_in(const char *idata, size_t idata_len, char *data, size_t data_len)
|
|
||||||
{
|
|
||||||
size_t enc = 0, dec = 0;
|
|
||||||
|
|
||||||
if(!idata || !idata_len) return -1;
|
|
||||||
if(!data || !data_len) return -1;
|
|
||||||
|
|
||||||
for(enc = 0; enc != idata_len; enc += 4) {
|
|
||||||
if(dec >= data_len) return dec;
|
|
||||||
decodeblock((unsigned char *)idata + enc, (unsigned char *)data + dec);
|
|
||||||
dec += 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dec;
|
|
||||||
}
|
|
@ -40,11 +40,11 @@
|
|||||||
|
|
||||||
#include <tdata/usrtc.h>
|
#include <tdata/usrtc.h>
|
||||||
#include <tdata/list.h>
|
#include <tdata/list.h>
|
||||||
|
#include <sxt/base64.h>
|
||||||
#include <sexpr/sexp.h>
|
#include <sexpr/sexp.h>
|
||||||
|
|
||||||
#include <sxmp/limits.h>
|
#include <sxmp/limits.h>
|
||||||
#include <sxmp/sxmp.h>
|
#include <sxmp/sxmp.h>
|
||||||
#include <sxmp/base64.h>
|
|
||||||
|
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
|
|
||||||
@ -413,17 +413,17 @@ size_t sxstream_bwriteat(sxstream_t *stream, const void *buf,
|
|||||||
int idx, r;
|
int idx, r;
|
||||||
|
|
||||||
msglen = strlen(_SXSTREAMBWRITE_CMD) + sizeof(char)*8 + 32*sizeof(char);
|
msglen = strlen(_SXSTREAMBWRITE_CMD) + sizeof(char)*8 + 32*sizeof(char);
|
||||||
if(MAX_RBBUF_LEN - msglen < sx_rawlen2b64len(buf_len)) /* cut the data */
|
if(MAX_RBBUF_LEN - msglen < sxt_rawlen2b64len(buf_len)) /* cut the data */
|
||||||
buf_len = ((MAX_RBBUF_LEN - msglen)/4)*3 - 2;
|
buf_len = ((MAX_RBBUF_LEN - msglen)/4)*3 - 2;
|
||||||
|
|
||||||
msglen += sx_rawlen2b64len(buf_len);
|
msglen += sxt_rawlen2b64len(buf_len);
|
||||||
if(!(mbuf = malloc(msglen))) {
|
if(!(mbuf = malloc(msglen))) {
|
||||||
errno = SXE_ENOMEM;
|
errno = SXE_ENOMEM;
|
||||||
goto __fail;
|
goto __fail;
|
||||||
}
|
}
|
||||||
msglen = snprintf(mbuf, msglen, "(%s %lu %lu %lu \"", _SXSTREAMBWRITE_CMD, stream->sid,
|
msglen = snprintf(mbuf, msglen, "(%s %lu %lu %lu \"", _SXSTREAMBWRITE_CMD, stream->sid,
|
||||||
off, buf_len);
|
off, buf_len);
|
||||||
wr = sx_b64encode_in(buf, mbuf + msglen, buf_len);
|
wr = sxt_b64encode_in(buf, mbuf + msglen, buf_len);
|
||||||
if(wr < 0) goto __fail;
|
if(wr < 0) goto __fail;
|
||||||
else msglen += wr;
|
else msglen += wr;
|
||||||
msglen += snprintf(mbuf + msglen, MAX_RBBUF_LEN - msglen, "\")");
|
msglen += snprintf(mbuf + msglen, MAX_RBBUF_LEN - msglen, "\")");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user