Milter smfi_getpriv()

Fetch private data pointer All sendmail versions

The smfi_setpriv() routine (Milter smfi_setpriv() on page 1199) allows you to set aside and save private data on a per-context basis. From inside any of the xxfi_ routines you write, you may call smfi_getpriv() to fetch a pointer to the private data you earlier saved. You fetch private data like this:

dataptr = (type *)smfi_getpriv(ctx);

The smfi_getpriv() routine’s only argument is the common context pointer ctx passed to the xxfi_ function you write. The value returned (and here stored in dataptr) is a pointer. The smfi_getpriv() routine is of type void *, so you need to cast the return value to a type that matches your saved datatype. If you failed to first set aside a pointer with the smfi_setpriv() routine, smfi_getpriv() will return NULL.

Be very careful with your use of saved data. Milters are multi-threaded and any shared data should be protected with mutexes. If you allocate and free data, be careful to always test the retuned value for NULL to avoid dereferencing a zero address.

Note too that each private data is bound to a single context (the ctx pointer) that is instantiated when each connection starts. Thus, it is best to think of such private data as per-connection private data.

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.