Home

Traffic Server Software Developers Kit

Guide to Traffic Server HTTP Header System

No Null-Terminated Strings

It's not safe to assume that string data contained in marshal buffers (such as URLs and MIME fields) is stored in null-terminated string copies. Therefore, your plugins should always use the length parameter when retrieving or manipulating these strings. You cannot pass in NULL for string-length return values; string values returned from marshall buffers are not null-terminated. If you need a null-terminated value, then use INKstrndup to automatically null-terminate a string. The strings that come back and are not null-terminated cannot be passed into the common str*() routines

[Note] Note

Values returned from a marshall buffer can be NULL, which means the field or object requested does not exist.

For example (from the blacklist-1 sample):

char *host_string;
int host_length;
host_string = INKUrlHostGet (bufp, url_loc, &host_length);
for (i = 0; i < nsites; i++) {
if (strncmp (host_string, sites[i], host_length) == 0) {
...
}

See the sample plugins for additional examples.