netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
bstraux.h File Reference

C example that implements trivial additional functions. More...

`#include <time.h>`
`#include <bstrlib.h>`

Go to the source code of this file.

## Macros
#define | bstrDeclare(b)
#define | bstrFree(b)
#define | bAssign(a, b)
#define | bSubs(b, pos, len, a, c)
#define | bStrchr(b, c)
#define | bStrchrFast(b, c)
#define | bCatCstr(b, s)
#define | bCatBlk(b, s, len)
#define | bCatStatic(b, s)
#define | bTrunc(b, n)
#define | bReplaceAll(b, find, repl, pos)
#define | bUppercase(b)
#define | bLowercase(b)
#define | bCaselessCmp(a, b)
#define | bCaselessNCmp(a, b, n)
#define | bBase64Decode(b)
#define | bUuDecode(b)
#define | bAscTime(t)
#define | bCTime(t)
#define | bSecureDestroy(b)
#define | bSecureWriteProtect(t)

## Typedefs
typedef int(* | bNwrite) (const void *buf, size_t elsize, size_t nelem, void *parm)

## Functions
BSTR_PUBLIC struct bStream * | bsFromBstr (const bstring b)
BSTR_PUBLIC bstring | bTail (bstring b, int n)
BSTR_PUBLIC bstring | bHead (bstring b, int n)
BSTR_PUBLIC int | bSetCstrChar (bstring a, int pos, char c)
BSTR_PUBLIC int | bSetChar (bstring b, int pos, char c)
BSTR_PUBLIC int | bFill (bstring a, char c, int len)
BSTR_PUBLIC int | bReplicate (bstring b, int n)
BSTR_PUBLIC int | bReverse (bstring b)
BSTR_PUBLIC int | bInsertChrs (bstring b, int pos, int len, unsigned char c, unsigned char fill)
BSTR_PUBLIC bstring | bStrfTime (const char *fmt, const struct tm *timeptr)
BSTR_PUBLIC int | bJustifyLeft (bstring b, int space)
BSTR_PUBLIC int | bJustifyRight (bstring b, int width, int space)
BSTR_PUBLIC int | bJustifyMargin (bstring b, int width, int space)
BSTR_PUBLIC int | bJustifyCenter (bstring b, int width, int space)
BSTR_PUBLIC char * | bStr2NetStr (const bstring b)
BSTR_PUBLIC bstring | bNetStr2Bstr (const char *buf)
BSTR_PUBLIC bstring | bBase64Encode (const bstring b)
BSTR_PUBLIC bstring | bBase64DecodeEx (const bstring b, int *boolTruncError)
BSTR_PUBLIC struct bStream * | bsUuDecode (struct bStream *sInp, int *badlines)
BSTR_PUBLIC bstring | bUuDecodeEx (const bstring src, int *badlines)
BSTR_PUBLIC bstring | bUuEncode (const bstring src)
BSTR_PUBLIC bstring | bYEncode (const bstring src)
BSTR_PUBLIC bstring | bYDecode (const bstring src)
BSTR_PUBLIC int | bSGMLEncode (bstring b)
BSTR_PUBLIC struct bwriteStream * | bwsOpen (bNwrite writeFn, void *parm)
BSTR_PUBLIC int | bwsWriteBstr (struct bwriteStream *stream, const bstring b)
BSTR_PUBLIC int | bwsWriteBlk (struct bwriteStream *stream, void *blk, int len)
BSTR_PUBLIC int | bwsWriteFlush (struct bwriteStream *stream)
BSTR_PUBLIC int | bwsIsEOF (const struct bwriteStream *stream)
BSTR_PUBLIC int | bwsBuffLength (struct bwriteStream *stream, int sz)
BSTR_PUBLIC void * | bwsClose (struct bwriteStream *stream)
BSTR_PUBLIC bstring | bSecureInput (int maxlen, int termchar, bNgetc vgetchar, void *vgcCtx)

## Detailed Description

C example that implements trivial additional functions.

This file is not a necessary part of the core bstring library itself, but is just an auxilliary module which includes miscellaneous or trivial functions.

## Macro Definition Documentation

