Overview of NSAPI C Functions

                                                                                                                                                                                                                                                                                                                                      Back to [Book]     [Topic]

Overview of NSAPI C Functions

NSAPI provides a set of C functions that are used to implement SAFs. These functions serve several purposes:

  • Provide platform independence across operating system and hardware platforms
  • Improved performance
  • Thread-safe, a requirement for SAFs
  • Prevent memory leaks
  • Provide functionality necessary for implementing SAFs

Always use these NSAPI routines when defining new SAFs.

This section provides an overview of the function categories available and some of the more commonly used routines. All of the public routines are detailed in NSAPI Function and Macro Reference.

The main categories of NSAPI functions are:

Parameter Block Manipulation Routines

The parameter block manipulation functions provide routines for locating, adding, and removing entries in a pblock data structure:

  • pblock_findval returns the value for a given name in a pblock. For more information, see pblock_findval() Function.
  • pblock_nvinsert adds a new name-value pair entry to a pblock. For more information, see pblock_nvinsert() Function.
  • pblock_remove removes a pblock entry by name from a pblock. The entry is not disposed. Use param_free() Function to free the memory used by the entry. For more information, see pblock_remove() Function.
  • param_free frees the memory for the given pblock entry. For more information, see param_free() Function.
  • pblock_pblock2str creates a new string containing all of the name-value pairs from a pblock in the form “name=value name=value.” This function can be a useful for debugging. For more information, see pblock_pblock2str() Function.

Protocol Utilities for Service SAFs

Protocol utilities provide functionality necessary to implement Service SAFs:

Memory Management

Memory management routines provide fast, platform-independent versions of the standard memory management routines. These routines also prevent memory leaks by allocating from a temporary memory, called “pooled” memory for each request, and then disposing the entire pool after each request. Wrappers enable standard memory routines to use permanent memory.

To disable the server's pooled memory allocator for debugging, use the built-in SAF pool-init. For more information, see the Sun Java System Web Server Administrator's Configuration File Reference.

File I/O

The file I/O functions provide platform-independent, thread-safe file I/O routines:

Network I/O

Network I/O functions provide platform-independent, thread-safe network I/O routines. These routines work with SSL when it is enabled:

  • netbuf_grab reads from a network buffer’s socket into the network buffer. For more information, see netbuf_grab() Function.
  • netbuf_getbytes gets a character from a network buffer. For more information, see netbuf_getbytes() Function.
  • net_flush flushes buffered data. For more information, see net_flush() Function.
  • net_read reads bytes from a specified socket into a specified buffer. For more information, see net_read() Function.
  • net_sendfile sends the contents of a specified file to a specified a socket. For more information, see net_sendfile() Function.
  • net_write writes to the network socket. For more information, see net_write() Function.

Threads

Thread functions include functions for creating your own threads that are compatible with the server’s threads. Routines also exist for critical sections and condition variables:

Utilities

Utility functions include platform-independent, thread-safe versions of many standard library functions such as string manipulation, as well as new utilities useful for NSAPI:

  • daemon_atrestart registers a user function to be called when the server is sent a restart signal (HUP) or at shutdown. For more information, see daemon_atrestart() Function.
  • daemon_atrestart gets the local host name as a fully qualified domain name. For more information, see util_hostname() Function.
  • util_later_than compares two dates. For more information, see util_later_than() Function.
  • util_sprintf is the same as the standard library routine sprintf(). For more information, see util_sprintf() Function.
  • util_strftime is the same as the standard library routine strftime(). For more information, see util_strftime() Function.
  • util_uri_escape converts the special characters in a string into URI-escaped format. For more information, see util_uri_escape() Function.
  • util_uri_unescape converts the URI-escaped characters in a string back into special characters. For more information, see util_uri_unescape() Function.
    Note -
    You cannot use an embedded null in a string, because NSAPI functions assume that a null is the end of the string. Therefore, passing Unicode-encoded content through an NSAPI plug-in does not work.

Virtual Server

The virtual server functions provide routines for retrieving information about virtual servers:

  • request_get_vs finds the virtual server to which a request is directed. For more information, see request_get_vs() Function.
  • vs_alloc_slot allocates a new slot for storing a pointer to data specific to a certain virtual server. For more information, see vs_alloc_slot() Function.
  • vs_get_data finds the value of a pointer to data for a given virtual server and slot. For more information, see vs_get_data() Function.
  • vs_get_default_httpd_object obtains a pointer to the default or root object from the virtual server's virtual server class configuration. For more information, see vs_get_default_httpd_object() Function.
  • vs_get_doc_root finds the document root for a virtual server. For more information, see vs_get_doc_root() Function.
  • vs_get_httpd_objset obtains a pointer to the virtual server class configuration for a given virtual server. For more information, see vs_get_httpd_objset Function.
  • vs_get_id finds the ID of a virtual server. For more information, see vs_get_id() Function.
  • vs_get_mime_type determines the MIME type that would be returned in the content-type: header for the given URI. For more information, see vs_get_mime_type() Function.
  • vs_lookup_config_var finds the value of a configuration variable for a given virtual server. For more information, see vs_lookup_config_var() Function.
  • vs_register_cb enables a plug-in to register functions that will receive notifications of virtual server initialization and destruction events. For more information, see vs_register_cb() Function.
  • vs_set_data sets the value of a pointer to data for a given virtual server and slot. For more information, see vs_set_data() Function.
  • vs_translate_uri translates a URI as though it were part of a request for a specific virtual server. For more information, see vs_translate_uri() Function.

Labels

java java Delete
server server Delete
sun sun Delete
webserver webserver Delete
application application Delete
system system Delete
webtier webtier Delete
guide guide Delete
webserver70 webserver70 Delete
sunjava sunjava Delete
nsapi nsapi Delete
nsapidevelopersguide nsapidevelopersguide Delete
developers developers Delete
web web Delete
+nsapiguide +nsapiguide Delete
nsapiguide nsapiguide Delete
developersguide developersguide Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Sign up or Log in to add a comment or watch this page.


The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

Copyright 1994-2009 Sun Microsystems, Inc.
Powered by Atlassian Confluence
Sun Guidelines on Public Discourse Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact