netatalk  4.4.2
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
bstraux.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <ctype.h>
#include "bstraux.h"

Data Structures

struct  bUuInOut
struct  bsUuCtx
struct  bwriteStream

Macros

#define B64_PAD   (-2)
#define B64_ERR   (-1)
#define UU_DECODE_BYTE(b)
#define UU_MAX_LINELEN   45
#define UU_ENCODE_BYTE(b)
#define MAX_OB_LEN   (64)
#define INIT_SECURE_INPUT_LENGTH   (256)
#define BWS_BUFF_SZ   (BUFSIZ)
#define internal_bwswriteout(ws, b)

Functions

bstring bTail (bstring b, int n)
bstring bHead (bstring b, int n)
int bFill (bstring b, char c, int len)
int bReplicate (bstring b, int n)
int bReverse (bstring b)
int bInsertChrs (bstring b, int pos, int len, unsigned char c, unsigned char fill)
int bJustifyLeft (bstring b, int space)
int bJustifyRight (bstring b, int width, int space)
int bJustifyCenter (bstring b, int width, int space)
int bJustifyMargin (bstring b, int width, int space)
static size_t readNothing (BSTR_UNUSED void *buff, BSTR_UNUSED size_t elsize, BSTR_UNUSED size_t nelem, BSTR_UNUSED void *parm)
struct bStreambsFromBstr (const bstring b)
static size_t readRef (void *buff, size_t elsize, size_t nelem, void *parm)
static struct bStreambsFromBstrRef (struct tagbstring *t)
char * bStr2NetStr (const bstring b)
bstring bNetStr2Bstr (const char *buff)
bstring bBase64Encode (const bstring b)
static int base64DecodeSymbol (unsigned char alpha)
bstring bBase64DecodeEx (const bstring b, int *boolTruncError)
static int bUuDecLine (void *parm, int ofs, int len)
bstring bUuDecodeEx (const bstring src, int *badlines)
static size_t bsUuDecodePart (void *buff, size_t elsize, size_t nelem, void *parm)
struct bStreambsUuDecode (struct bStream *sInp, int *badlines)
bstring bUuEncode (const bstring src)
bstring bYEncode (const bstring src)
bstring bYDecode (const bstring src)
bstring bStrfTime (const char *fmt, const struct tm *timeptr)
int bSetCstrChar (bstring b, int pos, char c)
int bSetChar (bstring b, int pos, char c)
bstring bSecureInput (int maxlen, int termchar, bNgetc vgetchar, void *vgcCtx)
struct bwriteStreambwsOpen (bNwrite writeFn, void *parm)
int bwsWriteFlush (struct bwriteStream *ws)
int bwsWriteBstr (struct bwriteStream *ws, const bstring b)
int bwsWriteBlk (struct bwriteStream *ws, void *blk, int len)
int bwsIsEOF (const struct bwriteStream *ws)
int bwsBuffLength (struct bwriteStream *ws, int sz)
void * bwsClose (struct bwriteStream *ws)

Variables

static char b64ETable []

Macro Definition Documentation

◆ B64_ERR

#define B64_ERR   (-1)

◆ B64_PAD

#define B64_PAD   (-2)

◆ BWS_BUFF_SZ

#define BWS_BUFF_SZ   (BUFSIZ)

◆ INIT_SECURE_INPUT_LENGTH

#define INIT_SECURE_INPUT_LENGTH   (256)

◆ internal_bwswriteout

#define internal_bwswriteout ( ws,
b )
Value:
{ \
if ((b)->slen > 0) { \
if (1 != (ws->writeFn ((b)->data, (b)->slen, 1, ws->parm))) { \
ws->isEOF = 1; \
return BSTR_ERR; \
} \
} \
}
#define BSTR_ERR
Definition bstrlib.h:78

◆ MAX_OB_LEN

#define MAX_OB_LEN   (64)

◆ UU_DECODE_BYTE

#define UU_DECODE_BYTE ( b)
Value:
(((b) == (signed int)'`') ? 0 : (b) - (signed int)' ')

◆ UU_ENCODE_BYTE

