regify utility  2.0.0-0
Data Cleaning Utility

This section contains a text replacement implementation that is fast and scalable. More...

Typedefs

typedef void * ruCleaner
 
typedef rusize_s(* rcWriteFn) (perm_ptr ctx, trans_ptr buf, rusize len)
 
typedef rusize_s(* rcReadFn) (perm_ptr ctx, ptr buf, rusize len)
 
typedef void(* ruCleanerCb) (perm_ptr user_data, trans_chars key, trans_chars subst)
 

Functions

RUAPI ruCleaner ruCleanNew (rusize chunkSize)
 Creates a new ruCleaner object. To be freed with ruCleanFree. More...
 
RUAPI ruCleaner ruCleanFree (ruCleaner rc)
 
RUAPI int32_t ruCleanDump (ruCleaner cp, ruCleanerCb lf, perm_ptr user_data)
 
RUAPI int32_t ruCleanAdd (ruCleaner rc, trans_chars instr, trans_chars substitute)
 
RUAPI int32_t ruCleanRemove (ruCleaner rc, trans_chars instr)
 
RUAPI int32_t ruCleanIo (ruCleaner rc, rcReadFn reader, perm_ptr readCtx, rcWriteFn writer, perm_ptr writeCtx)
 Does replacements using the given I/O functions. More...
 
RUAPI int32_t ruCleanToWriter (ruCleaner rc, trans_chars in, rusize len, rcWriteFn writer, perm_ptr writeCtx)
 Does replacements on given string using the given Output function. More...
 
RUAPI int32_t ruCleanToString (ruCleaner rc, trans_chars in, rusize len, ruString *out)
 Does replacements in given string and returns out in given String Object. More...
 

Detailed Description

This section contains a text replacement implementation that is fast and scalable.

It is meant to be used to clean credentials out of large files in a minimum amount of time.

Example:

#include <stdio.h>
#include <regify-util.h>
rusize_s reader(const void* in, void* data, rusize len) {
return (rusize_s) fread(data, len, 1, (FILE*)in);
}
rusize_s writer(const void* out, const void* data, rusize len) {
return (rusize_s) fwrite(data, len, 1, (FILE*)out);
}
void clean() {
int32_t ret;
FILE *in = 0, *out = 0;
const char* repl = "^^^PASSWORD^^^";
do {
ret = ruCleanAdd(rc, "mysecret", repl);
if (ret != RUE_OK) {
printf("Failed adding secret: %d", ret);
break;
}
ret = ruCleanAdd(rc, "myothersecret", repl);
if (ret != RUE_OK) {
printf("Failed adding other secret: %d", ret);
break;
}
in = ruFOpen("debug.log", "r", &ret);
if (ret != RUE_OK) {
printf("Failed opening debug.log: %d", ret);
break;
}
out = ruFOpen("clean.log", "w", &ret);
if (ret != RUE_OK) {
printf("Failed opening clean.log: %d", ret);
break;
}
ret = ruCleanIo(rc, &reader, in, &writer, out);
if (ret != RUE_OK) {
printf("Failed setting I/O context: %d", ret);
break;
}
ret = ruCleanNow(rc);
if (ret != RUE_OK) {
printf("Failed cleaning log: %d", ret);
break;
}
} while(0);
if (in) fclose(in);
if (out) fclose(out);
}
RUAPI int32_t ruCleanAdd(ruCleaner rc, trans_chars instr, trans_chars substitute)
void * ruCleaner
Definition: regify-util.h:690
RUAPI ruCleaner ruCleanFree(ruCleaner rc)
RUAPI ruCleaner ruCleanNew(rusize chunkSize)
Creates a new ruCleaner object. To be freed with ruCleanFree.
RUAPI int32_t ruCleanIo(ruCleaner rc, rcReadFn reader, perm_ptr readCtx, rcWriteFn writer, perm_ptr writeCtx)
Does replacements using the given I/O functions.
RUAPI FILE * ruFOpen(trans_chars filepath, trans_chars mode, int32_t *code)
size_t rusize
Abstracted version of size_t.
Definition: regify-util.h:338
signed long rusize_s
Abstracted version of size_t but signed.
Definition: regify-util.h:152
#define RUE_OK
Definition: errors.h:66

Typedef Documentation

◆ rcReadFn

typedef rusize_s(* rcReadFn) (perm_ptr ctx, ptr buf, rusize len)

The type function for the read operation when cleaning a data stream.

◆ rcWriteFn

typedef rusize_s(* rcWriteFn) (perm_ptr ctx, trans_ptr buf, rusize len)