## ◆ bAscTime

#define bAscTime | ( |  | t | ) |

Value:
(bStrfTime ("%c\n", (t)))
bStrfTime
bstring bStrfTime(const char *fmt, const struct tm *timeptr)
Definition bstraux.c:954

## ◆ bAssign

#define bAssign | ( |  | a,
|  |  | b )

Value:
((bassign)((a), (b)))
bassign
int bassign(bstring a, const bstring b)
Definition bstrlib.c:467

## ◆ bBase64Decode

#define bBase64Decode | ( |  | b | ) |

Value:
(bBase64DecodeEx((b), NULL))
bBase64DecodeEx
bstring bBase64DecodeEx(const bstring b, int *boolTruncError)
Definition bstraux.c:439
NULL
#define NULL
Definition utf8util.c:47

## ◆ bCaselessCmp

#define bCaselessCmp | ( |  | a,
|  |  | b )

Value:
((bstricmp)((a), (b)))
bstricmp
int bstricmp(const bstring b0, const bstring b1)
Definition bstrlib.c:620

## ◆ bCaselessNCmp

#define bCaselessNCmp | ( |  | a,
|  |  | b,
|  |  | n )

Value:
((bstrnicmp)((a), (b), (n)))
bstrnicmp
int bstrnicmp(const bstring b0, const bstring b1, int n)
Definition bstrlib.c:656

## ◆ bCatBlk

#define bCatBlk | ( |  | b,
|  |  | s,
|  |  | len )

Value:
((bcatblk)((b), (s), (len)))
bcatblk
int bcatblk(bstring b, const void *s, int len)
Definition bstrlib.c:410

## ◆ bCatCstr

#define bCatCstr | ( |  | b,
|  |  | s )

Value:
((bcatcstr)((b), (s)))
bcatcstr
int bcatcstr(bstring b, const char *s)
Definition bstrlib.c:386

## ◆ bCatStatic

#define bCatStatic | ( |  | b,
|  |  | s )

Value:
bcatStatic(b, s)
bcatStatic
#define bcatStatic(b, s)
Definition bstrlib.h:1597

## ◆ bCTime

#define bCTime | ( |  | t | ) |

Value:
((t) ? bAscTime (localtime (t)) : NULL)
bAscTime
#define bAscTime(t)
Definition bstraux.h:195

## ◆ bLowercase

#define bLowercase | ( |  | b | ) |

Value:
((btolower)(b))
btolower
int btolower(bstring b)
Definition bstrlib.c:605

## ◆ bReplaceAll

#define bReplaceAll | ( |  | b,
|  |  | find,
|  |  | repl,
|  |  | pos )

Value:
((bfindreplace)((b),(find),(repl),(pos)))
bfindreplace
int bfindreplace(bstring b, const bstring find, const bstring repl, int pos)
Definition bstrlib.c:1830

## ◆ bSecureDestroy

#define bSecureDestroy | ( |  | b | ) |

Value:
do { \
if ((b) && (b)->mlen > 0 && (b)->data) { \
(void)memset((b)->data, 0, (size_t)(b)->mlen); \
} \
(void)bdestroy((b)); \
} while (0)
bdestroy
int bdestroy(bstring b)
Definition bstrlib.c:1024
data
#define data
Definition hash.c:38

## ◆ bSecureWriteProtect

#define bSecureWriteProtect | ( |  | t | ) |

Value:
do { \
if ((t).mlen >= 0) { \
if ((t).mlen > (t).slen)) { \
(void)memset((t).data + (t).slen, 0, \
(size_t)(t).mlen - (t).slen); \
} \
(t).mlen = -1; \
} \
} while (0)

## ◆ bStrchr

#define bStrchr | ( |  | b,
|  |  | c )

Value:
((bstrchr)((b), (c)))
bstrchr
#define bstrchr(b, c)
Definition bstrlib.h:676
c
size_t c
Definition dircache.c:257

## ◆ bStrchrFast

#define bStrchrFast | ( |  | b,
|  |  | c )

Value:
((bstrchr)((b), (c)))

## ◆ bstrDeclare

#define bstrDeclare | ( |  | b | ) |

Value:
bstring(b) = NULL
bstring
struct tagbstring * bstring
Definition bstrlib.h:86

## ◆ bstrFree

#define bstrFree | ( |  | b | ) |

Value:
do { \
if ((b) != NULL && (b)->slen >= 0 && (b)->mlen >= (b)->slen) { \
bdestroy(b); \
(b) = NULL; \
} \
} while (0)

## ◆ bSubs

#define bSubs | ( |  | b,
|  |  | pos,
|  |  | len,
|  |  | a,
|  |  | c )

Value:
((breplace)((b),(pos),(len),(a),(unsigned char)(c)))
breplace
int breplace(bstring b1, int pos, int len, const bstring b2, unsigned char fill)
Definition bstrlib.c:1587

## ◆ bTrunc

#define bTrunc | ( |  | b,
|  |  | n )

Value:
((btrunc)((b), (n)))
btrunc
int btrunc(bstring b, int n)
Definition bstrlib.c:566

## ◆ bUppercase

#define bUppercase | ( |  | b | ) |

Value:
((btoupper)(b))
btoupper
int btoupper(bstring b)
Definition bstrlib.c:590

## ◆ bUuDecode

#define bUuDecode | ( |  | b | ) |

Value:
(bUuDecodeEx((b), NULL))
bUuDecodeEx
bstring bUuDecodeEx(const bstring src, int *badlines)
Definition bstraux.c:666

## Typedef Documentation

## ◆ bNwrite

typedef int(* bNwrite) (const void *buf, size_t elsize, size_t nelem, void *parm)

## Function Documentation

## ◆ bBase64DecodeEx()

BSTR_PUBLIC 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()

BSTR_PUBLIC bstring bBase64Encode | ( | const bstring | b | ) |

Generate a base64 encoding.

See: RFC1341

## ◆ bFill()

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

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

## ◆ bHead()

BSTR_PUBLIC bstring bHead | ( | bstring | b,
|  | int | n )

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

## ◆ bInsertChrs()

BSTR_PUBLIC 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()

BSTR_PUBLIC 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()

BSTR_PUBLIC int bJustifyLeft | ( | bstring | b,
|  | int | space )

Left justify a string.

## ◆ bJustifyMargin()

BSTR_PUBLIC 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()

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

Right justify a string to within a given width.

## ◆ bNetStr2Bstr()

BSTR_PUBLIC 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()

BSTR_PUBLIC int bReplicate | ( | bstring | b,
|  | int | n )

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

## ◆ bReverse()

BSTR_PUBLIC int bReverse | ( | bstring | b | ) |

Reverse the contents of b in place.

## ◆ bSecureInput()

BSTR_PUBLIC 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()

BSTR_PUBLIC 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()

BSTR_PUBLIC 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()

BSTR_PUBLIC 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.

## ◆ bSGMLEncode()

BSTR_PUBLIC int bSGMLEncode | ( | bstring | b | ) |

Change the string into a version that is quotable in SGML (HTML, XML). Replaces &, ", <, > with their SGML entity equivalents.

Parameters

  b | the bstring to encode in-place

Returns
  BSTR_OK on success, BSTR_ERR on error

## ◆ bStr2NetStr()

BSTR_PUBLIC 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()

BSTR_PUBLIC 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()

BSTR_PUBLIC 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.

## ◆ bTail()

BSTR_PUBLIC bstring bTail | ( | bstring | b,
|  | int | n )

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

## ◆ bUuDecodeEx()

BSTR_PUBLIC 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()

BSTR_PUBLIC bstring bUuEncode | ( | const bstring | src | ) |

Performs a UUEncode of a block of data.

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

## ◆ bwsBuffLength()

BSTR_PUBLIC 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()

BSTR_PUBLIC 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()

BSTR_PUBLIC 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()

BSTR_PUBLIC 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()

BSTR_PUBLIC 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()

BSTR_PUBLIC 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()

BSTR_PUBLIC int bwsWriteFlush | ( | struct bwriteStream * | stream | ) |

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

## ◆ bYDecode()

BSTR_PUBLIC 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()

BSTR_PUBLIC 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