• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

ts.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   Traffic Server SDK API header file
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022 
00023   @section developers Developers
00024 
00025   Developers, when adding a new element to an enum, append it. DO NOT
00026   insert it.  Otherwise, binary compatibility of plugins will be broken!
00027 
00028  */
00029 
00030 #ifndef __TS_API_H__
00031 #define __TS_API_H__
00032 
00033 #include "apidefs.h"
00034 
00035 #ifdef __cplusplus
00036 extern "C"
00037 {
00038 #endif /* __cplusplus */
00039 
00040   /* --------------------------------------------------------------------------
00041      Memory */
00042 #define TSmalloc(s)      _TSmalloc ((s), TS_RES_MEM_PATH)
00043 #define TSrealloc(p,s)   _TSrealloc ((p), (s), TS_RES_MEM_PATH)
00044 #define TSstrdup(p)      _TSstrdup ((p), -1, TS_RES_MEM_PATH)
00045 #define TSstrndup(p,n)   _TSstrdup ((p), (n), TS_RES_MEM_PATH)
00046 #define TSstrlcpy(d,s,l) _TSstrlcpy ((d), (s), (l))
00047 #define TSstrlcat(d,s,l) _TSstrlcat ((d), (s), (l))
00048 #define TSfree(p)        _TSfree (p)
00049 
00050   tsapi void* _TSmalloc(size_t size, const char* path);
00051   tsapi void* _TSrealloc(void* ptr, size_t size, const char* path);
00052   tsapi char* _TSstrdup(const char* str, int64_t length, const char* path);
00053   tsapi size_t _TSstrlcpy(char *dst, const char *str, size_t siz);
00054   tsapi size_t _TSstrlcat(char *dst, const char *str, size_t siz);
00055   tsapi void _TSfree(void* ptr);
00056 
00057   /* --------------------------------------------------------------------------
00058      Component object handles */
00059   /**
00060       Releases the TSMLoc mloc created from the TSMLoc parent.
00061       If there is no parent TSMLoc, use TS_NULL_MLOC.
00062 
00063       @param bufp marshal buffer containing the TSMLoc handle to be
00064         released.
00065       @param parent location of the parent object from which the handle
00066         was created.
00067       @param mloc location of the handle to be released.
00068 
00069    */
00070   tsapi TSReturnCode TSHandleMLocRelease(TSMBuffer bufp, TSMLoc parent, TSMLoc mloc);
00071 
00072   /* --------------------------------------------------------------------------
00073      Install and plugin locations */
00074   /**
00075       Gets the path of the directory in which Traffic Server is installed.
00076       Use this function to specify the location of files that the
00077       plugin uses.
00078 
00079       @return pointer to Traffic Server install directory.
00080 
00081    */
00082   tsapi const char* TSInstallDirGet(void);
00083 
00084   /**
00085       Gets the path of the directory of Traffic Server configuration.
00086 
00087       @return pointer to Traffic Server configuration directory.
00088 
00089    */
00090   tsapi const char* TSConfigDirGet(void);
00091 
00092   /**
00093       Gets the path of the plugin directory relative to the Traffic Server
00094       install directory. For example, to open the file "config_ui.txt" in
00095       the plugin directory:
00096 
00097       @code
00098       TSfopen("TSPluginInstallDirGet()/TSPluginDirGet()/config_ui.txt");
00099       @endcode
00100 
00101       @return pointer to plugin directory relative to Traffic Server install
00102       directory.
00103 
00104    */
00105   tsapi const char* TSPluginDirGet(void);
00106 
00107   /* --------------------------------------------------------------------------
00108      Traffic Server Version */
00109   /**
00110       Gets the version of Traffic Server currently running. Use this
00111       function to make sure that the plugin version and Traffic Server
00112       version are compatible. See the SDK sample code for usage.
00113 
00114       @return pointer to version of Traffic Server running the plugin.
00115 
00116    */
00117   tsapi const char* TSTrafficServerVersionGet(void);
00118 
00119   /**  Get the major version of Traffic Server currently running.
00120        This is the same as the first element of the string
00121        returned by @c TSTrafficServerVersionGet
00122 
00123        @return The major version as an integer.
00124    */
00125   int TSTrafficServerVersionGetMajor(void);
00126 
00127   /**  Get the minor version of Traffic Server currently running.
00128        This is the same as the second element of the string
00129        returned by @c TSTrafficServerVersionGet
00130 
00131        @return The minor version as an integer.
00132    */
00133   int TSTrafficServerVersionGetMinor(void);
00134 
00135   /**  Get the patch version of Traffic Server currently running.
00136        This is the same as the third element of the string
00137        returned by @c TSTrafficServerVersionGet
00138 
00139        @return The patch version as an integer.
00140    */
00141   int TSTrafficServerVersionGetPatch(void);
00142 
00143   /* --------------------------------------------------------------------------
00144      Plugin registration */
00145 
00146   /**
00147       This function registers your plugin with a particular version
00148       of Traffic Server SDK. Use this function to make sure that the
00149       Traffic Server version currently running also supports your plugin.
00150       See the SDK sample code for usage.
00151 
00152       @param sdk_version earliest version of the Traffic Server SDK that
00153         supports your plugin.
00154       @param plugin_info contains registration information about your
00155         plugin. See TSPluginRegistrationInfo.
00156       @return TS_ERROR if the plugin registration failed.
00157 
00158    */
00159   tsapi TSReturnCode TSPluginRegister(TSSDKVersion sdk_version, TSPluginRegistrationInfo* plugin_info);
00160 
00161   /* --------------------------------------------------------------------------
00162      Files */
00163   /**
00164       Opens a file for reading or writing and returns a descriptor for
00165       accessing the file. The current implementation cannot open a file
00166       for both reading or writing. See the SDK Programmer's Guide for
00167       sample code.
00168 
00169       @param filename file to be opened.
00170       @param mode specifies whether to open the file for reading or
00171         writing. If mode is "r" then the file is opened for reading.
00172         If mode is "w" then the file is opened for writing. Currently
00173         "r" and "w" are the only two valid modes for opening a file.
00174       @return descriptor for the file that TSfopen opens. Descriptors of
00175         type TSFile can be greater than 256.
00176 
00177    */
00178   tsapi TSFile TSfopen(const char* filename, const char* mode);
00179 
00180   /**
00181       Closes the file to which filep points and frees the data structures
00182       and buffers associated with it. If the file was opened for writing,
00183       any pending data is flushed.
00184 
00185       @param filep file to be closed.
00186 
00187    */
00188   tsapi void TSfclose(TSFile filep);
00189 
00190   /**
00191       Attempts to read length bytes of data from the file pointed to by
00192       filep into the buffer buf.
00193 
00194       @param filep name of the file to read from.
00195       @param buf buffer to read into.
00196       @param length amount of data to read, in bytes.
00197       @return number of bytes read. If end of the file, it returns 0.
00198         If the file was not opened for reading or if an error occurs
00199         while reading the file, it returns -1.
00200 
00201    */
00202   tsapi size_t TSfread(TSFile filep, void* buf, size_t length);
00203 
00204   /**
00205       Attempts to write length bytes of data from the buffer buf
00206       to the file filep. Make sure that filep is open for writing.
00207       You might want to check the number of bytes written (TSfwrite()
00208       returns this value) against the value of length. If it is less,
00209       there might be insufficient space on disk, for example.
00210 
00211       @param filep file to write into.
00212       @param buf buffer containing the data to be written.
00213       @param length amount of data to write to filep, in bytes.
00214       @return number of bytes written to filep. If the file was not
00215         opened for writing, it returns -1. If an error occurs while
00216         writing, it returns the number of bytes successfully written.
00217 
00218    */
00219   tsapi size_t TSfwrite(TSFile filep, const void* buf, size_t length);
00220 
00221   /**
00222       Flushes pending data that has been buffered up in memory from
00223       previous calls to TSfwrite().
00224 
00225       @param filep file to flush.
00226 
00227    */
00228   tsapi void TSfflush(TSFile filep);
00229 
00230   /**
00231       Reads a line from the file pointed to by filep into the buffer buf.
00232       Lines are terminated by a line feed character, '\n'. The line
00233       placed in the buffer includes the line feed character and is
00234       terminated with a NULL. If the line is longer than length bytes
00235       then only the first length-minus-1 bytes are placed in buf.
00236 
00237       @param filep file to read from.
00238       @param buf buffer to read into.
00239       @param length size of the buffer to read into.
00240       @return pointer to the string read into the buffer buf.
00241 
00242    */
00243   tsapi char* TSfgets(TSFile filep, char* buf, size_t length);
00244 
00245   /* --------------------------------------------------------------------------
00246      Error logging */
00247   /**
00248       Writes printf-style error messages to the Traffic Server error
00249       log. One advantage of TSError over printf is that each call is
00250       atomically placed into the error log and is not garbled with other
00251       error entries. This is not an issue in single-threaded programs
00252       but is a definite nuisance in multi-threaded programs.
00253 
00254       @param fmt printf format description.
00255       @param ... argument for the printf format description.
00256 
00257   */
00258   tsapi void TSError(const char* fmt, ...) TS_PRINTFLIKE(1, 2);
00259 
00260   /* --------------------------------------------------------------------------
00261      Assertions */
00262   tsapi void _TSReleaseAssert(const char* txt, const char* f, int l) TS_NORETURN;
00263   tsapi int _TSAssert(const char* txt, const char* f, int l);
00264 
00265 #define TSReleaseAssert(EX) \
00266             ( (void)((EX) ? (void)0 : _TSReleaseAssert(#EX, __FILE__, __LINE__)) )
00267 
00268 #define TSAssert(EX) \
00269             (void)((EX) || (_TSAssert(#EX, __FILE__, __LINE__)))
00270 
00271   /* --------------------------------------------------------------------------
00272      Marshal buffers */
00273   /**
00274       Creates a new marshal buffer and initializes the reference count
00275       to 1.
00276 
00277    */
00278   tsapi TSMBuffer TSMBufferCreate(void);
00279 
00280   /**
00281       Ignores the reference count and destroys the marshal buffer bufp.
00282       The internal data buffer associated with the marshal buffer is
00283       also destroyed if the marshal buffer allocated it.
00284 
00285       @param bufp marshal buffer to be destroyed.
00286 
00287    */
00288   tsapi TSReturnCode TSMBufferDestroy(TSMBuffer bufp);
00289 
00290   /* --------------------------------------------------------------------------
00291      URLs */
00292   /**
00293       Creates a new URL within the marshal buffer bufp. Returns a
00294       location for the URL within the marshal buffer.
00295 
00296       @param bufp marshal buffer containing the new URL.
00297       @param locp pointer to a TSMLoc to store the MLoc into.
00298 
00299    */
00300   tsapi TSReturnCode TSUrlCreate(TSMBuffer bufp, TSMLoc* locp);
00301 
00302   /**
00303       Destroys the URL located at url_loc within the marshal buffer
00304       bufp. Do not forget to release the TSMLoc url_loc with a call
00305       to TSHandleMLocRelease().
00306 
00307       @param bufp marshal buffer containing the URL to be destroyed.
00308       @param offset location of the URL to be destroyed.
00309 
00310    */
00311   /** @deprecated There is no reason to destroy the URL, just release
00312       the marshal buffers. Should be removed for v5.0.0 */
00313   tsapi TS_DEPRECATED TSReturnCode TSUrlDestroy(TSMBuffer bufp, TSMLoc offset);
00314 
00315   /**
00316       Copies the URL located at src_url within src_bufp to a URL
00317       location within the marshal buffer dest_bufp, and returns the
00318       TSMLoc location of the copied URL. Unlike TSUrlCopy(), you do
00319       not have to create the destination URL before cloning. Release
00320       the returned TSMLoc handle with a call to TSHandleMLocRelease().
00321 
00322       @param dest_bufp marshal buffer containing the cloned URL.
00323       @param src_bufp marshal buffer containing the URL to be cloned.
00324       @param src_url location of the URL to be cloned, within the marshal
00325         buffer src_bufp.
00326       @param locp pointer to a TSMLoc to store the MLoc into.
00327 
00328    */
00329   tsapi TSReturnCode TSUrlClone(TSMBuffer dest_bufp, TSMBuffer src_bufp, TSMLoc src_url, TSMLoc* locp);
00330 
00331   /**
00332       Copies the contents of the URL at location src_loc within the
00333       marshal buffer src_bufp to the location dest_loc within the marshal
00334       buffer dest_bufp. TSUrlCopy() works correctly even if src_bufp
00335       and dest_bufp point to different marshal buffers. Important: create
00336       the destination URL before copying into it. Use TSUrlCreate().
00337 
00338       @param dest_bufp marshal buffer to contain the copied URL.
00339       @param dest_offset location of the URL to be copied.
00340       @param src_bufp marshal buffer containing the source URL.
00341       @param src_offset location of the source URL within src_bufp.
00342 
00343    */
00344   tsapi TSReturnCode TSUrlCopy(TSMBuffer dest_bufp, TSMLoc dest_offset, TSMBuffer src_bufp, TSMLoc src_offset);
00345 
00346   /**
00347       Formats a URL stored in an TSMBuffer into an TSIOBuffer.
00348 
00349       @param bufp marshal buffer contain the URL to be printed.
00350       @param offset location of the URL within bufp.
00351       @param iobufp destination TSIOBuffer for the URL.
00352 
00353    */
00354   tsapi void TSUrlPrint(TSMBuffer bufp, TSMLoc offset, TSIOBuffer iobufp);
00355 
00356   /**
00357       Parses a URL. The start pointer is both an input and an output
00358       parameter and marks the start of the URL to be parsed. After
00359       a successful parse, the start pointer equals the end pointer.
00360       The end pointer must be one byte after the last character you
00361       want to parse. The URL parsing routine assumes that everything
00362       between start and end is part of the URL. It is up to higher level
00363       parsing routines, such as TSHttpHdrParseReq(), to determine the
00364       actual end of the URL. Returns TS_PARSE_ERROR if an error occurs,
00365       otherwise TS_PARSE_DONE is returned to indicate success.
00366 
00367       @param bufp marshal buffer containing the URL to be parsed.
00368       @param offset location of the URL to be parsed.
00369       @param start points to the start of the URL to be parsed AND at
00370         the end of a successful parse it will equal the end pointer.
00371       @param end must be one byte after the last character.
00372       @return TS_PARSE_ERROR or TS_PARSE_DONE.
00373 
00374    */
00375   tsapi TSParseResult TSUrlParse(TSMBuffer bufp, TSMLoc offset, const char** start, const char* end);
00376 
00377   /**
00378       Calculates the length of the URL located at url_loc within the
00379       marshal buffer bufp if it were returned as a string. This length
00380       is the same as the length returned by TSUrlStringGet().
00381 
00382       @param bufp marshal buffer containing the URL whose length you want.
00383       @param offset location of the URL within the marshal buffer bufp.
00384       @return string length of the URL.
00385 
00386    */
00387   tsapi int TSUrlLengthGet(TSMBuffer bufp, TSMLoc offset);
00388 
00389   /**
00390       Constructs a string representation of the URL located at url_loc
00391       within bufp. TSUrlStringGet() stores the length of the allocated
00392       string in the parameter length. This is the same length that
00393       TSUrlLengthGet() returns. The returned string is allocated by a
00394       call to TSmalloc(). It should be freed by a call to TSfree().
00395       The length parameter must present, providing storage for the URL
00396       string length value.
00397       Note: To get the effective URL from a request, use the alternative
00398             TSHttpTxnEffectiveUrlStringGet API.
00399 
00400       @param bufp marshal buffer containing the URL you want to get.
00401       @param offset location of the URL within bufp.
00402       @param length string length of the URL.
00403       @return The URL as a string.
00404 
00405    */
00406   tsapi char* TSUrlStringGet(TSMBuffer bufp, TSMLoc offset, int* length);
00407 
00408   /**
00409       Retrieves the scheme portion of the URL located at url_loc within
00410       the marshal buffer bufp. TSUrlSchemeGet() places the length of
00411       the string in the length argument. If the length is NULL then no
00412       attempt is made to dereference it.
00413 
00414       @param bufp marshal buffer storing the URL.
00415       @param offset location of the URL within bufp.
00416       @param length length of the returned string.
00417       @return The scheme portion of the URL, as a string.
00418 
00419    */
00420   tsapi const char* TSUrlSchemeGet(TSMBuffer bufp, TSMLoc offset, int *length);
00421 
00422   /**
00423       Sets the scheme portion of the URL located at url_loc within
00424       the marshal buffer bufp to the string value. If length is -1
00425       then TSUrlSchemeSet() assumes that value is null-terminated.
00426       Otherwise, the length of the string value is taken to be length.
00427       TSUrlSchemeSet() copies the string to within bufp, so it is OK
00428       to modify or delete value after calling TSUrlSchemeSet().
00429 
00430       @param bufp marshal buffer containing the URL.
00431       @param offset location of the URL.
00432       @param value value to set the URL's scheme to.
00433       @param length string stored in value.
00434 
00435    */
00436   tsapi TSReturnCode TSUrlSchemeSet(TSMBuffer bufp, TSMLoc offset, const char* value, int length);
00437 
00438   /* --------------------------------------------------------------------------
00439      Internet specific URLs */
00440   /**
00441       Retrieves the user portion of the URL located at url_loc
00442       within bufp. Note: the returned string is not guaranteed to
00443       be null-terminated.
00444 
00445       @param bufp marshal buffer containing the URL.
00446       @param offset location of the URL.
00447       @param length length of the returned string.
00448       @return user portion of the URL.
00449 
00450    */
00451   tsapi const char* TSUrlUserGet(TSMBuffer bufp, TSMLoc offset, int* length);
00452 
00453   /**
00454       Sets the user portion of the URL located at url_loc within bufp
00455       to the string value. If length is -1 then TSUrlUserSet() assumes
00456       that value is null-terminated. Otherwise, the length of the string
00457       value is taken to be length. TSUrlUserSet() copies the string to
00458       within bufp, so it is OK to modify or delete value after calling
00459       TSUrlUserSet().
00460 
00461       @param bufp marshal buffer containing the URL.
00462       @param offset location of the URL whose user is to be set.
00463       @param value holds the new user name.
00464       @param length string length of value.
00465 
00466    */
00467   tsapi TSReturnCode TSUrlUserSet(TSMBuffer bufp, TSMLoc offset, const char* value, int length);
00468 
00469   /**
00470       Retrieves the password portion of the URL located at url_loc
00471       within bufp. TSUrlPasswordGet() places the length of the returned
00472       string in the length argument. Note: the returned string is
00473       not guaranteed to be null-terminated.
00474 
00475       @param bufp marshal buffer containing the URL.
00476       @param offset
00477       @param length of the returned password string.
00478       @return password portion of the URL.
00479 
00480    */
00481   tsapi const char* TSUrlPasswordGet(TSMBuffer bufp, TSMLoc offset, int* length);
00482 
00483   /**
00484       Sets the password portion of the URL located at url_loc within
00485       bufp to the string value. If length is -1 then TSUrlPasswordSet()
00486       assumes that value is null-terminated. Otherwise, the length
00487       of value is taken to be length. TSUrlPasswordSet() copies the
00488       string to within bufp, so it is okay to modify or delete value
00489       after calling TSUrlPasswordSet().
00490 
00491       @param bufp marshal buffer containing the URL.
00492       @param offset
00493       @param value new password.
00494       @param length of the new password.
00495 
00496    */
00497   tsapi TSReturnCode TSUrlPasswordSet(TSMBuffer bufp, TSMLoc offset, const char* value, int length);
00498 
00499   /**
00500       Retrieves the host portion of the URL located at url_loc
00501       within bufp. Note: the returned string is not guaranteed to be
00502       null-terminated.
00503 
00504       @param bufp marshal buffer containing the URL.
00505       @param offset location of the URL.
00506       @param length of the returned string.
00507       @return Host portion of the URL.
00508 
00509    */
00510   tsapi const char* TSUrlHostGet(TSMBuffer bufp, TSMLoc offset, int* length);
00511 
00512   /**
00513       Sets the host portion of the URL at url_loc to the string value.
00514       If length is -1 then TSUrlHostSet() assumes that value is
00515       null-terminated. Otherwise, the length of the string value is
00516       taken to be length. The string is copied to within bufp, so you
00517       can modify or delete value after calling TSUrlHostSet().
00518 
00519       @param bufp marshal buffer containing the URL to modify.
00520       @param offset location of the URL.
00521       @param value new host name for the URL.
00522       @param length string length of the new host name of the URL.
00523 
00524    */
00525   tsapi TSReturnCode TSUrlHostSet(TSMBuffer bufp, TSMLoc offset, const char* value, int length);
00526 
00527   /**
00528       Retrieves the port portion of the URL located at url_loc.
00529 
00530       @param bufp marshal buffer containing the URL.
00531       @param offset location of the URL.
00532       @return port portion of the URL.
00533 
00534    */
00535   tsapi int TSUrlPortGet(TSMBuffer bufp, TSMLoc offset);
00536 
00537   /**
00538       Sets the port portion of the URL located at url_loc.
00539 
00540       @param bufp marshal buffer containing the URL.
00541       @param offset location of the URL.
00542       @param port new port setting for the URL.
00543 
00544    */
00545   tsapi TSReturnCode TSUrlPortSet(TSMBuffer bufp, TSMLoc offset, int port);
00546 
00547   /* --------------------------------------------------------------------------
00548      HTTP specific URLs */
00549   /**
00550       Retrieves the path portion of the URL located at url_loc within
00551       bufp. TSUrlPathGet() places the length of the returned string in
00552       the length argument. Note: the returned string is not guaranteed to
00553       be null-terminated.
00554 
00555       @param bufp marshal buffer containing the URL.
00556       @param offset location of the URL.
00557       @param length of the returned string.
00558       @return path portion of the URL.
00559 
00560    */
00561   tsapi const char* TSUrlPathGet(TSMBuffer bufp, TSMLoc offset, int* length);
00562 
00563   /**
00564       Sets the path portion of the URL located at url_loc within bufp
00565       to the string value. If length is -1 then TSUrlPathSet() assumes
00566       that value is null-terminated. Otherwise, the length of the value
00567       is taken to be length. TSUrlPathSet() copies the string into bufp,
00568       so you can modify or delete value after calling TSUrlPathSet().
00569 
00570       @param bufp marshal buffer containing the URL.
00571       @param offset location of the URL.
00572       @param value new path string for the URL.
00573       @param length of the new path string.
00574 
00575    */
00576   tsapi TSReturnCode TSUrlPathSet(TSMBuffer bufp, TSMLoc offset, const char* value, int length);
00577 
00578   /* --------------------------------------------------------------------------
00579      FTP specific URLs */
00580   /**
00581       Retrieves the FTP type of the URL located at url_loc within bufp.
00582 
00583       @param bufp marshal buffer containing the URL.
00584       @param offset location of the URL.
00585       @return FTP type of the URL.
00586 
00587    */
00588   tsapi int TSUrlFtpTypeGet(TSMBuffer bufp, TSMLoc offset);
00589 
00590   /**
00591       Sets the FTP type portion of the URL located at url_loc within
00592       bufp to the value type.
00593 
00594       @param bufp marshal buffer containing the URL.
00595       @param offset location of the URL to modify.
00596       @param type new FTP type for the URL.
00597 
00598    */
00599   tsapi TSReturnCode TSUrlFtpTypeSet(TSMBuffer bufp, TSMLoc offset, int type);
00600 
00601   /* --------------------------------------------------------------------------
00602      HTTP specific URLs */
00603   /**
00604       Retrieves the HTTP params portion of the URL located at url_loc
00605       within bufp. The length of the returned string is in the length
00606       argument. Note: the returned string is not guaranteed to be
00607       null-terminated.
00608 
00609       @param bufp marshal buffer containing the URL.
00610       @param offset location of the URL.
00611       @param length of the returned string.
00612       @return HTTP params portion of the URL.
00613 
00614    */
00615   tsapi const char* TSUrlHttpParamsGet(TSMBuffer bufp, TSMLoc offset, int* length);
00616 
00617   /**
00618       Sets the HTTP params portion of the URL located at url_loc within
00619       bufp to the string value. If length is -1 that TSUrlHttpParamsSet()
00620       assumes that value is null-terminated. Otherwise, the length of
00621       the string value is taken to be length. TSUrlHttpParamsSet()
00622       copies the string to within bufp, so you can modify or delete
00623       value after calling TSUrlHttpParamsSet().
00624 
00625       @param bufp marshal buffer containing the URL.
00626       @param offset location of the URL.
00627       @param value HTTP params string to set in the URL.
00628       @param length string length of the new HTTP params value.
00629 
00630    */
00631   tsapi TSReturnCode TSUrlHttpParamsSet(TSMBuffer bufp, TSMLoc offset, const char* value, int length);
00632 
00633   /**
00634       Retrieves the HTTP query portion of the URL located at url_loc
00635       within bufp. The length of the returned string is in the length
00636       argument. Note: the returned string is not guaranteed to be
00637       null-terminated.
00638 
00639       @param bufp marshal buffer containing the URL.
00640       @param offset location of the URL.
00641       @param length of the returned string.
00642       @return HTTP query portion of the URL.
00643 
00644    */
00645   tsapi const char* TSUrlHttpQueryGet(TSMBuffer bufp, TSMLoc offset, int* length);
00646 
00647   /**
00648       Sets the HTTP query portion of the URL located at url_loc within
00649       bufp to value. If length is -1, the string value is assumed to
00650       be null-terminated; otherwise, the length of value is taken to be
00651       length. TSUrlHttpQuerySet() copies the string to within bufp, so
00652       you can modify or delete value after calling TSUrlHttpQuerySet().
00653 
00654       @param bufp marshal buffer containing the URL.
00655       @param offset location of the URL within bufp.
00656       @param value new HTTP query string for the URL.
00657       @param length of the new HTTP query string.
00658 
00659    */
00660   tsapi TSReturnCode TSUrlHttpQuerySet(TSMBuffer bufp, TSMLoc offset, const char* value, int length);
00661 
00662   /**
00663       Retrieves the HTTP fragment portion of the URL located at url_loc
00664       within bufp. The length of the returned string is in the length
00665       argument. Note: the returned string is not guaranteed to be
00666       null-terminated.
00667 
00668       @param bufp marshal buffer containing the URL.
00669       @param offset location of the URL.
00670       @param length of the returned string.
00671       @return HTTP fragment portion of the URL.
00672 
00673    */
00674   tsapi const char* TSUrlHttpFragmentGet(TSMBuffer bufp, TSMLoc offset, int* length);
00675 
00676   /**
00677       Sets the HTTP fragment portion of the URL located at url_loc
00678       within bufp to value. If length is -1, the string value is
00679       assumed to be null-terminated; otherwise, the length of value
00680       is taken to be length. TSUrlHttpFragmentSet() copies the string
00681       to within bufp, so you can modify or delete value after calling
00682       TSUrlHttpFragmentSet().
00683 
00684       @param bufp marshal buffer containing the URL.
00685       @param offset location of the URL within bufp.
00686       @param value new HTTP fragment string for the URL.
00687       @param length of the new HTTP query string.
00688 
00689    */
00690   tsapi TSReturnCode TSUrlHttpFragmentSet(TSMBuffer bufp, TSMLoc offset, const char* value, int length);
00691 
00692   /**
00693      Perform percent-encoding of the string in the buffer, storing the
00694      new string in the destination buffer. The length parameter will be
00695      set to the new (encoded) string length, or 0 if the encoding failed.
00696 
00697      @param str the string buffer to encode.
00698      @param str_len length of the string buffer.
00699      @param dst destination buffer.
00700      @param dst_size size of the destination buffer.
00701      @param length amount of data written to the destination buffer.
00702      @param map optional (can be NULL) map of characters to encode.
00703 
00704   */
00705   tsapi TSReturnCode TSStringPercentEncode(const char *str, int str_len, char *dst, size_t dst_size, size_t *length, const unsigned char *map);
00706 
00707   /**
00708      Similar to TSStringPercentEncode(), but works on a URL object.
00709 
00710      @param bufp marshal buffer containing the URL.
00711      @param offset location of the URL within bufp.
00712      @param dst destination buffer.
00713      @param dst_size size of the destination buffer.
00714      @param length amount of data written to the destination buffer.
00715      @param map optional (can be NULL) map of characters to encode.
00716 
00717   */
00718   tsapi TSReturnCode TSUrlPercentEncode(TSMBuffer bufp, TSMLoc offset, char *dst, size_t dst_size, size_t *length, const unsigned char *map);
00719 
00720   /**
00721      Perform percent-decoding of the string in the buffer, writing
00722      to the output buffer. The source and destination can be the same,
00723      in which case they overwrite. The decoded string is always
00724      guaranteed to be no longer than the source string.
00725 
00726      @param str the string to decode (and possibly write to).
00727      @param str_len length of the input string (or 0).
00728      @param dst output buffer (can be the same as src).
00729      @param dst_len size of the output buffer.
00730      @param length amount of data written to the destination buffer.
00731 
00732   */
00733   tsapi TSReturnCode TSStringPercentDecode(const char *str, size_t str_len, char *dst, size_t dst_size, size_t *length);
00734 
00735 
00736 
00737   /* --------------------------------------------------------------------------
00738      MIME headers */
00739 
00740   /**
00741       Creates a MIME parser. The parser's data structure contains
00742       information about the header being parsed. A single MIME
00743       parser can be used multiple times, though not simultaneously.
00744       Before being used again, the parser must be cleared by calling
00745       TSMimeParserClear().
00746 
00747    */
00748   tsapi TSMimeParser TSMimeParserCreate(void);
00749 
00750   /**
00751       Clears the specified MIME parser so that it can be used again.
00752 
00753       @param parser to be cleared.
00754 
00755    */
00756   tsapi void TSMimeParserClear(TSMimeParser parser);
00757 
00758   /**
00759       Destroys the specified MIME parser and frees the associated memory.
00760 
00761       @param parser to destroy.
00762    */
00763   tsapi void TSMimeParserDestroy(TSMimeParser parser);
00764 
00765   /**
00766       Creates a new MIME header within bufp. Release with a call to
00767       TSHandleMLocRelease().
00768 
00769       @param bufp marshal buffer to contain the new MIME header.
00770       @param locp buffer pointer to contain the MLoc
00771 
00772    */
00773   tsapi TSReturnCode TSMimeHdrCreate(TSMBuffer bufp, TSMLoc* locp);
00774 
00775   /**
00776       Destroys the MIME header located at hdr_loc within bufp.
00777 
00778       @param bufp marshal buffer containing the MIME header to destroy.
00779       @param offset location of the MIME header.
00780 
00781    */
00782   tsapi TSReturnCode TSMimeHdrDestroy(TSMBuffer bufp, TSMLoc offset);
00783 
00784   /**
00785       Copies a specified MIME header to a specified marshal buffer,
00786       and returns the location of the copied MIME header within the
00787       destination marshal buffer. Unlike TSMimeHdrCopy(), you do not
00788       have to create the destination MIME header before cloning. Release
00789       the returned TSMLoc handle with a call to TSHandleMLocRelease().
00790 
00791       @param dest_bufp destination marshal buffer.
00792       @param src_bufp source marshal buffer.
00793       @param src_hdr location of the source MIME header.
00794       @param locp where to store the location of the copied MIME header.
00795 
00796    */
00797   tsapi TSReturnCode TSMimeHdrClone(TSMBuffer dest_bufp, TSMBuffer src_bufp, TSMLoc src_hdr, TSMLoc* locp);
00798 
00799   /**
00800       Copies the contents of the MIME header located at src_loc
00801       within src_bufp to the MIME header located at dest_loc within
00802       dest_bufp. TSMimeHdrCopy() works correctly even if src_bufp and
00803       dest_bufp point to different marshal buffers. Important: you must
00804       create the destination MIME header before copying into it--use
00805       TSMimeHdrCreate().
00806 
00807       @param dest_bufp is the destination marshal buffer.
00808       @param dest_offset
00809       @param src_bufp is the source marshal buffer.
00810       @param src_offset
00811 
00812    */
00813   tsapi TSReturnCode TSMimeHdrCopy(TSMBuffer dest_bufp, TSMLoc dest_offset, TSMBuffer src_bufp,
00814                                       TSMLoc src_offset);
00815 
00816   /**
00817       Formats the MIME header located at hdr_loc within bufp into the
00818       TSIOBuffer iobufp.
00819 
00820       @param bufp marshal buffer containing the header to be copied to
00821         an TSIOBuffer.
00822       @param offset
00823       @param iobufp target TSIOBuffer.
00824 
00825    */
00826   tsapi void TSMimeHdrPrint(TSMBuffer bufp, TSMLoc offset, TSIOBuffer iobufp);
00827 
00828   /**
00829       Parses a MIME header. The MIME header must have already been
00830       allocated and both bufp and hdr_loc must point within that header.
00831       It is possible to parse a MIME header a single byte at a time
00832       using repeated calls to TSMimeHdrParse(). As long as an error
00833       does not occur, TSMimeHdrParse() consumes each single byte and
00834       asks for more.
00835 
00836       @param parser parses the specified MIME header.
00837       @param bufp marshal buffer containing the MIME header to be parsed.
00838       @param offset
00839       @param start both an input and output. On input, the start
00840         argument points to the current position of the buffer being
00841         parsed. On return, start is modified to point past the last
00842         character parsed.
00843       @param end points to one byte after the end of the buffer.
00844       @return One of 3 possible int values:
00845         - TS_PARSE_ERROR if there is a parsing error.
00846         - TS_PARSE_DONE is returned when a "\r\n\r\n" pattern is
00847           encountered, indicating the end of the header.
00848         - TS_PARSE_CONT is returned if parsing of the header stopped
00849           because the end of the buffer was reached.
00850 
00851    */
00852   tsapi TSParseResult TSMimeHdrParse(TSMimeParser parser, TSMBuffer bufp, TSMLoc offset, const char** start,
00853                                      const char* end);
00854 
00855   /**
00856       Calculates the length of the MIME header located at hdr_loc if it
00857       were returned as a string. This the length of the MIME header in
00858       its unparsed form.
00859 
00860       @param bufp marshal buffer containing the MIME header.
00861       @param offset location of the MIME header.
00862       @return string length of the MIME header located at hdr_loc.
00863 
00864    */
00865   tsapi int TSMimeHdrLengthGet(TSMBuffer bufp, TSMLoc offset);
00866 
00867   /**
00868       Removes and destroys all the MIME fields within the MIME header
00869       located at hdr_loc within the marshal buffer bufp.
00870 
00871       @param bufp marshal buffer containing the MIME header.
00872       @param offset location of the MIME header.
00873 
00874    */
00875   tsapi TSReturnCode TSMimeHdrFieldsClear(TSMBuffer bufp, TSMLoc offset);
00876 
00877   /**
00878       Returns a count of the number of MIME fields within the MIME header
00879       located at hdr_loc within the marshal buffer bufp.
00880 
00881       @param bufp marshal buffer containing the MIME header.
00882       @param offset location of the MIME header within bufp.
00883       @return number of MIME fields within the MIME header located
00884         at hdr_loc.
00885 
00886    */
00887   tsapi int TSMimeHdrFieldsCount(TSMBuffer bufp, TSMLoc offset);
00888 
00889   /**
00890       Retrieves the location of a specified MIME field within the
00891       MIME header located at hdr_loc within bufp. The idx parameter
00892       specifies which field to retrieve. The fields are numbered from 0
00893       to TSMimeHdrFieldsCount(bufp, hdr_loc) - 1. If idx does not lie
00894       within that range then TSMimeHdrFieldGet returns 0. Release the
00895       returned handle with a call to TSHandleMLocRelease.
00896 
00897       @param bufp marshal buffer containing the MIME header.
00898       @param hdr location of the MIME header.
00899       @param idx index of the field to get with base at 0.
00900       @return location of the specified MIME field.
00901 
00902    */
00903   tsapi TSMLoc TSMimeHdrFieldGet(TSMBuffer bufp, TSMLoc hdr, int idx);
00904 
00905   /**
00906       Retrieves the TSMLoc location of a specified MIME field from within
00907       the MIME header located at hdr. The name and length parameters
00908       specify which field to retrieve. For each MIME field in the MIME
00909       header, a case insensitive string comparison is done between
00910       the field name and name. If TSMimeHdrFieldFind() cannot find the
00911       requested field, it returns TS_NULL_MLOC. Release the returned
00912       TSMLoc handle with a call to TSHandleMLocRelease().
00913 
00914       @param bufp marshal buffer containing the MIME header field to find.
00915       @param hdr location of the MIME header containing the field.
00916       @param name of the field to retrieve.
00917       @param length string length of the string name. If length is -1,
00918         then name is assumed to be null-terminated.
00919       @return location of the requested MIME field. If the field could
00920         not be found, returns TS_NULL_MLOC.
00921 
00922    */
00923   tsapi TSMLoc TSMimeHdrFieldFind(TSMBuffer bufp, TSMLoc hdr, const char* name, int length);
00924 
00925   /**
00926       Returns the TSMLoc location of a specified MIME field from within
00927       the MIME header located at hdr. The retrieved_str parameter
00928       specifies which field to retrieve. For each MIME field in the
00929       MIME header, a pointer comparison is done between the field name
00930       and retrieved_str. This is a much quicker retrieval function
00931       than TSMimeHdrFieldFind() since it obviates the need for a
00932       string comparison. However, retrieved_str must be one of the
00933       predefined field names of the form TS_MIME_FIELD_XXX for the
00934       call to succeed. Release the returned TSMLoc handle with a call
00935       to TSHandleMLocRelease().
00936 
00937       @param bufp marshal buffer containing the MIME field.
00938       @param hdr location of the MIME header containing the field.
00939       @param retrieved_str specifies the field to retrieve. Must be
00940         one of the predefined field names of the form TS_MIME_FIELD_XXX.
00941       @return location of the requested MIME field. If the requested
00942         field cannot be found, returns 0.
00943 
00944    */
00945   tsapi TSReturnCode TSMimeHdrFieldAppend(TSMBuffer bufp, TSMLoc hdr, TSMLoc field);
00946 
00947   /**
00948       Removes the MIME field located at field within bufp from the
00949       header located at hdr within bufp. If the specified field cannot
00950       be found in the list of fields associated with the header then
00951       nothing is done.
00952 
00953       Note: removing the field does not destroy the field, it only
00954       detaches the field, hiding it from the printed output. The field
00955       can be reattached with a call to TSMimeHdrFieldAppend(). If you
00956       do not use the detached field you should destroy it with a call to
00957       TSMimeHdrFieldDestroy() and release the handle field with a call
00958       to TSHandleMLocRelease().
00959 
00960       @param bufp contains the MIME field to remove.
00961       @param hdr location of the header containing the MIME field to
00962         be removed. This header could be an HTTP header or MIME header.
00963       @param field is the location of the field to remove.
00964 
00965    */
00966   tsapi TSReturnCode TSMimeHdrFieldRemove(TSMBuffer bufp, TSMLoc hdr, TSMLoc field);
00967 
00968   tsapi TSReturnCode TSMimeHdrFieldCreate(TSMBuffer bufp, TSMLoc hdr, TSMLoc* locp);
00969 
00970   /****************************************************************************
00971    *  Create a new field and assign it a name all in one call
00972    ****************************************************************************/
00973   tsapi TSReturnCode TSMimeHdrFieldCreateNamed(TSMBuffer bufp, TSMLoc mh_mloc, const char* name, int name_len, TSMLoc* locp);
00974 
00975   /**
00976       Destroys the MIME field located at field within bufp. You must
00977       release the TSMLoc field with a call to TSHandleMLocRelease().
00978 
00979       @param bufp contains the MIME field to be destroyed.
00980       @param hdr location of the parent header containing the field
00981         to be destroyed. This could be the location of a MIME header or
00982         HTTP header.
00983       @param field location of the field to be destroyed.
00984 
00985    */
00986   tsapi TSReturnCode TSMimeHdrFieldDestroy(TSMBuffer bufp, TSMLoc hdr, TSMLoc field);
00987 
00988   tsapi TSReturnCode TSMimeHdrFieldClone(TSMBuffer dest_bufp, TSMLoc dest_hdr, TSMBuffer src_bufp, TSMLoc src_hdr,
00989                                          TSMLoc src_field, TSMLoc* locp);
00990   tsapi TSReturnCode TSMimeHdrFieldCopy(TSMBuffer dest_bufp, TSMLoc dest_hdr, TSMLoc dest_field,
00991                                         TSMBuffer src_bufp, TSMLoc src_hdr, TSMLoc src_field);
00992   tsapi TSReturnCode TSMimeHdrFieldCopyValues(TSMBuffer dest_bufp, TSMLoc dest_hdr, TSMLoc dest_field,
00993                                               TSMBuffer src_bufp, TSMLoc src_hdr, TSMLoc src_field);
00994   tsapi TSMLoc TSMimeHdrFieldNext(TSMBuffer bufp, TSMLoc hdr, TSMLoc field);
00995   tsapi TSMLoc TSMimeHdrFieldNextDup(TSMBuffer bufp, TSMLoc hdr, TSMLoc field);
00996   tsapi int TSMimeHdrFieldLengthGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field);
00997   tsapi const char* TSMimeHdrFieldNameGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int* length);
00998   tsapi TSReturnCode TSMimeHdrFieldNameSet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, const char* name, int length);
00999 
01000   tsapi TSReturnCode TSMimeHdrFieldValuesClear(TSMBuffer bufp, TSMLoc hdr, TSMLoc field);
01001   tsapi int TSMimeHdrFieldValuesCount(TSMBuffer bufp, TSMLoc hdr, TSMLoc field);
01002 
01003   tsapi const char* TSMimeHdrFieldValueStringGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, int* value_len_ptr);
01004   tsapi int TSMimeHdrFieldValueIntGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx);
01005   tsapi int64_t TSMimeHdrFieldValueInt64Get(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx);
01006   tsapi unsigned int TSMimeHdrFieldValueUintGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx);
01007   tsapi time_t TSMimeHdrFieldValueDateGet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field);
01008   tsapi TSReturnCode TSMimeHdrFieldValueStringSet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx,
01009                                                      const char* value, int length);
01010   tsapi TSReturnCode TSMimeHdrFieldValueIntSet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, int value);
01011   tsapi TSReturnCode TSMimeHdrFieldValueInt64Set(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, int64_t value);
01012   tsapi TSReturnCode TSMimeHdrFieldValueUintSet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx,
01013                                                    unsigned int value);
01014   tsapi TSReturnCode TSMimeHdrFieldValueDateSet(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, time_t value);
01015 
01016   tsapi TSReturnCode TSMimeHdrFieldValueAppend(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx,
01017                                                   const char* value, int length);
01018   /* These Insert() APIs should be considered. Use the corresponding Set() API instead */
01019   tsapi TSReturnCode TSMimeHdrFieldValueStringInsert(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx,
01020                                                         const char* value, int length);
01021   tsapi TSReturnCode TSMimeHdrFieldValueIntInsert(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx, int value);
01022   tsapi TSReturnCode TSMimeHdrFieldValueUintInsert(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx,
01023                                                       unsigned int value);
01024   tsapi TSReturnCode TSMimeHdrFieldValueDateInsert(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, time_t value);
01025 
01026   tsapi TSReturnCode TSMimeHdrFieldValueDelete(TSMBuffer bufp, TSMLoc hdr, TSMLoc field, int idx);
01027 
01028   /* --------------------------------------------------------------------------
01029      HTTP headers */
01030   tsapi TSHttpParser TSHttpParserCreate(void);
01031   tsapi void TSHttpParserClear(TSHttpParser parser);
01032   tsapi void TSHttpParserDestroy(TSHttpParser parser);
01033 
01034   /**
01035       Parses an HTTP request header. The HTTP header must have already
01036       been created, and must reside inside the marshal buffer bufp.
01037       The start argument points to the current position of the string
01038       buffer being parsed. The end argument points to one byte after the
01039       end of the buffer to be parsed. On return, TSHttpHdrParseReq()
01040       modifies start to point past the last character parsed.
01041 
01042       It is possible to parse an HTTP request header a single byte at
01043       a time using repeated calls to TSHttpHdrParseReq(). As long as
01044       an error does not occur, the TSHttpHdrParseReq() function will
01045       consume that single byte and ask for more.
01046 
01047       @param parser parses the HTTP header.
01048       @param bufp marshal buffer containing the HTTP header to be parsed.
01049       @param offset location of the HTTP header within bufp.
01050       @param start both an input and output. On input, it points to the
01051         current position of the string buffer being parsed. On return,
01052         start is modified to point past the last character parsed.
01053       @param end points to one byte after the end of the buffer to be parsed.
01054       @return status of the parse:
01055         - TS_PARSE_ERROR means there was a parsing error.
01056         - TS_PARSE_DONE means that the end of the header was reached
01057           (the parser encountered a "\r\n\r\n" pattern).
01058         - TS_PARSE_CONT means that parsing of the header stopped because
01059           the parser reached the end of the buffer (large headers can
01060           span multiple buffers).
01061 
01062    */
01063   tsapi TSParseResult TSHttpHdrParseReq(TSHttpParser parser, TSMBuffer bufp, TSMLoc offset, const char** start, const char* end);
01064 
01065   tsapi TSParseResult TSHttpHdrParseResp(TSHttpParser parser, TSMBuffer bufp, TSMLoc offset, const char** start, const char* end);
01066 
01067   tsapi TSMLoc TSHttpHdrCreate(TSMBuffer bufp);
01068 
01069   /**
01070       Destroys the HTTP header located at hdr_loc within the marshal
01071       buffer bufp. Do not forget to release the handle hdr_loc with a
01072       call to TSHandleMLocRelease().
01073 
01074    */
01075   tsapi void TSHttpHdrDestroy(TSMBuffer bufp, TSMLoc offset);
01076 
01077   tsapi TSReturnCode TSHttpHdrClone(TSMBuffer dest_bufp, TSMBuffer src_bufp, TSMLoc src_hdr, TSMLoc* locp);
01078 
01079   /**
01080       Copies the contents of the HTTP header located at src_loc within
01081       src_bufp to the HTTP header located at dest_loc within dest_bufp.
01082       TSHttpHdrCopy() works correctly even if src_bufp and dest_bufp
01083       point to different marshal buffers. Make sure that you create the
01084       destination HTTP header before copying into it.
01085 
01086       Note: TSHttpHdrCopy() appends the port number to the domain
01087       of the URL portion of the header. For example, a copy of
01088       http://www.example.com appears as http://www.example.com:80 in
01089       the destination buffer.
01090 
01091       @param dest_bufp marshal buffer to contain the copied header.
01092       @param dest_offset location of the copied header.
01093       @param src_bufp marshal buffer containing the source header.
01094       @param src_offset location of the source header.
01095 
01096    */
01097   tsapi TSReturnCode TSHttpHdrCopy(TSMBuffer dest_bufp, TSMLoc dest_offset, TSMBuffer src_bufp,
01098                                    TSMLoc src_offset);
01099 
01100   tsapi void TSHttpHdrPrint(TSMBuffer bufp, TSMLoc offset, TSIOBuffer iobufp);
01101 
01102   tsapi int TSHttpHdrLengthGet(TSMBuffer bufp, TSMLoc offset);
01103 
01104   tsapi TSHttpType TSHttpHdrTypeGet(TSMBuffer bufp, TSMLoc offset);
01105   tsapi TSReturnCode TSHttpHdrTypeSet(TSMBuffer bufp, TSMLoc offset, TSHttpType type);
01106 
01107   tsapi int TSHttpHdrVersionGet(TSMBuffer bufp, TSMLoc offset);
01108   tsapi TSReturnCode TSHttpHdrVersionSet(TSMBuffer bufp, TSMLoc offset, int ver);
01109 
01110   tsapi const char* TSHttpHdrMethodGet(TSMBuffer bufp, TSMLoc offset, int* length);
01111   tsapi TSReturnCode TSHttpHdrMethodSet(TSMBuffer bufp, TSMLoc offset, const char* value, int length);
01112   tsapi TSReturnCode TSHttpHdrUrlGet(TSMBuffer bufp, TSMLoc offset, TSMLoc* locp);
01113   tsapi TSReturnCode TSHttpHdrUrlSet(TSMBuffer bufp, TSMLoc offset, TSMLoc url);
01114 
01115   tsapi TSHttpStatus TSHttpHdrStatusGet(TSMBuffer bufp, TSMLoc offset);
01116   tsapi TSReturnCode TSHttpHdrStatusSet(TSMBuffer bufp, TSMLoc offset, TSHttpStatus status);
01117   tsapi const char* TSHttpHdrReasonGet(TSMBuffer bufp, TSMLoc offset, int* length);
01118   tsapi TSReturnCode TSHttpHdrReasonSet(TSMBuffer bufp, TSMLoc offset, const char* value, int length);
01119   tsapi const char* TSHttpHdrReasonLookup(TSHttpStatus status);
01120 
01121   /* --------------------------------------------------------------------------
01122      Threads */
01123   tsapi TSThread TSThreadCreate(TSThreadFunc func, void* data);
01124   tsapi TSThread TSThreadInit(void);
01125   tsapi void TSThreadDestroy(TSThread thread);
01126   tsapi TSThread TSThreadSelf(void);
01127 
01128   /* --------------------------------------------------------------------------
01129      Mutexes */
01130   tsapi TSMutex TSMutexCreate(void);
01131   tsapi void TSMutexLock(TSMutex mutexp);
01132   tsapi TSReturnCode TSMutexLockTry(TSMutex mutexp);
01133 
01134   tsapi void TSMutexUnlock(TSMutex mutexp);
01135 
01136   /* --------------------------------------------------------------------------
01137      cachekey */
01138   /**
01139       Creates (allocates memory for) a new cache key.
01140    */
01141   tsapi TSCacheKey TSCacheKeyCreate(void);
01142 
01143   /**
01144       Generates a key for an object to be cached (written to the cache).
01145 
01146       @param key to be associated with the cached object. Before
01147         calling TSCacheKeySetDigest() you must create the key with
01148         TSCacheKeyCreate().
01149       @param input string that uniquely identifies the object. In most
01150         cases, it is the URL of the object.
01151       @param length of the string input.
01152 
01153    */
01154   tsapi TSReturnCode TSCacheKeyDigestSet(TSCacheKey key, const char* input, int length);
01155 
01156   tsapi TSReturnCode TSCacheKeyDigestFromUrlSet(TSCacheKey key, TSMLoc url);
01157 
01158   /**
01159       Associates a host name to the cache key. Use this function if the
01160       cache has been partitioned by hostname. The hostname tells the
01161       cache which volume to use for the object.
01162 
01163       @param key of the cached object.
01164       @param hostname to associate with the cache key.
01165       @param host_len length of the string hostname.
01166 
01167    */
01168   tsapi TSReturnCode TSCacheKeyHostNameSet(TSCacheKey key, const char* hostname, int host_len);
01169 
01170   tsapi TSReturnCode TSCacheKeyPinnedSet(TSCacheKey key, time_t pin_in_cache);
01171 
01172   /**
01173       Destroys a cache key. You must destroy cache keys when you are
01174       finished with them, i.e. after all reads and writes are completed.
01175 
01176       @param key to be destroyed.
01177 
01178    */
01179   tsapi TSReturnCode TSCacheKeyDestroy(TSCacheKey key);
01180 
01181   /* --------------------------------------------------------------------------
01182      cache url */
01183   tsapi TSReturnCode TSCacheUrlSet(TSHttpTxn txnp, const char* url, int length);
01184 
01185   /* --------------------------------------------------------------------------
01186      Configuration */
01187   tsapi unsigned int TSConfigSet(unsigned int id, void* data, TSConfigDestroyFunc funcp);
01188   tsapi TSConfig TSConfigGet(unsigned int id);
01189   tsapi void TSConfigRelease(unsigned int id, TSConfig configp);
01190   tsapi void* TSConfigDataGet(TSConfig configp);
01191 
01192   /* --------------------------------------------------------------------------
01193      Management */
01194   tsapi void TSMgmtUpdateRegister(TSCont contp, const char *plugin_name);
01195   tsapi TSReturnCode TSMgmtIntGet(const char* var_name, TSMgmtInt* result);
01196   tsapi TSReturnCode TSMgmtCounterGet(const char* var_name, TSMgmtCounter* result);
01197   tsapi TSReturnCode TSMgmtFloatGet(const char* var_name, TSMgmtFloat* result);
01198   tsapi TSReturnCode TSMgmtStringGet(const char* var_name, TSMgmtString* result);
01199 
01200   /* --------------------------------------------------------------------------
01201      Continuations */
01202   tsapi TSCont TSContCreate(TSEventFunc funcp, TSMutex mutexp);
01203   tsapi void TSContDestroy(TSCont contp);
01204   tsapi void TSContDataSet(TSCont contp, void* data);
01205   tsapi void* TSContDataGet(TSCont contp);
01206   tsapi TSAction TSContSchedule(TSCont contp, TSHRTime timeout, TSThreadPool tp);
01207   tsapi TSAction TSContScheduleEvery(TSCont contp, TSHRTime every /* millisecs */, TSThreadPool tp);
01208   tsapi TSAction TSHttpSchedule(TSCont contp, TSHttpTxn txnp, TSHRTime timeout);
01209   tsapi int TSContCall(TSCont contp, TSEvent event, void* edata);
01210   tsapi TSMutex TSContMutexGet(TSCont contp);
01211 
01212   /* --------------------------------------------------------------------------
01213      Plugin lifecycle  hooks */
01214   tsapi void TSLifecycleHookAdd(TSLifecycleHookID id, TSCont contp);
01215   /* --------------------------------------------------------------------------
01216      HTTP hooks */
01217   tsapi void TSHttpHookAdd(TSHttpHookID id, TSCont contp);
01218 
01219   /* --------------------------------------------------------------------------
01220      HTTP sessions */
01221   tsapi void TSHttpSsnHookAdd(TSHttpSsn ssnp, TSHttpHookID id, TSCont contp);
01222   tsapi void TSHttpSsnReenable(TSHttpSsn ssnp, TSEvent event);
01223   tsapi int TSHttpSsnTransactionCount(TSHttpSsn ssnp);
01224 
01225   /* --------------------------------------------------------------------------
01226      HTTP transactions */
01227   tsapi void TSHttpTxnHookAdd(TSHttpTxn txnp, TSHttpHookID id, TSCont contp);
01228   tsapi TSHttpSsn TSHttpTxnSsnGet(TSHttpTxn txnp);
01229 
01230   /* Gets the client request header for a specified HTTP transaction. */
01231   tsapi TSReturnCode TSHttpTxnClientReqGet(TSHttpTxn txnp, TSMBuffer* bufp, TSMLoc* offset);
01232   /* Gets the client response header for a specified HTTP transaction. */
01233   tsapi TSReturnCode TSHttpTxnClientRespGet(TSHttpTxn txnp, TSMBuffer* bufp, TSMLoc* offset);
01234   /* Gets the server request header from a specified HTTP transaction. */
01235   tsapi TSReturnCode TSHttpTxnServerReqGet(TSHttpTxn txnp, TSMBuffer* bufp, TSMLoc* offset);
01236   /* Gets the server response header from a specified HTTP transaction. */
01237   tsapi TSReturnCode TSHttpTxnServerRespGet(TSHttpTxn txnp, TSMBuffer* bufp, TSMLoc* offset);
01238   /* Gets the cached request header for a specified HTTP transaction. */
01239   tsapi TSReturnCode TSHttpTxnCachedReqGet(TSHttpTxn txnp, TSMBuffer* bufp, TSMLoc* offset);
01240   /* Gets the cached response header for a specified HTTP transaction. */
01241   tsapi TSReturnCode TSHttpTxnCachedRespGet(TSHttpTxn txnp, TSMBuffer* bufp, TSMLoc* offset);
01242 
01243   tsapi TSReturnCode TSHttpTxnPristineUrlGet(TSHttpTxn txnp, TSMBuffer* bufp, TSMLoc* url_loc);
01244 
01245   /** Get the effective URL for the transaction.
01246       The effective URL is the URL taking in to account both the explicit
01247       URL in the request and the HOST field.
01248 
01249       A possibly non-null terminated string is returned.
01250 
01251       @note The returned string is allocated and must be freed by the caller
01252       after use with @c TSfree.
01253   */
01254   tsapi char* TSHttpTxnEffectiveUrlStringGet(TSHttpTxn txnp,
01255                                              int* length /**< String length return, may be @c NULL. */
01256                                              );
01257 
01258   tsapi void TSHttpTxnRespCacheableSet(TSHttpTxn txnp, int flag);
01259   tsapi void TSHttpTxnReqCacheableSet(TSHttpTxn txnp, int flag);
01260 
01261   /** Set flag indicating whether or not to cache the server response for
01262       given TSHttpTxn
01263 
01264       @note This should be done in the HTTP_READ_RESPONSE_HDR_HOOK or earlier.
01265 
01266       @note If TSHttpTxnRespCacheableSet() is not working the way you expect,
01267       this may be the function you should use instead.
01268 
01269       @param txnp The transaction whose server response you do not want to store.
01270       @param flag Set 0 to allow storing and 1 to disable storing.
01271 
01272       @return TS_SUCCESS.
01273   */
01274   tsapi TSReturnCode TSHttpTxnServerRespNoStoreSet(TSHttpTxn txnp, int flag);
01275 
01276   tsapi TSReturnCode TSFetchPageRespGet (TSHttpTxn txnp, TSMBuffer* bufp, TSMLoc* offset);
01277   tsapi char* TSFetchRespGet(TSHttpTxn txnp, int* length);
01278   tsapi TSReturnCode TSHttpTxnCacheLookupStatusGet(TSHttpTxn txnp, int* lookup_status);
01279 
01280   tsapi TSReturnCode TSHttpTxnTransformRespGet(TSHttpTxn txnp, TSMBuffer* bufp, TSMLoc* offset);
01281 
01282   tsapi void TSHttpTxnClientIncomingPortSet(TSHttpTxn txnp, int port);
01283 
01284   /** Get SSL object of this session.
01285       Retrieves the SSL object of the SSL connection.
01286 
01287       @return SSL object of this session
01288    */
01289   tsapi void* TSHttpSsnSSLConnectionGet(TSHttpSsn ssnp); //returns SSL *
01290 
01291   /** Get client address for transaction @a txnp.
01292       Retrieves the socket address of the remote client that has
01293       connected to Traffic Server for transaction @a txnp. The
01294       return structure is the generic socket address storage in
01295       order to be address-family agnostic. The user of this function
01296       can then go on to do the appropriate thing with the type
01297       specified in the ss_family field of the structure whether
01298       that be for IPv4, IPv6, or any other address family.
01299 
01300       @return Client address for connection to client in transaction @a txnp.
01301 
01302    */
01303   tsapi struct sockaddr const* TSHttpTxnClientAddrGet(TSHttpTxn txnp);
01304   /** Get the incoming address.
01305 
01306       @note The pointer is valid only for the current callback. Clients
01307       that need to keep the value across callbacks must maintain their
01308       own storage.
01309 
01310       @return Local address of the client connection for transaction @a txnp.
01311   */
01312   tsapi struct sockaddr const* TSHttpTxnIncomingAddrGet(TSHttpTxn txnp);
01313   /** Get the origin server address.
01314    *
01315       @note The pointer is valid only for the current callback. Clients
01316       that need to keep the value across callbacks must maintain their
01317       own storage.
01318 
01319       @return The address of the origin server for transaction @a txnp.
01320   */
01321   tsapi struct sockaddr const* TSHttpTxnServerAddrGet(TSHttpTxn txnp);
01322   /** Set the origin server address.
01323 
01324       This must be invoked before the origin server address is looked up.
01325       If called no lookup is done, the address @a addr is used instead.
01326 
01327       @return @c TS_SUCCESS if the origin server address is set, @c TS_ERROR otherwise.
01328   */
01329   tsapi TSReturnCode TSHttpTxnServerAddrSet(TSHttpTxn txnp,
01330                                             struct sockaddr const* addr /**< Address for origin server. */
01331                                             );
01332 
01333   /** Get the next hop address.
01334    *
01335       @note The pointer is valid only for the current callback. Clients
01336       that need to keep the value across callbacks must maintain their
01337       own storage.
01338 
01339       @return The address of the next hop for transaction @a txnp.
01340   */
01341   tsapi struct sockaddr const* TSHttpTxnNextHopAddrGet(TSHttpTxn txnp);
01342 
01343   tsapi TSReturnCode TSHttpTxnClientFdGet(TSHttpTxn txnp, int* fdp);
01344   tsapi TSReturnCode TSHttpTxnOutgoingAddrSet(TSHttpTxn txnp, struct sockaddr const* addr);
01345   tsapi TSReturnCode TSHttpTxnOutgoingTransparencySet(TSHttpTxn txnp, int flag);
01346 
01347   /* TS-1008: the above TXN calls for the Client conn should work with SSN */
01348   tsapi struct sockaddr const* TSHttpSsnClientAddrGet(TSHttpSsn ssnp);
01349   tsapi struct sockaddr const* TSHttpSsnIncomingAddrGet(TSHttpSsn ssnp);
01350   tsapi TSReturnCode TSHttpSsnClientFdGet(TSHttpSsn ssnp, int* fdp);
01351   /* TS-1008 END */
01352 
01353   /** Change packet firewall mark for the client side connection
01354    *
01355       @note The change takes effect immediately
01356       
01357       @return TS_SUCCESS if the client connection was modified
01358   */
01359   tsapi TSReturnCode TSHttpTxnClientPacketMarkSet(TSHttpTxn txnp, int mark);
01360   
01361   /** Change packet firewall mark for the server side connection
01362    *
01363       @note The change takes effect immediately, if no OS connection has been
01364       made, then this sets the mark that will be used IF an OS connection
01365       is established
01366       
01367       @return TS_SUCCESS if the (future?) server connection was modified
01368   */
01369   tsapi TSReturnCode TSHttpTxnServerPacketMarkSet(TSHttpTxn txnp, int mark);
01370   
01371   /** Change packet TOS for the client side connection
01372    *
01373       @note The change takes effect immediately
01374       
01375       @note TOS is deprecated and replaced by DSCP, this is still used to
01376       set DSCP however the first 2 bits of this value will be ignored as
01377       they now belong to the ECN field.
01378       
01379       @return TS_SUCCESS if the client connection was modified
01380   */
01381   tsapi TSReturnCode TSHttpTxnClientPacketTosSet(TSHttpTxn txnp, int tos);
01382   
01383   /** Change packet TOS for the server side connection
01384    *
01385       
01386       @note The change takes effect immediately, if no OS connection has been
01387       made, then this sets the mark that will be used IF an OS connection
01388       is established
01389       
01390       @note TOS is deprecated and replaced by DSCP, this is still used to
01391       set DSCP however the first 2 bits of this value will be ignored as
01392       they now belong to the ECN field.
01393       
01394       @return TS_SUCCESS if the (future?) server connection was modified
01395   */
01396   tsapi TSReturnCode TSHttpTxnServerPacketTosSet(TSHttpTxn txnp, int tos);
01397 
01398 
01399   /**
01400      Sets an error type body to a transaction. Note that both string arguments
01401      must be allocated with TSmalloc() or TSstrdup(). The mimetype argument is
01402      optional, if not provided it defaults to "text/html". Sending an emptry
01403      string would prevent setting a content type header (but that is not adviced).
01404 
01405      @param txnp HTTP transaction whose parent proxy to get.
01406      @param buf The body message (must be heap allocated).
01407      @param buflength Length of the body message.
01408      @param mimetype The MIME type to set the response to (can be NULL, but must
01409             be heap allocated if non-NULL).
01410   */
01411   tsapi void TSHttpTxnErrorBodySet(TSHttpTxn txnp, char* buf, size_t buflength, char* mimetype);
01412 
01413   /**
01414       Retrieves the parent proxy hostname and port, if parent
01415       proxying is enabled. If parent proxying is not enabled,
01416       TSHttpTxnParentProxyGet() sets hostname to NULL and port to -1.
01417 
01418       @param txnp HTTP transaction whose parent proxy to get.
01419       @param hostname of the parent proxy.
01420       @param port parent proxy's port.
01421 
01422    */
01423   tsapi TSReturnCode TSHttpTxnParentProxyGet(TSHttpTxn txnp, char** hostname, int* port);
01424 
01425   /**
01426       Sets the parent proxy name and port. The string hostname is copied
01427       into the TSHttpTxn; you can modify or delete the string after
01428       calling TSHttpTxnParentProxySet().
01429 
01430       @param txnp HTTP transaction whose parent proxy to set.
01431       @param hostname parent proxy host name string.
01432       @param port parent proxy port to set.
01433 
01434    */
01435   tsapi void TSHttpTxnParentProxySet(TSHttpTxn txnp, char* hostname, int port);
01436 
01437   tsapi void TSHttpTxnUntransformedRespCache(TSHttpTxn txnp, int on);
01438   tsapi void TSHttpTxnTransformedRespCache(TSHttpTxn txnp, int on);
01439 
01440   /**
01441       Notifies the HTTP transaction txnp that the plugin is
01442       finished processing the current hook. The plugin tells the
01443       transaction to either continue (TS_EVENT_HTTP_CONTINUE) or stop
01444       (TS_EVENT_HTTP_ERROR).
01445 
01446       You must always reenable the HTTP transaction after the processing
01447       of each transaction event. However, never reenable twice.
01448       Reenabling twice is a serious error.
01449 
01450       @param txnp transaction to be reenabled.
01451       @param event tells the transaction how to continue:
01452         - TS_EVENT_HTTP_CONTINUE, which means that the transaction
01453           should continue.
01454         - TS_EVENT_HTTP_ERROR which terminates the transaction
01455           and sends an error to the client if no response has already
01456           been sent.
01457 
01458    */
01459   tsapi void TSHttpTxnReenable(TSHttpTxn txnp, TSEvent event);
01460   tsapi TSReturnCode TSHttpCacheReenable(TSCacheTxn txnp, const TSEvent event, const void* data, const uint64_t size);
01461 
01462   tsapi void TSHttpTxnArgSet(TSHttpTxn txnp, int arg_idx, void* arg);
01463   tsapi void* TSHttpTxnArgGet(TSHttpTxn txnp, int arg_idx);
01464   tsapi void TSHttpSsnArgSet(TSHttpSsn ssnp, int arg_idx, void* arg);
01465   tsapi void* TSHttpSsnArgGet(TSHttpSsn ssnp, int arg_idx);
01466 
01467   /* The reserve API should only be use in TSAPI plugins, during plugin initialization! */
01468   /* The lookup methods can be used anytime, but are best used during initialization as well,
01469      or at least "cache" the results for best performance. */
01470   tsapi TSReturnCode TSHttpArgIndexReserve(const char* name, const char* description, int* arg_idx);
01471   tsapi TSReturnCode TSHttpArgIndexNameLookup(const char* name, int* arg_idx, const char** description);
01472   tsapi TSReturnCode TSHttpArgIndexLookup(int arg_idx, const char** name, const char** description);
01473 
01474   /* ToDo: This is a leftover from olden days, can we eliminate? */
01475   tsapi void TSHttpTxnSetHttpRetStatus(TSHttpTxn txnp, TSHttpStatus http_retstatus);
01476 
01477   tsapi void TSHttpTxnActiveTimeoutSet(TSHttpTxn txnp, int timeout);
01478   tsapi void TSHttpTxnConnectTimeoutSet(TSHttpTxn txnp, int timeout);
01479   tsapi void TSHttpTxnDNSTimeoutSet(TSHttpTxn txnp, int timeout);
01480   tsapi void TSHttpTxnNoActivityTimeoutSet(TSHttpTxn txnp, int timeout);
01481 
01482   tsapi TSServerState TSHttpTxnServerStateGet(TSHttpTxn txnp);
01483 
01484   /* --------------------------------------------------------------------------
01485      Transaction specific debugging control  */
01486 
01487   /**
01488          Set the transaction specific debugging flag for this transaction.
01489          When turned on, internal debug messages related to this transaction
01490          will be written even if the debug tag isn't on.
01491 
01492       @param txnp transaction to change.
01493       @param on set to 1 to turn on, 0 to turn off.
01494   */
01495   tsapi void TSHttpTxnDebugSet(TSHttpTxn txnp, int on);
01496   /**
01497          Returns the transaction specific debugging flag for this transaction.
01498 
01499       @param txnp transaction to check.
01500       @return 1 if enabled, 0 otherwise.
01501   */
01502   tsapi int TSHttpTxnDebugGet(TSHttpTxn txnp);
01503   /**
01504          Set the session specific debugging flag for this client session.
01505          When turned on, internal debug messages related to this session and all transactions
01506          in the session will be written even if the debug tag isn't on.
01507 
01508       @param ssnp Client session to change.
01509       @param on set to 1 to turn on, 0 to turn off.
01510   */
01511   tsapi void TSHttpSsnDebugSet(TSHttpSsn ssnp, int on);
01512   /**
01513          Returns the transaction specific debugging flag for this client session.
01514 
01515       @param txnp Client session to check.
01516       @return 1 if enabled, 0 otherwise.
01517   */
01518   tsapi int TSHttpSsnDebugGet(TSHttpSsn ssnp, int *on);
01519 
01520   /* --------------------------------------------------------------------------
01521      Intercepting Http Transactions */
01522 
01523   /**
01524       Allows a plugin take over the servicing of the request as though
01525       it was the origin server. contp will be sent TS_EVENT_NET_ACCEPT.
01526       The edata passed with TS_NET_EVENT_ACCEPT is an TSVConn just as
01527       it would be for a normal accept. The plugin must act as if it is
01528       an http server and read the http request and body off the TSVConn
01529       and send an http response header and body.
01530 
01531       TSHttpTxnIntercept() must be called be called from only
01532       TS_HTTP_READ_REQUEST_HOOK. Using TSHttpTxnIntercept will
01533       bypass the Traffic Server cache. If response sent by the plugin
01534       should be cached, use TSHttpTxnServerIntercept() instead.
01535       TSHttpTxnIntercept() primary use is allow plugins to serve data
01536       about their functioning directly.
01537 
01538       TSHttpTxnIntercept() must only be called once per transaction.
01539 
01540       @param contp continuation called to handle the interception.
01541       @param txnp transaction to be intercepted.
01542 
01543    */
01544   tsapi void TSHttpTxnIntercept(TSCont contp, TSHttpTxn txnp);
01545 
01546   /**
01547       Allows a plugin take over the servicing of the request as though
01548       it was the origin server. In the event a request needs to be
01549       made to the server for transaction txnp, contp will be sent
01550       TS_EVENT_NET_ACCEPT. The edata passed with TS_NET_EVENT_ACCEPT
01551       is an TSVConn just as it would be for a normal accept. The plugin
01552       must act as if it is an http server and read the http request and
01553       body off the TSVConn and send an http response header and body.
01554 
01555       TSHttpTxnInterceptServer() must be not be called after
01556       the connection to the server has taken place. The last hook
01557       last hook in that TSHttpTxnIntercept() can be called from is
01558       TS_HTTP_READ_CACHE_HDR_HOOK. If a connection to the server is
01559       not necessary, contp is not called.
01560 
01561       The response from the plugin is cached subject to standard
01562       and configured http caching rules. Should the plugin wish the
01563       response not be cached, the plugin must use appropriate http
01564       response headers to prevent caching. The primary purpose of
01565       TSHttpTxnInterceptServer() is allow plugins to provide gateways
01566       to other protocols or to allow to plugin to it's own transport for
01567       the next hop to the server. TSHttpTxnInterceptServer() overrides
01568       parent cache configuration.
01569 
01570       TSHttpTxnInterceptServer() must only be called once per
01571       transaction.
01572 
01573       @param contp continuation called to handle the interception
01574       @param txnp transaction to be intercepted.
01575 
01576    */
01577   tsapi void TSHttpTxnServerIntercept(TSCont contp, TSHttpTxn txnp);
01578 
01579   /* --------------------------------------------------------------------------
01580      Initiate Http Connection */
01581 
01582   /**
01583       Allows the plugin to initiate an http connection. The TSVConn the
01584       plugin receives as the result of successful operates identically to
01585       one created through TSNetConnect. Aside from allowing the plugin
01586       to set the client ip and port for logging, the functionality of
01587       TSHttpConnect() is identical to connecting to localhost on the
01588       proxy port with TSNetConnect(). TSHttpConnect() is more efficient
01589       than TSNetConnect() to localhost since it avoids the overhead of
01590       passing the data through the operating system.
01591 
01592       This returns a VConn that connected to the transaction.
01593 
01594       @param addr Target address of the origin server.
01595       @param tag A logging tag that can be accessed via the pitag field. May be @c NULL.
01596       @param id A logging id that can be access via the piid field.
01597    */
01598   tsapi TSVConn TSHttpConnectWithPluginId(struct sockaddr const* addr, char const* tag, int64_t id);
01599 
01600   /** Backwards compatible version.
01601       This provides a @a tag of "plugin" and an @a id of 0.
01602    */
01603   tsapi TSVConn TSHttpConnect(struct sockaddr const* addr);
01604 
01605     /* --------------------------------------------------------------------------
01606      Initiate Transparent Http Connection */
01607   /**
01608       Allows the plugin to initiate a transparent http connection. This operates
01609       identically to TSHttpConnect except that it is treated as an intercepted
01610       transparent connection by the session and transaction state machines.
01611 
01612       @param client_addr the address that the resulting connection will be seen as
01613         coming from
01614       @param server_addr the address that the resulting connection will be seen as
01615         attempting to connect to when intercepted
01616       @param vc will be set to point to the new TSVConn on success.
01617 
01618    */
01619   tsapi TSVConn TSHttpConnectTransparent(struct sockaddr const* client_addr, struct sockaddr const * server_addr);
01620 
01621   tsapi void TSFetchUrl(const char* request,int request_len, struct sockaddr const* addr, TSCont contp, TSFetchWakeUpOptions callback_options,TSFetchEvent event);
01622   tsapi void TSFetchPages(TSFetchUrlParams_t* params);
01623 
01624   /* Check if HTTP State machine is internal or not */
01625   tsapi TSReturnCode TSHttpIsInternalRequest(TSHttpTxn txnp);
01626   tsapi TSReturnCode TSHttpIsInternalSession(TSHttpSsn ssnp);
01627 
01628   /* --------------------------------------------------------------------------
01629      HTTP alternate selection */
01630   tsapi TSReturnCode TSHttpAltInfoClientReqGet(TSHttpAltInfo infop, TSMBuffer* bufp, TSMLoc* offset);
01631   tsapi TSReturnCode TSHttpAltInfoCachedReqGet(TSHttpAltInfo infop, TSMBuffer* bufp, TSMLoc* offset);
01632   tsapi TSReturnCode TSHttpAltInfoCachedRespGet(TSHttpAltInfo infop, TSMBuffer* bufp, TSMLoc* offset);
01633   tsapi void TSHttpAltInfoQualitySet(TSHttpAltInfo infop, float quality);
01634 
01635   /* --------------------------------------------------------------------------
01636      Actions */
01637   tsapi void TSActionCancel(TSAction actionp);
01638   tsapi int TSActionDone(TSAction actionp);
01639 
01640   /* --------------------------------------------------------------------------
01641      VConnections */
01642   tsapi TSVIO TSVConnReadVIOGet(TSVConn connp);
01643   tsapi TSVIO TSVConnWriteVIOGet(TSVConn connp);
01644   tsapi int TSVConnClosedGet(TSVConn connp);
01645 
01646   tsapi TSVIO TSVConnRead(TSVConn connp, TSCont contp, TSIOBuffer bufp, int64_t nbytes);
01647   tsapi TSVIO TSVConnWrite(TSVConn connp, TSCont contp, TSIOBufferReader readerp, int64_t nbytes);
01648   tsapi void TSVConnClose(TSVConn connp);
01649   tsapi void TSVConnAbort(TSVConn connp, int error);
01650   tsapi void TSVConnShutdown(TSVConn connp, int read, int write);
01651 
01652   /* --------------------------------------------------------------------------
01653      Cache VConnections */
01654   tsapi int64_t TSVConnCacheObjectSizeGet(TSVConn connp);
01655 
01656   /* --------------------------------------------------------------------------
01657      Transformations */
01658   tsapi TSVConn TSTransformCreate(TSEventFunc event_funcp, TSHttpTxn txnp);
01659   tsapi TSVConn TSTransformOutputVConnGet(TSVConn connp);
01660 
01661   /* --------------------------------------------------------------------------
01662      Net VConnections */
01663 
01664   tsapi struct sockaddr const* TSNetVConnRemoteAddrGet(TSVConn vc);
01665 
01666   /**
01667       Opens a network connection to the host specified by ip on the port
01668       specified by port. If the connection is successfully opened, contp
01669       is called back with the event TS_EVENT_NET_CONNECT and the new
01670       network vconnection will be passed in the event data parameter.
01671       If the connection is not successful, contp is called back with
01672       the event TS_EVENT_NET_CONNECT_FAILED.
01673 
01674       Note: on Solaris, it is possible to receive TS_EVENT_NET_CONNECT
01675       even if the connection failed, because of the implementation of
01676       network sockets in the underlying operating system. There is an
01677       exception: if a plugin tries to open a connection to a port on
01678       its own host machine, then TS_EVENT_NET_CONNECT is sent only
01679       if the connection is successfully opened. In general, however,
01680       your plugin needs to look for an TS_EVENT_VCONN_WRITE_READY to
01681       be sure that the connection is successfully opened.
01682 
01683       @return something allows you to check if the connection is complete,
01684         or cancel the attempt to connect.
01685 
01686    */
01687   tsapi TSAction TSNetConnect(TSCont contp, /**< continuation that is called back when the attempted net connection either succeeds or fails. */
01688                               struct sockaddr const* to /**< Address to which to connect. */
01689   );
01690 
01691   tsapi TSAction TSNetAccept(TSCont contp, int port, int domain, int accept_threads);
01692 
01693   /**
01694     Listen on all SSL ports for connections for the specified protocol name.
01695 
01696     TSNetAcceptNamedProtocol registers the specified protocol for all
01697     statically configured TLS ports. When a client using the TLS Next Protocol
01698     Negotiation extension negotiates the requested protocol, TrafficServer will
01699     route the request to the given handler. Note that the protocol is not
01700     registered on ports opened by other plugins.
01701 
01702     The event and data provided to the handler are the same as for
01703     TSNetAccept(). If a connection is successfully accepted, the event code
01704     will be TS_EVENT_NET_ACCEPT and the event data will be a valid TSVConn
01705     bound to the accepted connection.
01706 
01707     Neither contp nor protocol are copied. They must remain valid for the
01708     lifetime of the plugin.
01709 
01710     TSNetAcceptNamedProtocol fails if the requested protocol cannot be
01711     registered on all of the configured TLS ports. If it fails, the protocol
01712     will not be registered on any ports (ie.. no partial failure).
01713   */
01714   tsapi TSReturnCode TSNetAcceptNamedProtocol(TSCont contp, const char * protocol);
01715 
01716   /**
01717     Create a new port from the string specification used by the
01718     proxy.config.http.server_ports configuration value.
01719    */
01720   tsapi TSPortDescriptor TSPortDescriptorParse(const char * descriptor);
01721 
01722   /**
01723      Start listening on the given port descriptor. If a connection is
01724      successfully accepted, the TS_EVENT_NET_ACCEPT is delivered to the
01725      continuation. The event data will be a valid TSVConn bound to the accepted
01726      connection.
01727    */
01728   tsapi TSReturnCode TSPortDescriptorAccept(TSPortDescriptor, TSCont);
01729 
01730   /* --------------------------------------------------------------------------
01731      DNS Lookups */
01732   tsapi TSAction TSHostLookup(TSCont contp, const char* hostname, size_t namelen);
01733   tsapi struct sockaddr const* TSHostLookupResultAddrGet(TSHostLookupResult lookup_result);
01734   /* TODO: Eventually, we might want something like this as well, but it requires
01735      support for building the HostDBInfo struct:
01736      tsapi void TSHostLookupResultSet(TSHttpTxn txnp, TSHostLookupResult result);
01737   */
01738 
01739   /* --------------------------------------------------------------------------
01740      Cache VConnections */
01741   /**
01742       Asks the Traffic Server cache if the object corresponding to key
01743       exists in the cache and can be read. If the object can be read,
01744       the Traffic Server cache calls the continuation contp back with
01745       the event TS_EVENT_CACHE_OPEN_READ. In this case, the cache also
01746       passes contp a cache vconnection and contp can then initiate a
01747       read operation on that vconnection using TSVConnRead.
01748 
01749       If the object cannot be read, the cache calls contp back with
01750       the event TS_EVENT_CACHE_OPEN_READ_FAILED. The user (contp)
01751       has the option to cancel the action returned by TSCacheRead.
01752       Note that reentrant calls are possible, i.e. the cache can call
01753       back the user (contp) in the same call.
01754 
01755       @param contp continuation to be called back if a read operation
01756         is permissible.
01757       @param key cache key corresponding to the object to be read.
01758       @return something allowing the user to cancel or schedule the
01759         cache read.
01760 
01761    */
01762   tsapi TSAction TSCacheRead(TSCont contp, TSCacheKey key);
01763 
01764   /**
01765       Asks the Traffic Server cache if contp can start writing the
01766       object (corresponding to key) to the cache. If the object
01767       can be written, the cache calls contp back with the event
01768       TS_EVENT_CACHE_OPEN_WRITE. In this case, the cache also passes
01769       contp a cache vconnection and contp can then initiate a write
01770       operation on that vconnection using TSVConnWrite. The object
01771       is not committed to the cache until the vconnection is closed.
01772       When all data has been transferred, the user (contp) must do
01773       an TSVConnClose. In case of any errors, the user MUST do an
01774       TSVConnAbort(contp, 0).
01775 
01776       If the object cannot be written, the cache calls contp back with
01777       the event TS_EVENT_CACHE_OPEN_WRITE_FAILED. This can happen,
01778       for example, if there is another object with the same key being
01779       written to the cache. The user (contp) has the option to cancel
01780       the action returned by TSCacheWrite.
01781 
01782       Note that reentrant calls are possible, i.e. the cache can call
01783       back the user (contp) in the same call.
01784 
01785       @param contp continuation that the cache calls back (telling it
01786         whether the write operation can proceed or not).
01787       @param key cache key corresponding to the object to be cached.
01788       @return something allowing the user to cancel or schedule the
01789         cache write.
01790 
01791    */
01792   tsapi TSAction TSCacheWrite(TSCont contp, TSCacheKey key);
01793 
01794   /**
01795       Removes the object corresponding to key from the cache. If the
01796       object was removed successfully, the cache calls contp back
01797       with the event TS_EVENT_CACHE_REMOVE. If the object was not
01798       found in the cache, the cache calls contp back with the event
01799       TS_EVENT_CACHE_REMOVE_FAILED.
01800 
01801       In both of these callbacks, the user (contp) does not have to do
01802       anything. The user does not get any vconnection from the cache,
01803       since no data needs to be transferred. When the cache calls
01804       contp back with TS_EVENT_CACHE_REMOVE, the remove has already
01805       been commited.
01806 
01807       @param contp continuation that the cache calls back reporting the
01808         success or failure of the remove.
01809       @param key cache key corresponding to the object to be removed.
01810       @return something allowing the user to cancel or schedule the
01811         remove.
01812 
01813    */
01814   tsapi TSAction TSCacheRemove(TSCont contp, TSCacheKey key);
01815   tsapi TSReturnCode TSCacheReady(int* is_ready);
01816   tsapi TSAction TSCacheScan(TSCont contp, TSCacheKey key, int KB_per_second);
01817 
01818   /* --------------------------------------------------------------------------
01819      VIOs */
01820   tsapi void TSVIOReenable(TSVIO viop);
01821   tsapi TSIOBuffer TSVIOBufferGet(TSVIO viop);
01822   tsapi TSIOBufferReader TSVIOReaderGet(TSVIO viop);
01823   tsapi int64_t TSVIONBytesGet(TSVIO viop);
01824   tsapi void TSVIONBytesSet(TSVIO viop, int64_t nbytes);
01825   tsapi int64_t TSVIONDoneGet(TSVIO viop);
01826   tsapi void TSVIONDoneSet(TSVIO viop, int64_t ndone);
01827   tsapi int64_t TSVIONTodoGet(TSVIO viop);
01828   tsapi TSMutex TSVIOMutexGet(TSVIO viop);
01829   tsapi TSCont TSVIOContGet(TSVIO viop);
01830   tsapi TSVConn TSVIOVConnGet(TSVIO viop);
01831 
01832   /* --------------------------------------------------------------------------
01833      Buffers */
01834   tsapi TSIOBuffer TSIOBufferCreate(void);
01835 
01836   /**
01837       Creates a new TSIOBuffer of the specified size. With this function,
01838       you can create smaller buffers than the 32K buffer created by
01839       TSIOBufferCreate(). In some situations using smaller buffers can
01840       improve performance.
01841 
01842       @param index size of the new TSIOBuffer to be created.
01843       @param new TSIOBuffer of the specified size.
01844 
01845    */
01846   tsapi TSIOBuffer TSIOBufferSizedCreate(TSIOBufferSizeIndex index);
01847 
01848   /**
01849       The watermark of an TSIOBuffer is the minimum number of bytes
01850       of data that have to be in the buffer before calling back any
01851       continuation that has initiated a read operation on this buffer.
01852       TSIOBufferWaterMarkGet() will provide the size of the watermark,
01853       in bytes, for a specified TSIOBuffer.
01854 
01855       @param bufp buffer whose watermark the function gets.
01856 
01857    */
01858   tsapi int64_t TSIOBufferWaterMarkGet(TSIOBuffer bufp);
01859 
01860   /**
01861       The watermark of an TSIOBuffer is the minimum number of bytes
01862       of data that have to be in the buffer before calling back any
01863       continuation that has initiated a read operation on this buffer.
01864       As a writer feeds data into the TSIOBuffer, no readers are called
01865       back until the amount of data reaches the watermark. Setting
01866       a watermark can improve performance because it avoids frequent
01867       callbacks to read small amounts of data. TSIOBufferWaterMarkSet()
01868       assigns a watermark to a particular TSIOBuffer.
01869 
01870       @param bufp buffer whose water mark the function sets.
01871       @param water_mark watermark setting, as a number of bytes.
01872 
01873    */
01874   tsapi void TSIOBufferWaterMarkSet(TSIOBuffer bufp, int64_t water_mark);
01875 
01876   tsapi void TSIOBufferDestroy(TSIOBuffer bufp);
01877   tsapi TSIOBufferBlock TSIOBufferStart(TSIOBuffer bufp);
01878   tsapi int64_t TSIOBufferCopy(TSIOBuffer bufp, TSIOBufferReader readerp, int64_t length, int64_t offset);
01879 
01880   /**
01881       Writes length bytes of data contained in the string buf to the
01882       TSIOBuffer bufp. Returns the number of bytes of data successfully
01883       written to the TSIOBuffer.
01884 
01885       @param bufp is the TSIOBuffer to write into.
01886       @param buf string to write into the TSIOBuffer.
01887       @param length of the string buf.
01888       @return length of data successfully copied into the buffer,
01889         in bytes.
01890 
01891    */
01892   tsapi int64_t TSIOBufferWrite(TSIOBuffer bufp, const void* buf, int64_t length);
01893   tsapi void TSIOBufferProduce(TSIOBuffer bufp, int64_t nbytes);
01894 
01895   tsapi TSIOBufferBlock TSIOBufferBlockNext(TSIOBufferBlock blockp);
01896   tsapi const char* TSIOBufferBlockReadStart(TSIOBufferBlock blockp, TSIOBufferReader readerp, int64_t* avail);
01897   tsapi int64_t TSIOBufferBlockReadAvail(TSIOBufferBlock blockp, TSIOBufferReader readerp);
01898   tsapi char* TSIOBufferBlockWriteStart(TSIOBufferBlock blockp, int64_t* avail);
01899   tsapi int64_t TSIOBufferBlockWriteAvail(TSIOBufferBlock blockp);
01900 
01901   tsapi TSIOBufferReader TSIOBufferReaderAlloc(TSIOBuffer bufp);
01902   tsapi TSIOBufferReader TSIOBufferReaderClone(TSIOBufferReader readerp);
01903   tsapi void TSIOBufferReaderFree(TSIOBufferReader readerp);
01904   tsapi TSIOBufferBlock TSIOBufferReaderStart(TSIOBufferReader readerp);
01905   tsapi void TSIOBufferReaderConsume(TSIOBufferReader readerp, int64_t nbytes);
01906   tsapi int64_t TSIOBufferReaderAvail(TSIOBufferReader readerp);
01907 
01908    tsapi struct sockaddr const* TSNetVConnLocalAddrGet(TSVConn vc);
01909 
01910   /* --------------------------------------------------------------------------
01911      Stats and configs based on librecords raw stats (this is preferred API until we
01912      rewrite stats). This system has a limitation of up to 1,500 stats max, controlled
01913      via proxy.config.stat_api.max_stats_allowed (default is 512).
01914 
01915      This is available as of Apache TS v2.2.*/
01916   typedef enum
01917   {
01918     TS_STAT_PERSISTENT = 1,
01919     TS_STAT_NON_PERSISTENT
01920   } TSStatPersistence;
01921 
01922   typedef enum
01923   {
01924     TS_STAT_SYNC_SUM = 0,
01925     TS_STAT_SYNC_COUNT,
01926     TS_STAT_SYNC_AVG,
01927     TS_STAT_SYNC_TIMEAVG
01928   } TSStatSync;
01929 
01930   /* APIs to create new records.config configurations */
01931   tsapi TSReturnCode TSMgmtStringCreate(TSRecordType rec_type, const char *name, const TSMgmtString data_default,
01932                                         TSRecordUpdateType update_type, TSRecordCheckType check_type,
01933                                         const char *check_regex, TSRecordAccessType access_type);
01934   tsapi TSReturnCode TSMgmtIntCreate(TSRecordType rec_type, const char *name, TSMgmtInt data_default,
01935                                      TSRecordUpdateType update_type, TSRecordCheckType check_type,
01936                                      const char *check_regex, TSRecordAccessType access_type);
01937 
01938   /*  Note that only TS_RECORDDATATYPE_INT is supported at this point. */
01939   tsapi int TSStatCreate(const char* the_name, TSRecordDataType the_type, TSStatPersistence persist, TSStatSync sync);
01940 
01941   tsapi void TSStatIntIncrement(int the_stat, TSMgmtInt amount);
01942   tsapi void TSStatIntDecrement(int the_stat, TSMgmtInt amount);
01943   /* Currently not supported. */
01944   /* tsapi void TSStatFloatIncrement(int the_stat, float amount); */
01945   /* tsapi void TSStatFloatDecrement(int the_stat, float amount); */
01946 
01947   tsapi TSMgmtInt TSStatIntGet(int the_stat);
01948   tsapi void TSStatIntSet(int the_stat, TSMgmtInt value);
01949   /* Currently not supported. */
01950   /* tsapi TSeturnCode TSStatFloatGet(int the_stat, float* value); */
01951   /* tsapi TSReturnCode TSStatFloatSet(int the_stat, float value); */
01952 
01953   tsapi TSReturnCode TSStatFindName(const char* name, int* idp);
01954 
01955   /* --------------------------------------------------------------------------
01956      tracing api */
01957 
01958   tsapi int TSIsDebugTagSet(const char* t);
01959   tsapi void TSDebug(const char* tag, const char* format_str, ...) TS_PRINTFLIKE(2, 3);
01960   /**
01961       Output a debug line even if the debug tag is turned off, as long as
01962       debugging is enabled. Could be used as follows:
01963       @code
01964       TSDebugSpecifc(TSHttpTxnDebugGet(txn), "plugin_tag" , "Hello World from transaction %p", txn);
01965       @endcode
01966       will be printed if the plugin_tag is enabled or the transaction specific
01967       debugging is turned on for txn.
01968 
01969       @param debug_flag boolean flag.
01970       @param tag Debug tag for the line.
01971       @param format Format string.
01972       @param ... Format arguments.
01973    */
01974   tsapi void TSDebugSpecific(int debug_flag, const char* tag, const char* format_str, ...) TS_PRINTFLIKE(3, 4);
01975   extern int diags_on_for_plugins;
01976 #define TSDEBUG if (diags_on_for_plugins) TSDebug
01977 
01978   /* --------------------------------------------------------------------------
01979      logging api */
01980 
01981   /**
01982       The following enum values are flags, so they should be powers
01983       of two. With the exception of TS_LOG_MODE_INVALID_FLAG, they
01984       are all used to configure the creation of an TSTextLogObject
01985       through the mode argument to TSTextLogObjectCreate().
01986       TS_LOG_MODE_INVALID_FLAG is used internally to check the validity
01987       of this argument. Insert new flags before TS_LOG_MODE_INVALID_FLAG,
01988       and set TS_LOG_MODE_INVALID_FLAG to the largest power of two of
01989       the enum.
01990 
01991    */
01992   enum
01993   {
01994     TS_LOG_MODE_ADD_TIMESTAMP = 1,
01995     TS_LOG_MODE_DO_NOT_RENAME = 2,
01996     TS_LOG_MODE_INVALID_FLAG = 4
01997   };
01998 
01999   /**
02000       This type represents a custom log file that you create with
02001       TSTextLogObjectCreate(). Your plugin writes entries into this
02002       log file using TSTextLogObjectWrite().
02003 
02004    */
02005   typedef struct tsapi_textlogobject* TSTextLogObject;
02006 
02007   typedef void (*TSRecordDumpCb) (TSRecordType rec_type, void* edata, int registered, const char* name, TSRecordDataType data_type, TSRecordData* datum);
02008 
02009   tsapi void TSRecordDump(int rec_type, TSRecordDumpCb callback, void* edata);
02010 
02011   /**
02012 
02013       Creates a new custom log file that your plugin can write to. You
02014       can design the fields and inputs to the log file using the
02015       TSTextLogObjectWrite() function. The logs you create are treated
02016       like ordinary logs; they are rolled if log rolling is enabled. (Log
02017       collation is not supported though).
02018 
02019       @param filename new log file being created. The new log file
02020         is created in the logs directory. You can specify a path to a
02021         subdirectory within the log directory, e.g. subdir/filename,
02022         but make sure you create the subdirectory first. If you do
02023         not specify a file name extension, the extension ".log" is
02024         automatically added.
02025       @param mode is one (or both) of the following:
02026         - TS_LOG_MODE_ADD_TIMESTAMP Whenever the plugin makes a log
02027           entry using TSTextLogObjectWrite (see below), it prepends
02028           the entry with a timestamp.
02029         - TS_LOG_MODE_DO_NOT_RENAME This means that if there is a
02030           filename conflict, Traffic Server should not attempt to rename
02031           the custom log. The consequence of a name conflict is that the
02032           custom log will simply not be created, e.g. suppose you call:
02033             @code
02034             log = TSTextLogObjectCreate("squid" , mode, NULL, &error);
02035             @endcode
02036           If mode is TS_LOG_MODE_DO_NOT_RENAME, you will NOT get a new
02037           log (you'll get a null pointer) if squid.log already exists.
02038           If mode is not TS_LOG_MODE_DO_NOT_RENAME, Traffic Server
02039           tries to rename the log to a new name (it will try squid_1.log).
02040       @param new_log_obj new custom log file.
02041       @return error code:
02042         - TS_LOG_ERROR_NO_ERROR No error; the log object has been
02043           created successfully.
02044         - TS_LOG_ERROR_OBJECT_CREATION Log object not created. This
02045           error is rare and would most likely be caused by the system
02046           running out of memory.
02047         - TS_LOG_ERROR_FILENAME_CONFLICTS You get this error if mode =
02048           TS_LOG_MODE_DO_NOT_RENAME, and if there is a naming conflict.
02049           The log object is not created.
02050         - TS_LOG_ERROR_FILE_ACCESS Log object not created because of
02051           a file access problem (for example, no write permission to the
02052           logging directory, or a specified subdirectory for the log file
02053           does not exist).
02054 
02055    */
02056   tsapi TSReturnCode TSTextLogObjectCreate(const char* filename, int mode, TSTextLogObject* new_log_obj);
02057 
02058   /**
02059       Writes a printf-style formatted statement to an TSTextLogObject
02060       (a plugin custom log).
02061 
02062       @param the_object log object to write to. You must first create
02063         this object with TSTextLogObjectCreate().
02064       @param format printf-style formatted statement to be printed.
02065       @param ... parameters in the formatted statement. A newline is
02066         automatically added to the end.
02067       @return one of the following errors:
02068         - TS_LOG_ERROR_NO_ERROR Means that the write was successful.
02069         - TS_LOG_ERROR_LOG_SPACE_EXHAUSTED Means that Traffic Server
02070           ran out of disk space for logs. If you see this error you might
02071           want to roll logs more often.
02072         - TS_LOG_ERROR_INTERNAL_ERROR Indicates some internal problem
02073           with a log entry (such as an entry larger than the size of the
02074           log write buffer). This error is very unusual.
02075 
02076    */
02077   tsapi TSReturnCode TSTextLogObjectWrite(TSTextLogObject the_object, const char* format, ...) TS_PRINTFLIKE(2, 3);
02078 
02079   /**
02080       This immediately flushes the contents of the log write buffer for
02081       the_object to disk. Use this call only if you want to make sure that
02082       log entries are flushed immediately. This call has a performance
02083       cost. Traffic Server flushes the log buffer automatically about
02084       every 1 second.
02085 
02086       @param the_object custom log file whose write buffer is to be
02087         flushed.
02088 
02089    */
02090   tsapi void TSTextLogObjectFlush(TSTextLogObject the_object);
02091 
02092   /**
02093       Destroys a log object and releases the memory allocated to it.
02094       Use this call if you are done with the log.
02095 
02096       @param  the_object custom log to be destroyed.
02097 
02098    */
02099   tsapi TSReturnCode TSTextLogObjectDestroy(TSTextLogObject the_object);
02100 
02101   /**
02102       Set log header.
02103 
02104    */
02105   tsapi void TSTextLogObjectHeaderSet(TSTextLogObject the_object, const char* header);
02106 
02107   /**
02108       Enable/disable rolling.
02109 
02110       @param rolling_enabled a valid proxy.config.log.rolling_enabled value.
02111 
02112    */
02113   tsapi TSReturnCode TSTextLogObjectRollingEnabledSet(TSTextLogObject the_object, int rolling_enabled);
02114 
02115   /**
02116       Set the rolling interval.
02117 
02118    */
02119   tsapi void TSTextLogObjectRollingIntervalSecSet(TSTextLogObject the_object, int rolling_interval_sec);
02120 
02121   /**
02122       Set the rolling offset. rolling_offset_hr specifies the hour (between 0 and 23) when log rolling
02123       should take place.
02124 
02125    */
02126   tsapi void TSTextLogObjectRollingOffsetHrSet(TSTextLogObject the_object, int rolling_offset_hr);
02127 
02128   /**
02129       Async disk IO read
02130 
02131       @return TS_SUCCESS or TS_ERROR.
02132    */
02133   tsapi TSReturnCode TSAIORead(int fd, off_t offset, char* buf, size_t buffSize, TSCont contp);
02134 
02135   /**
02136       Async disk IO buffer get
02137 
02138       @return char* to the buffer
02139    */
02140   tsapi char* TSAIOBufGet(TSAIOCallback data);
02141 
02142   /**
02143       Async disk IO get number of bytes
02144 
02145       @return the number of bytes
02146    */
02147   tsapi int TSAIONBytesGet(TSAIOCallback data);
02148 
02149   /**
02150       Async disk IO write
02151 
02152       @return TS_SUCCESS or TS_ERROR.
02153    */
02154   tsapi TSReturnCode TSAIOWrite(int fd, off_t offset, char* buf, size_t bufSize, TSCont contp);
02155 
02156   /**
02157       Async disk IO set number of threads
02158 
02159       @return TS_SUCCESS or TS_ERROR.
02160    */
02161   tsapi TSReturnCode TSAIOThreadNumSet(int thread_num);
02162 
02163   /**
02164       Check if transaction was aborted (due client/server errors etc.)
02165 
02166       @return 1 if transaction was aborted
02167   */
02168   tsapi TSReturnCode TSHttpTxnAborted(TSHttpTxn txnp);
02169 
02170   tsapi TSVConn TSVConnCreate(TSEventFunc event_funcp, TSMutex mutexp);
02171   tsapi TSVConn TSVConnFdCreate(int fd);
02172 
02173   /* api functions to access stats */
02174   /* ClientResp APIs exist as well and are exposed in PrivateFrozen  */
02175   tsapi int TSHttpTxnClientReqHdrBytesGet(TSHttpTxn txnp);
02176   tsapi int64_t TSHttpTxnClientReqBodyBytesGet(TSHttpTxn txnp);
02177   tsapi int TSHttpTxnServerReqHdrBytesGet(TSHttpTxn txnp);
02178   tsapi int64_t TSHttpTxnServerReqBodyBytesGet(TSHttpTxn txnp);
02179   tsapi int TSHttpTxnPushedRespHdrBytesGet(TSHttpTxn txnp);
02180   tsapi int64_t TSHttpTxnPushedRespBodyBytesGet(TSHttpTxn txnp);
02181   tsapi int TSHttpTxnServerRespHdrBytesGet(TSHttpTxn txnp);
02182   tsapi int64_t TSHttpTxnServerRespBodyBytesGet(TSHttpTxn txnp);
02183   tsapi int TSHttpTxnClientRespHdrBytesGet(TSHttpTxn txnp);
02184   tsapi int64_t TSHttpTxnClientRespBodyBytesGet(TSHttpTxn txnp);
02185 
02186   /* NetVC timeout APIs. */
02187   tsapi void TSVConnInactivityTimeoutSet(TSVConn connp, TSHRTime timeout);
02188   tsapi void TSVConnInactivityTimeoutCancel(TSVConn connp);
02189   tsapi void TSVConnActiveTimeoutSet(TSVConn connp, TSHRTime timeout);
02190   tsapi void TSVConnActiveTimeoutCancel(TSVConn connp);
02191 
02192   /*
02193     ability to skip the remap phase of the State Machine
02194     this only really makes sense in TS_HTTP_READ_REQUEST_HDR_HOOK
02195   */
02196   tsapi void TSSkipRemappingSet(TSHttpTxn txnp, int flag);
02197 
02198 
02199   /*
02200     Set or get various overridable configurations, for a transaction. This should
02201     probably be done as early as possible, e.g. TS_HTTP_READ_REQUEST_HDR_HOOK.
02202   */
02203   tsapi TSReturnCode TSHttpTxnConfigIntSet(TSHttpTxn txnp, TSOverridableConfigKey conf, TSMgmtInt value);
02204   tsapi TSReturnCode TSHttpTxnConfigIntGet(TSHttpTxn txnp, TSOverridableConfigKey conf, TSMgmtInt* value);
02205   tsapi TSReturnCode TSHttpTxnConfigFloatSet(TSHttpTxn txnp, TSOverridableConfigKey conf, TSMgmtFloat value);
02206   tsapi TSReturnCode TSHttpTxnConfigFloatGet(TSHttpTxn txnp, TSOverridableConfigKey conf, TSMgmtFloat* value);
02207   tsapi TSReturnCode TSHttpTxnConfigStringSet(TSHttpTxn txnp, TSOverridableConfigKey conf, const char* value, int length);
02208   tsapi TSReturnCode TSHttpTxnConfigStringGet(TSHttpTxn txnp, TSOverridableConfigKey conf, const char** value, int* length);
02209 
02210   tsapi TSReturnCode TSHttpTxnConfigFind(const char* name, int length, TSOverridableConfigKey* conf, TSRecordDataType* type);
02211 
02212   /**
02213      This API informs the core to try to follow redirections (e.g. 301 responses.
02214      The new URL would be provided in the standard Location header.
02215 
02216      @param txnp the transaction pointer
02217      @param on   turn this on or off (0 or 1)
02218 
02219      @return @c TS_SUCCESS if it succeeded
02220   */
02221   tsapi TSReturnCode TSHttpTxnFollowRedirect(TSHttpTxn txnp, int on);
02222 
02223   /**
02224      This is a generalization of the TSHttpTxnFollowRedirect(), but gives finer
02225      control over the behavior. Instead of using the Location: header for the new
02226      destination, this API takes the new URL as a parameter. Calling this API
02227      transfers the ownership of the URL from the plugin to the core, so you must
02228      make sure it is heap allocated, and that you do not free it.
02229 
02230      Calling this API implicitly also enables the "Follow Redirect" feature, so
02231      there is no rason to call TSHttpTxnFollowRedirect() as well.
02232 
02233      @param txnp the transaction pointer
02234      @param url  a heap allocated string with the URL
02235      @param url_len the length of the URL
02236   */
02237   tsapi void TSHttpTxnRedirectUrlSet(TSHttpTxn txnp, const char* url, const int url_len);
02238   //  This is deprecated as of v5.0.0.
02239   tsapi TS_DEPRECATED void TSRedirectUrlSet(TSHttpTxn txnp, const char* url, const int url_len);
02240 
02241   /**
02242      Return the current (if set) redirection URL string. This is still owned by the
02243      core, and must not be free'd.
02244 
02245      @param txnp the transaction pointer
02246      @param url_len_ptr a pointer to where the URL length is to be stored
02247 
02248      @return the url string
02249   */
02250   tsapi const char* TSHttpTxnRedirectUrlGet(TSHttpTxn txnp, int* url_len_ptr);
02251   //  This is deprecated as of v5.0.0.
02252   tsapi TS_DEPRECATED const char* TSRedirectUrlGet(TSHttpTxn txnp, int* url_len_ptr);
02253 
02254   /**
02255      Return the number of redirection retries we have done. This starts off
02256      at zero, and can be used to select different URLs based on which attempt this
02257      is. This can be useful for example when providing a list of URLs to try, and
02258      do so in order until one succeeds.
02259 
02260      @param txnp the transaction pointer
02261 
02262      @return the redirect try count
02263   */
02264   tsapi int TSHttpTxnRedirectRetries(TSHttpTxn txnp);
02265 
02266   /* Get current HTTP connection stats */
02267   tsapi int TSHttpCurrentClientConnectionsGet(void);
02268   tsapi int TSHttpCurrentActiveClientConnectionsGet(void);
02269   tsapi int TSHttpCurrentIdleClientConnectionsGet(void);
02270   tsapi int TSHttpCurrentCacheConnectionsGet(void);
02271   tsapi int TSHttpCurrentServerConnectionsGet(void);
02272 
02273   /* =====  Http Transactions =====  */
02274   tsapi TSReturnCode TSHttpTxnCachedRespModifiableGet(TSHttpTxn txnp, TSMBuffer *bufp, TSMLoc *offset);
02275   tsapi TSReturnCode TSHttpTxnCacheLookupStatusSet(TSHttpTxn txnp, int cachelookup);
02276   tsapi TSReturnCode TSHttpTxnCacheLookupUrlGet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj);
02277   tsapi TSReturnCode TSHttpTxnPrivateSessionSet(TSHttpTxn txnp, int private_session);
02278   tsapi int TSHttpTxnBackgroundFillStarted(TSHttpTxn txnp);
02279 
02280   /* Expose internal Base64 Encoding / Decoding */
02281   tsapi TSReturnCode TSBase64Decode(const char *str, size_t str_len, unsigned char *dst, size_t dst_size, size_t *length);
02282   tsapi TSReturnCode TSBase64Encode(const char *str, size_t str_len, char *dst, size_t dst_size, size_t *length);
02283 
02284   /* Get milestone timers, useful for measuring where we are spending time in the transaction processing */
02285   /**
02286      Return the particular milestone timer for the transaction. If 0 is returned, it means
02287      the transaction has not yet reached that milestone. Asking for an "unknown" milestone is
02288      an error.
02289 
02290      @param txnp the transaction pointer
02291      @param milestone the requested milestone timer
02292      was created.
02293      @param time a pointer to a TSHRTime where we will store the timer
02294 
02295      @return @c TS_SUCCESS if the milestone is supported, TS_ERROR otherwise
02296 
02297   */
02298   tsapi TSReturnCode TSHttpTxnMilestoneGet(TSHttpTxn txnp, TSMilestonesType milestone, TSHRTime *time);
02299 
02300   /**
02301     Test whether a request / response header pair would be cacheable under the current
02302     configuration. This would typically be used in TS_HTTP_READ_RESPONSE_HDR_HOOK, when
02303     you have both the client request and server response ready.
02304 
02305     @param txnp the transaction pointer
02306     @param request the client request header. If NULL, use the transactions client request.
02307     @param response the server response header. If NULL, use the transactions origin response.
02308 
02309     @return 1 if the request / response is cacheable, 0 otherwise
02310   */
02311   tsapi int TSHttpTxnIsCacheable(TSHttpTxn txnp, TSMBuffer request, TSMBuffer response);
02312 
02313   /**
02314      Return a string respresentation for a TSServerState value. This is useful for plugin debugging.
02315 
02316      @param state the value of this TSServerState
02317 
02318      @return the string representation of the state
02319   */
02320   tsapi const char* TSHttpServerStateNameLookup(TSServerState state);
02321 
02322   /**
02323      Return a string respresentation for a TSHttpHookID value. This is useful for plugin debugging.
02324 
02325      @param hook the value of this TSHttpHookID
02326 
02327      @return the string representation of the hook ID
02328   */
02329   tsapi const char* TSHttpHookNameLookup(TSHttpHookID hook);
02330 
02331   /**
02332      Return a string respresentation for a TSEvent value. This is useful for plugin debugging.
02333 
02334      @param event the value of this TSHttpHookID
02335 
02336      @return the string representation of the event
02337   */
02338   tsapi const char* TSHttpEventNameLookup(TSEvent event);
02339 
02340 #ifdef __cplusplus
02341 }
02342 #endif /* __cplusplus */
02343 
02344 #endif /* __TS_API_H__ */

Generated by  doxygen 1.7.1