Scroll to navigation

Ns_Conn(3aolserver) AOLserver Library Procedures Ns_Conn(3aolserver)


NAME

Ns_ConnAuthPasswd, Ns_ConnAuthUser, Ns_ConnHeaders, Ns_ConnHost, Ns_ConnId, Ns_ConnLocation, Ns_ConnOutputHeaders, Ns_ConnPeer, Ns_ConnPeerPort, Ns_ConnPort, Ns_ConnResponseLength, Ns_ConnResponseStatus, Ns_ConnServer, Ns_ConnSock - Routines to access data about a connection

SYNOPSIS

#include "ns.h"

char *
Ns_ConnAuthPasswd(Ns_Conn *conn)

char *
Ns_ConnAuthUser(Ns_Conn *conn)

Ns_Set *
Ns_ConnHeaders(Ns_Conn *conn)

char *
Ns_ConnHost(Ns_Conn *conn)

int
Ns_ConnId(Ns_Conn *conn)

char *
Ns_ConnLocation(Ns_Conn *conn)

Ns_Set *
Ns_ConnOutputHeaders(Ns_Conn *conn)

char *
Ns_ConnPeer(Ns_Conn *conn)

int
Ns_ConnPeerPort(Ns_Conn *conn)

int
Ns_ConnPort(Ns_Conn *conn)

int
Ns_ConnResponseLength(Ns_Conn *conn)

int
Ns_ConnResponseStatus(Ns_Conn *conn)

char *
Ns_ConnServer(Ns_Conn *conn)

int
Ns_ConnSock(Ns_Conn *conn)

ARGUMENTS

Ns_Conn *conn (in)
Pointer to given connection.

    

DESCRIPTION

These routines provide access to data stored within an active connection. All routines take as an argument a pointer to an Ns_Conn structure which is setup by the server and passed to request handling procedures.

THE NS_CONN STRUCTURE

The Ns_Conn structure includes the following fields:

typedef struct Ns_Conn {

Ns_Request *request;
Ns_Set *headers;
Ns_Set *outputheaders;
char *authUser;
char *authPasswd;
int contentLength;
int flags; } Ns_Conn;

All fields of an Ns_Conn structure should be considered read-only. The request field contains a pointer to the parsed HTTP request. See the manual page for Ns_ParseRequest for details on what it contains.

The headers and outputHeaders fields point to Ns_Set structures for the input and output headers, respectively. The outputHeaders set will generally not contain any fields until after the request has been processed. See the manual page on Ns_Set for details on the fields of the structure and routines to access and manipulate them.

The authUser and authPasswd fields point to the decoded username and password for the request or NULL if no authorization was sent.

The contentLength field is the length of the content, if any, sent with the request. See the man page on Ns_ConnContent for details on accessing the content.

The flags field is a bitmask with one or more NS_CONN bits:

Connection is closed.
Pre-HTTP/1.0 connection which will not return headers.
HTTP HEAD request which will return no content.
Headers have been read (noramlly set).
Result headers have been sent.
Connection should be kept alive for another request if possible.
Output could be encoded when directly sent.
Connection contains content originally in a temp file.
Connection is currently active in a request thread.
Connection is being rejected due to overflow of a limit.
Connection has timed out waiting for service.
Connection content will be compressed if possible.
Content is being sent in chunked encoding mode.

These flags should be considered read-only. Use the corresponding routines, e.g., Ns_ConnSetKeepAlive, to set the flags if necessary.

CONNECTION ACCESS ROUTINES

In addition to the public fields, the routines above can be used to access data contained in the private components of the connection (in retrospect, all fields should have been private).

Returns the authPassword field for the Ns_Conn stucture.

Returns the authUser field for the Ns_Conn stucture.

Returns the headers field for the Ns_Conn stucture.

Returns the IP address as a string that the communications driver is listening on, e.g., 127.0.0.1 for a server listening for connectionsn on localhost.

Returns a unique integer ID for the connection. The ids start at zero and increase monotonically with each new connection accepted by the server.

Returns a pointer to a string which is the HTTP location for the connection, e.g., http://www.mysite.com. The string can be helpful to construct redirect messages.

Returns the outputHeaders field for the Ns_Conn stucture.

Returns a string with an IP address for the remote end of the connection (e.g., the users browser). Note this could also be the IP address of a proxy server.

Returns the port of the remote end of the connection.

Returns the port for the server end point of the connection, by default port 80.

Returns the length of content sent to the client. The result will be zero until a result has been generated.

Returns the HTTP status code of the responses sent to the client, 200 for normal responses.

Returns a pointer to the string name of the virtual server used for the connection. This string can then be passed to other virtual server specific routines, e.g., Ns_TclAllocateInterp.

Returns the underlying socket file descriptor for the connection. This can be useful for diagnostic or introspection routines (e.g., getpeername). It should otherwise not be manipulated or closed.

SEE ALSO

Ns_Set(3), Ns_ConnContent(3), Ns_ConnGetQuery(3), Ns_ParseRequest(3), ns_conn(n)

KEYWORDS

connection, location, headers

4.0 AOLserver