The type function for the write operation when cleaning a data stream.

◆ ruCleaner

typedef void* ruCleaner

Opaque pointer to cleaner object. See Data Cleaning Utility

◆ ruCleanerCb

typedef void(* ruCleanerCb) (perm_ptr user_data, trans_chars key, trans_chars subst)

A callback for the ruCleanDump function. The given key and subst parameters belong to the cleaner and must not be freed.

Parameters
user_dataThe optional context that was given to ruCleanDump.
keyThe secret key to clean.
substThe placeholder to substitute the secret with.

Function Documentation

◆ ruCleanAdd()

RUAPI int32_t ruCleanAdd ( ruCleaner  rc,
trans_chars  instr,
trans_chars  substitute 
)

Adds a new string to be replaced.

Parameters
rcThe relevant ruCleaner object
instrThe string to be replaced. Will be copied.
substituteThe string to replace instr with. Will be copied.
Returns
RUE_OK on success else an error code.

◆ ruCleanDump()

RUAPI int32_t ruCleanDump ( ruCleaner  cp,
ruCleanerCb  lf,
perm_ptr  user_data 
)

Iterates over the cleaner database and calls given ruCleanerCb with each secret and substitute. This function is mainly used for debugging.

Parameters
cpThe relevant ruCleaner object
lfThe ruCleanerCb to call with each entry
user_dataAn optional context that will be given to the callbacks user_data parameter.
Returns
RUE_OK on success else an error code.

◆ ruCleanFree()

RUAPI ruCleaner ruCleanFree ( ruCleaner  rc)

Frees the given ruCleaner object.

Parameters
rclist to free.
Returns
NULL

◆ ruCleanIo()

RUAPI int32_t ruCleanIo ( ruCleaner  rc,
rcReadFn  reader,
perm_ptr  readCtx,
rcWriteFn  writer,
perm_ptr  writeCtx 
)

Does replacements using the given I/O functions.

This can be an opened file with the corresponding file handle as context. This function may be called multiple times and interchangeably with the ruCleanTo* functions.

Parameters
rcThe relevant ruCleaner object
readerThe read function to be called for data input.
readCtxThe context to be passed to the read function.
writerThe write function to be called for data output.
writeCtxThe context to be passed to the write function.
Returns
RUE_OK on success else an error code.

◆ ruCleanNew()

RUAPI ruCleaner ruCleanNew ( rusize  chunkSize)

Creates a new ruCleaner object. To be freed with ruCleanFree.

Unless the ruCleaner comes from a pwcleaner library which lacks the remaining regify-util functionality, it is made thread safe by the internal use of a mutex. pwcleaner users need to do their own locking in multi threaded use cases.

Parameters
chunkSizeSize of chunk to process at a time. Will be allocated twice. Will be increased to the largest item to clean if that is bigger. Defaults to 1M if set to 0.
Returns
Guaranteed to return new ruCleaner object, or process abort.

◆ ruCleanRemove()

RUAPI int32_t ruCleanRemove ( ruCleaner  rc,
trans_chars  instr 
)

Removes a string entry from the database.

Parameters
rcThe relevant ruCleaner object
instrThe string to be removed
Returns
RUE_OK on success else an error code.

◆ ruCleanToString()

RUAPI int32_t ruCleanToString ( ruCleaner  rc,
trans_chars  in,
rusize  len,
ruString out 
)

Does replacements in given string and returns out in given String Object.

This function may be called multiple times and interchangeably with the ruCleanTo*, ruCleanIo functions. This function is thread safe but locks allow only one thread at time.

Parameters
rcThe relevant ruCleaner object
inString to replace tokens in.
lenLength of the string or 0 to use the null terminator for length detection.
outWhere the String Object containing the result will be stored. Caller must free with ruStringFree after use.
Returns
RUE_OK on success else an error code.

◆ ruCleanToWriter()

RUAPI int32_t ruCleanToWriter ( ruCleaner  rc,
trans_chars  in,
rusize  len,
rcWriteFn  writer,
perm_ptr  writeCtx 
)

Does replacements on given string using the given Output function.

This can be an opened file with the corresponding file handle as context. This function may be called multiple times and interchangeably with the ruCleanTo*, ruCleanIo functions. This function is thread safe but locks allow only one thread at time.

Parameters
rcThe relevant ruCleaner object
inString to replace tokens in.
lenLength of the string or 0 to use the null terminator for length detection.
writerThe write function to be called for data output.
writeCtxThe context to be passed to the write function.
Returns
RUE_OK on success else an error code.