#define UU_ENCODE_BYTE ( b)
Value:
((char)(((b) == 0) ? '`' : ((b) + ' ')))

◆ UU_MAX_LINELEN

#define UU_MAX_LINELEN   45

Function Documentation

◆ base64DecodeSymbol()

int base64DecodeSymbol ( unsigned char alpha)
static

◆ bBase64DecodeEx()

bstring bBase64DecodeEx ( const bstring b,
int * boolTruncError )

Decode a base64 block of data.

All MIME headers are assumed to have been removed.

See: RFC1341

◆ bBase64Encode()

bstring bBase64Encode ( const bstring b)

Generate a base64 encoding.

See: RFC1341

◆ bFill()

int bFill ( bstring a,
char c,
int len )

Fill a given bstring with the character in parameter c, for a length n.

◆ bHead()

bstring bHead ( bstring b,
int n )

Return with a string of the first n characters of b.

◆ bInsertChrs()

int bInsertChrs ( bstring b,
int pos,
int len,
unsigned char c,
unsigned char fill )

Insert a repeated sequence of a given character into the string at position pos for a length len.

◆ bJustifyCenter()

int bJustifyCenter ( bstring b,
int width,
int space )

Center a string's non-white space characters to within a given width by inserting whitespaces at the beginning.

◆ bJustifyLeft()

int bJustifyLeft ( bstring b,
int space )

Left justify a string.

◆ bJustifyMargin()

int bJustifyMargin ( bstring b,
int width,
int space )

Stretch a string to flush against left and right margins by evenly distributing additional white space between words.

If the line is too long to be margin justified, it is left justified.

◆ bJustifyRight()

int bJustifyRight ( bstring b,
int width,
int space )

Right justify a string to within a given width.

◆ bNetStr2Bstr()

bstring bNetStr2Bstr ( const char * buf)

Convert a netstring to a bstring.

See http://cr.yp.to/proto/netstrings.txt for a description of netstrings.

Note that the terminating "," must be present, however a following '\0' is not required.

◆ bReplicate()

int bReplicate ( bstring b,
int n )

Replicate the contents of b end to end n times and replace it in b.

◆ bReverse()

int bReverse ( bstring b)

Reverse the contents of b in place.

◆ bSecureInput()

bstring bSecureInput ( int maxlen,
int termchar,
bNgetc vgetchar,
void * vgcCtx )

Read input from an abstracted input interface, for a length of at most maxlen characters.

If maxlen <= 0, then there is no length limit put on the input. The result is terminated early if vgetchar() return EOF or the user specified value termchar.

◆ bSetChar()

int bSetChar ( bstring b,
int pos,
char c )

Sets the character at position pos to the character c in the bstring a.

The string is not truncated if the character c is NUL ('\0'). pos must be in the position between 0 and b->slen inclusive, otherwise BSTR_ERR will be returned.

◆ bSetCstrChar()

int bSetCstrChar ( bstring a,
int pos,
char c )

Sets the character at position pos to the character c in the bstring a.

If the character c is NUL ('\0') then the string is truncated at this point. Note: this does not enable any other '\0' character in the bstring as terminator indicator for the string. pos must be in the position between 0 and b->slen inclusive, otherwise BSTR_ERR will be returned.

◆ bsFromBstr()

struct bStream * bsFromBstr ( const bstring b)

Create a bStream whose contents are a copy of the bstring passed in.

This allows the use of all the bStream APIs with bstrings.

◆ bsFromBstrRef()

struct bStream * bsFromBstrRef ( struct tagbstring * t)
static

The "by reference" version of the above function.

This function puts a number of restrictions on the call site (the passed in struct tagbstring will be modified by this function, and the source data must remain alive and constant for the lifetime of the bStream). Hence it is not presented as an extern.

◆ bStr2NetStr()

char * bStr2NetStr ( const bstring b)

Convert a bstring to a netstring.

See http://cr.yp.to/proto/netstrings.txt for a description of netstrings.

Note: 1) The value returned should be freed with a call to bcstrfree() at the point when it will no longer be referenced to avoid a memory leak. 2) If the returned value is non-NULL, then it also '\0' terminated in the character position one past the "," terminator.

