Milter smfi_setpriv()

Set aside private data for later use All sendmail versions

Often, a Milter will need private data to keep track of things such as individual headers viewed, or will need to buffer data, such as the parts of a message’s body. The Milter library provides a means to set aside and use private data. You declare the data using this smfi_setpriv() routine, then later fetch it using the smfi_getpriv() routine (Milter smfi_getpriv() on page 1189). The smfi_setpriv() routine is used like this:

ret = smfi_setpriv(ctx, datap);

Here, ctx is the common context pointer that was passed to your xxfi_eom() function. The datap is a pointer that contains the address of your data. The smfi_setpriv() routine expects a datap that is of type void *, so you may need to cast your call, depending on how picky your compiler is:

ret = smfi_setpriv(ctx, (void *)datap);

The data to which datap points must not be automatic or local because it must survive calls to multiple xxfi_ functions. Instead, you should allocate the space and free it when done. Consider, for example, the following:

typedef struct {
    char        **rheads;
    int           nheads;
} MY_DATUM;

MY_DATUM *mdp = calloc(1, sizeof(MY_DATUM));

ret = smfi_setpriv(ctx, mdp);

Each context (ctx) may have only one private data pointer. If you call smfi_setpriv() twice with the same ctx, the first pointer will be discarded and replaced with the second, possibly resulting in a memory leak.

The return value (ret) will be MI_FAILURE only if the context pointer ...

Get sendmail, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.