◆ bStrfTime()

bstring bStrfTime ( const char * fmt,
const struct tm * timeptr )

Takes a format string that is compatible with strftime and a struct tm pointer, formats the time according to the format string and outputs the bstring as a result.

Note that if there is an early generation of a '\0' character, the bstring will be truncated to this end point.

◆ bsUuDecode()

struct bStream * bsUuDecode ( struct bStream * sInp,
int * badlines )

Creates a bStream which performs the UUDecode of an an input stream.

If there are errors in the decoding, they are counted up and returned in "badlines", if badlines is not NULL. It is assumed that the "begin" and "end" lines have already been stripped off. The potential security problem of writing the filename in the begin line is something that is beyond the scope of a portable library.

◆ bsUuDecodePart()

size_t bsUuDecodePart ( void * buff,
size_t elsize,
size_t nelem,
void * parm )
static

◆ bTail()

bstring bTail ( bstring b,
int n )

Return with a string of the last n characters of b.

◆ bUuDecLine()

int bUuDecLine ( void * parm,
int ofs,
int len )
static

◆ bUuDecodeEx()

bstring bUuDecodeEx ( const bstring src,
int * badlines )

Performs a UUDecode of a block of data.

If there are errors in the decoding, they are counted up and returned in "badlines", if badlines is not NULL. It is assumed that the "begin" and "end" lines have already been stripped off. The potential security problem of writing the filename in the begin line is something that is beyond the scope of a portable library.

◆ bUuEncode()

bstring bUuEncode ( const bstring src)

Performs a UUEncode of a block of data.

The "begin" and "end" lines are not appended.

◆ bwsBuffLength()

int bwsBuffLength ( struct bwriteStream * stream,
int sz )

Set the length of the buffer used by the bwsStream.

If sz is zero, the length is not set. This function returns with the previous length.

◆ bwsClose()

void * bwsClose ( struct bwriteStream * stream)

Close the bwriteStream, and return the handle to the stream that was originally used to open the given stream.

Note that even if the stream is at EOF it still needs to be closed with a call to bwsClose.

◆ bwsIsEOF()

int bwsIsEOF ( const struct bwriteStream * stream)

Returns 0 if the stream is currently writable, 1 if the core stream has responded by not accepting the previous attempted write.

◆ bwsOpen()

struct bwriteStream * bwsOpen ( bNwrite writeFn,
void * parm )

Wrap a given open stream (described by a fwrite work-a-like function pointer and stream handle) into an open bwriteStream suitable for write streaming functions.

◆ bwsWriteBlk()

int bwsWriteBlk ( struct bwriteStream * stream,
void * blk,
int len )

Send a block of data a bwriteStream.

If the stream is at EOF BSTR_ERR is returned.

◆ bwsWriteBstr()

int bwsWriteBstr ( struct bwriteStream * stream,
const bstring b )

Send a bstring to a bwriteStream.

If the stream is at EOF BSTR_ERR is returned. Note that there is no deterministic way to determine the exact cut off point where the core stream stopped accepting data.

◆ bwsWriteFlush()

int bwsWriteFlush ( struct bwriteStream * stream)

Force any pending data to be written to the core stream.

◆ bYDecode()

bstring bYDecode ( const bstring src)

Performs a YDecode of a block of data.

See: https://yence.sourceforge.net/docs/protocol/version1_3_draft.html

◆ bYEncode()

bstring bYEncode ( const bstring src)

Performs a YEncode of a block of data.

No header or tail info is appended.

See: https://yence.sourceforge.net/docs/protocol/version1_3_draft.html

◆ readNothing()

size_t readNothing ( BSTR_UNUSED void * buff,
BSTR_UNUSED size_t elsize,
BSTR_UNUSED size_t nelem,
BSTR_UNUSED void * parm )
static

◆ readRef()

size_t readRef ( void * buff,
size_t elsize,
size_t nelem,
void * parm )
static

Variable Documentation

◆ b64ETable

char b64ETable[]
static
Initial value:
= "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/"