libUPnP
1.8.0
|
00001 /******************************************************************************* 00002 * 00003 * Copyright (c) 2000-2003 Intel Corporation 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * * Redistributions of source code must retain the above copyright notice, 00010 * this list of conditions and the following disclaimer. 00011 * * Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * * Neither name of Intel Corporation nor the names of its contributors 00015 * may be used to endorse or promote products derived from this software 00016 * without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00019 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00020 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00021 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 00022 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00023 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00024 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00025 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00026 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00027 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 ******************************************************************************/ 00031 00032 00033 #ifndef UPNP_H 00034 #define UPNP_H 00035 00036 00046 #include "ixml.h" 00047 #include "upnpconfig.h" 00048 #include "UpnpGlobal.h" 00049 #include "UpnpInet.h" 00050 00051 00052 /* 00053 * \todo Document the exact reason of these include files and solve this 00054 * include mess in an include file like UpnpTime.h 00055 */ 00056 #ifdef WIN32 00057 #include <time.h> 00058 #elif (defined(BSD) && BSD >= 199306) 00059 #include <time.h> 00060 #else 00061 /* Other systems ??? */ 00062 #endif 00063 00064 00065 #ifdef WIN32 00066 /* Do not #include <sys/param.h> */ 00067 #else 00068 #include <sys/param.h> 00069 #endif 00070 00071 00072 #ifdef WIN32 00073 #include <iphlpapi.h> 00074 #else 00075 #define SOCKET int 00076 #define INVALID_SOCKET (SOCKET)(~0) 00077 #endif 00078 00079 00080 #ifdef WIN32 00081 #define UpnpCloseSocket closesocket 00082 #define fseeko fseek 00083 #else 00084 #define UpnpCloseSocket close 00085 #endif 00086 00087 00088 #define NUM_HANDLE 200 00089 #define LINE_SIZE 180 00090 #define NAME_SIZE 256 00091 #define MNFT_NAME_SIZE 64 00092 #define MODL_NAME_SIZE 32 00093 #define SERL_NUMR_SIZE 64 00094 #define MODL_DESC_SIZE 64 00095 #define UPNP_INFINITE -1 00096 #define UPNP_USING_CHUNKED -3 00097 #define UPNP_UNTIL_CLOSE -4 00098 00099 00119 #define UPNP_E_SUCCESS 0 00120 00124 #define UPNP_E_INVALID_HANDLE -100 00125 00132 #define UPNP_E_INVALID_PARAM -101 00133 00139 #define UPNP_E_OUTOF_HANDLE -102 00140 00141 #define UPNP_E_OUTOF_CONTEXT -103 00142 00148 #define UPNP_E_OUTOF_MEMORY -104 00149 00156 #define UPNP_E_INIT -105 00157 00158 #define UPNP_E_BUFFER_TOO_SMALL -106 00159 00164 #define UPNP_E_INVALID_DESC -107 00165 00173 #define UPNP_E_INVALID_URL -108 00174 00175 #define UPNP_E_INVALID_SID -109 00176 00177 #define UPNP_E_INVALID_DEVICE -110 00178 00185 #define UPNP_E_INVALID_SERVICE -111 00186 00193 #define UPNP_E_BAD_RESPONSE -113 00194 00195 #define UPNP_E_BAD_REQUEST -114 00196 00203 #define UPNP_E_INVALID_ACTION -115 00204 00210 #define UPNP_E_FINISH -116 00211 00217 #define UPNP_E_INIT_FAILED -117 00218 00224 #define UPNP_E_URL_TOO_BIG -118 00225 00235 #define UPNP_E_BAD_HTTPMSG -119 00236 00243 #define UPNP_E_ALREADY_REGISTERED -120 00244 00249 #define UPNP_E_INVALID_INTERFACE -121 00250 00258 #define UPNP_E_NETWORK_ERROR -200 00259 00268 #define UPNP_E_SOCKET_WRITE -201 00269 00278 #define UPNP_E_SOCKET_READ -202 00279 00288 #define UPNP_E_SOCKET_BIND -203 00289 00298 #define UPNP_E_SOCKET_CONNECT -204 00299 00308 #define UPNP_E_OUTOF_SOCKET -205 00309 00316 #define UPNP_E_LISTEN -206 00317 00324 #define UPNP_E_TIMEDOUT -207 00325 00332 #define UPNP_E_SOCKET_ERROR -208 00333 00334 #define UPNP_E_FILE_WRITE_ERROR -209 00335 00340 #define UPNP_E_CANCELED -210 00341 00342 #define UPNP_E_EVENT_PROTOCOL -300 00343 00347 #define UPNP_E_SUBSCRIBE_UNACCEPTED -301 00348 00352 #define UPNP_E_UNSUBSCRIBE_UNACCEPTED -302 00353 00357 #define UPNP_E_NOTIFY_UNACCEPTED -303 00358 00365 #define UPNP_E_INVALID_ARGUMENT -501 00366 00371 #define UPNP_E_FILE_NOT_FOUND -502 00372 00376 #define UPNP_E_FILE_READ_ERROR -503 00377 00382 #define UPNP_E_EXT_NOT_XML -504 00383 00384 #define UPNP_E_NO_WEB_SERVER -505 00385 #define UPNP_E_OUTOF_BOUNDS -506 00386 00391 #define UPNP_E_NOT_FOUND -507 00392 00397 #define UPNP_E_INTERNAL_ERROR -911 00398 00399 /* SOAP-related error codes */ 00400 #define UPNP_SOAP_E_INVALID_ACTION 401 00401 #define UPNP_SOAP_E_INVALID_ARGS 402 00402 #define UPNP_SOAP_E_OUT_OF_SYNC 403 00403 #define UPNP_SOAP_E_INVALID_VAR 404 00404 #define UPNP_SOAP_E_ACTION_FAILED 501 00405 00406 /* @} ErrorCodes */ 00407 00408 #ifndef OUT 00409 #define OUT 00410 #endif 00411 00412 #ifndef IN 00413 #define IN 00414 #endif 00415 00416 #ifndef INOUT 00417 #define INOUT 00418 #endif 00419 00420 00421 /* 00422 * Opaque data structures. The following includes are data structures that 00423 * must be externally visible. Since version 1.8.0, only an opaque typedef 00424 * is visible from the outside world. Any operation on these data types 00425 * must be done using the appropriate interface functions. 00426 * 00427 * This policy has the great advantage that it is now possible to change 00428 * the internal implementation of these data structures without breaking 00429 * the API. 00430 */ 00431 #include "ActionComplete.h" 00432 #include "ActionRequest.h" 00433 #include "Discovery.h" 00434 #include "Event.h" 00435 #include "EventSubscribe.h" 00436 #include "FileInfo.h" 00437 #include "StateVarComplete.h" 00438 #include "StateVarRequest.h" 00439 #include "SubscriptionRequest.h" 00440 00441 00448 enum UpnpOpenFileMode 00449 { 00450 UPNP_READ, 00451 UPNP_WRITE 00452 }; 00453 00461 typedef int UpnpClient_Handle; 00462 00470 typedef int UpnpDevice_Handle; 00471 00479 enum Upnp_EventType_e { 00480 /* 00481 * Control callbacks 00482 */ 00483 00488 UPNP_CONTROL_ACTION_REQUEST, 00489 00493 UPNP_CONTROL_ACTION_COMPLETE, 00494 00499 UPNP_CONTROL_GET_VAR_REQUEST, 00500 00504 UPNP_CONTROL_GET_VAR_COMPLETE, 00505 00506 /* 00507 * Discovery callbacks 00508 */ 00509 00514 UPNP_DISCOVERY_ADVERTISEMENT_ALIVE, 00515 00520 UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE, 00521 00526 UPNP_DISCOVERY_SEARCH_RESULT, 00527 00531 UPNP_DISCOVERY_SEARCH_TIMEOUT, 00532 00533 /* 00534 * Eventing callbacks 00535 */ 00536 00546 UPNP_EVENT_SUBSCRIPTION_REQUEST, 00547 00551 UPNP_EVENT_RECEIVED, 00552 00556 UPNP_EVENT_RENEWAL_COMPLETE, 00557 00561 UPNP_EVENT_SUBSCRIBE_COMPLETE, 00562 00566 UPNP_EVENT_UNSUBSCRIBE_COMPLETE, 00567 00572 UPNP_EVENT_AUTORENEWAL_FAILED, 00573 00578 UPNP_EVENT_SUBSCRIPTION_EXPIRED 00579 }; 00580 00581 typedef enum Upnp_EventType_e Upnp_EventType; 00582 00590 typedef char Upnp_SID[44]; 00591 00600 enum Upnp_SType_e { 00602 UPNP_S_ALL, 00603 00605 UPNP_S_ROOT, 00606 00608 UPNP_S_DEVICE, 00609 00612 UPNP_S_SERVICE 00613 }; 00614 00615 typedef enum Upnp_SType_e Upnp_SType; 00616 00623 enum Upnp_DescType_e { 00625 UPNPREG_URL_DESC, 00626 00629 UPNPREG_FILENAME_DESC, 00630 00633 UPNPREG_BUF_DESC 00634 }; 00635 00636 typedef enum Upnp_DescType_e Upnp_DescType; 00637 00638 00664 typedef int (*Upnp_FunPtr)( 00666 Upnp_EventType EventType, 00668 void *Event, 00670 void *Cookie); 00671 00672 /* @} Constants and Types */ 00673 00674 00675 #ifdef __cplusplus 00676 extern "C" { 00677 #endif /* __cplusplus */ 00678 00679 00720 EXPORT_SPEC int UpnpInit( 00723 const char *HostIP, 00726 unsigned short DestPort); 00727 00728 00761 EXPORT_SPEC int UpnpInit2( 00765 const char *IfName, 00768 unsigned short DestPort); 00769 00770 00790 EXPORT_SPEC int UpnpFinish(void); 00791 00792 00804 EXPORT_SPEC unsigned short UpnpGetServerPort(void); 00805 00806 00818 EXPORT_SPEC unsigned short UpnpGetServerPort6(void); 00819 00831 EXPORT_SPEC const char *UpnpGetServerIpAddress(void); 00832 00833 00845 EXPORT_SPEC const char *UpnpGetServerIp6Address(void); 00846 00847 00884 EXPORT_SPEC int UpnpRegisterRootDevice( 00887 const char *DescUrl, 00889 Upnp_FunPtr Callback, 00891 const void *Cookie, 00893 UpnpDevice_Handle *Hnd); 00894 00963 EXPORT_SPEC int UpnpRegisterRootDevice2( 00965 Upnp_DescType descriptionType, 00968 const char* description, 00971 size_t bufferLen, 00974 int config_baseURL, 00976 Upnp_FunPtr Fun, 00979 const void* Cookie, 00981 UpnpDevice_Handle* Hnd); 00982 00983 01019 EXPORT_SPEC int UpnpRegisterRootDevice3( 01022 const char *DescUrl, 01024 Upnp_FunPtr Callback, 01026 const void *Cookie, 01028 UpnpDevice_Handle *Hnd, 01031 const int AddressFamily); 01032 01033 01049 EXPORT_SPEC int UpnpUnRegisterRootDevice( 01051 UpnpDevice_Handle Hnd); 01052 01053 01072 EXPORT_SPEC int UpnpRegisterClient( 01074 Upnp_FunPtr Callback, 01076 const void *Cookie, 01078 UpnpClient_Handle *Hnd); 01079 01080 01097 EXPORT_SPEC int UpnpUnRegisterClient( 01099 UpnpClient_Handle Hnd); 01100 01101 01108 EXPORT_SPEC int UpnpSetContentLength( 01111 UpnpClient_Handle Hnd, 01113 int contentLength); 01114 01115 01130 EXPORT_SPEC int UpnpSetMaxContentLength( 01133 size_t contentLength); 01134 01135 01136 /* @} Initialization and Registration */ 01137 01138 01139 /****************************************************************************** 01140 ****************************************************************************** 01141 * * 01142 * D I S C O V E R Y * 01143 * * 01144 ****************************************************************************** 01145 ******************************************************************************/ 01146 01147 01178 EXPORT_SPEC int UpnpSearchAsync( 01180 UpnpClient_Handle Hnd, 01185 int Mx, 01188 const char *TTarget_constarget_const, 01190 const void *Cookie_const); 01191 01207 EXPORT_SPEC int UpnpSendAdvertisement( 01209 UpnpDevice_Handle Hnd, 01211 int Exp); 01212 01213 01214 /* @} Discovery */ 01215 01216 01217 /****************************************************************************** 01218 ****************************************************************************** 01219 * * 01220 * C O N T R O L * 01221 * * 01222 ****************************************************************************** 01223 ******************************************************************************/ 01224 01225 01258 EXPORT_SPEC int UpnpGetServiceVarStatus( 01260 UpnpClient_Handle Hnd, 01262 const char *ActionURL, 01264 const char *VarName, 01268 DOMString *StVarVal); 01269 01270 01288 EXPORT_SPEC int UpnpGetServiceVarStatusAsync( 01290 UpnpClient_Handle Hnd, 01292 const char *ActionURL, 01294 const char *VarName, 01297 Upnp_FunPtr Fun, 01299 const void *Cookie); 01300 01301 01325 EXPORT_SPEC int UpnpSendAction( 01327 UpnpClient_Handle Hnd, 01329 const char *ActionURL, 01331 const char *ServiceType, 01333 const char *DevUDN, 01335 IXML_Document *Action, 01338 IXML_Document **RespNode); 01339 01340 01364 EXPORT_SPEC int UpnpSendActionEx( 01366 UpnpClient_Handle Hnd, 01368 const char *ActionURL, 01370 const char *ServiceType, 01372 const char *DevUDN, 01375 IXML_Document *Header, 01377 IXML_Document *Action, 01380 IXML_Document **RespNode); 01381 01382 01404 EXPORT_SPEC int UpnpSendActionAsync( 01406 UpnpClient_Handle Hnd, 01408 const char *ActionURL, 01410 const char *ServiceType, 01412 const char *DevUDN, 01414 IXML_Document *Action, 01417 Upnp_FunPtr Fun, 01420 const void *Cookie); 01421 01422 01444 EXPORT_SPEC int UpnpSendActionExAsync( 01446 UpnpClient_Handle Hnd, 01448 const char *ActionURL, 01450 const char *ServiceType, 01452 const char *DevUDN, 01455 IXML_Document *Header, 01457 IXML_Document *Action, 01460 Upnp_FunPtr Fun, 01463 const void *Cookie); 01464 01465 01469 /****************************************************************************** 01470 ****************************************************************************** 01471 * * 01472 * E V E N T I N G * 01473 * * 01474 ****************************************************************************** 01475 ******************************************************************************/ 01476 01477 01510 EXPORT_SPEC int UpnpAcceptSubscription( 01512 UpnpDevice_Handle Hnd, 01514 const char *DevID, 01516 const char *ServID, 01518 const char **VarName, 01520 const char **NewVal, 01522 int cVariables, 01524 const Upnp_SID SubsId); 01525 01526 01549 EXPORT_SPEC int UpnpAcceptSubscriptionExt( 01551 UpnpDevice_Handle Hnd, 01553 const char *DevID, 01555 const char *ServID, 01559 IXML_Document *PropSet, 01561 const Upnp_SID SubsId); 01562 01563 01585 EXPORT_SPEC int UpnpNotify( 01587 UpnpDevice_Handle, 01589 const char *DevID, 01591 const char *ServID, 01593 const char **VarName, 01595 const char **NewVal, 01597 int cVariables); 01598 01599 01621 EXPORT_SPEC int UpnpNotifyExt( 01623 UpnpDevice_Handle, 01625 const char *DevID, 01627 const char *ServID, 01631 IXML_Document *PropSet); 01632 01633 01662 EXPORT_SPEC int UpnpRenewSubscription( 01664 UpnpClient_Handle Hnd, 01667 int *TimeOut, 01669 const Upnp_SID SubsId); 01670 01671 01719 EXPORT_SPEC int UpnpRenewSubscriptionAsync( 01721 UpnpClient_Handle Hnd, 01724 int TimeOut, 01726 Upnp_SID SubsId, 01729 Upnp_FunPtr Fun, 01731 const void *Cookie); 01732 01733 01747 EXPORT_SPEC int UpnpSetMaxSubscriptions( 01750 UpnpDevice_Handle Hnd, 01752 int MaxSubscriptions); 01753 01754 01769 EXPORT_SPEC int UpnpSetMaxSubscriptionTimeOut( 01772 UpnpDevice_Handle Hnd, 01774 int MaxSubscriptionTimeOut); 01775 01776 01806 EXPORT_SPEC int UpnpSubscribe( 01808 UpnpClient_Handle Hnd, 01810 const char *PublisherUrl, 01814 int *TimeOut, 01816 Upnp_SID SubsId); 01817 01818 01867 EXPORT_SPEC int UpnpSubscribeAsync( 01869 UpnpClient_Handle Hnd, 01871 const char *PublisherUrl, 01874 int TimeOut, 01876 Upnp_FunPtr Fun, 01878 const void *Cookie); 01879 01880 01910 EXPORT_SPEC int UpnpUnSubscribe( 01912 UpnpClient_Handle Hnd, 01914 const Upnp_SID SubsId); 01915 01916 01963 EXPORT_SPEC int UpnpUnSubscribeAsync( 01965 UpnpClient_Handle Hnd, 01967 Upnp_SID SubsId, 01970 Upnp_FunPtr Fun, 01972 const void *Cookie); 01973 01974 01979 /****************************************************************************** 01980 ****************************************************************************** 01981 * * 01982 * C L I E N T - A P I * 01983 * * 01984 ****************************************************************************** 01985 ******************************************************************************/ 01986 02019 EXPORT_SPEC int UpnpDownloadUrlItem( 02021 const char *url, 02023 char **outBuf, 02026 char *contentType); 02027 02028 02057 EXPORT_SPEC int UpnpOpenHttpGet( 02059 const char *url, 02061 void **handle, 02063 char **contentType, 02065 int *contentLength, 02067 int *httpStatus, 02071 int timeout); 02072 02073 02102 EXPORT_SPEC int UpnpOpenHttpGetProxy( 02104 const char *url, 02106 const char *proxy_str, 02108 void **handle, 02110 char **contentType, 02112 int *contentLength, 02114 int *httpStatus, 02118 int timeout); 02119 02120 02151 EXPORT_SPEC int UpnpOpenHttpGetEx( 02153 const char *url, 02155 void **handle, 02157 char **contentType, 02159 int *contentLength, 02161 int *httpStatus, 02163 int lowRange, 02165 int highRange, 02169 int timeout); 02170 02171 02189 EXPORT_SPEC int UpnpReadHttpGet( 02191 void *handle, 02193 char *buf, 02195 unsigned int *size, 02199 int timeout); 02200 02201 02210 EXPORT_SPEC int UpnpHttpGetProgress( 02212 void *handle, 02214 unsigned int *length, 02216 unsigned int *total); 02217 02218 02226 EXPORT_SPEC int UpnpCancelHttpGet( 02229 void *handle); 02230 02239 EXPORT_SPEC int UpnpCloseHttpGet( 02242 void *handle); 02243 02244 02270 EXPORT_SPEC int UpnpOpenHttpPost( 02272 const char *url, 02275 void **handle, 02277 const char *contentType, 02279 int contentLength, 02282 int timeout); 02283 02284 02298 EXPORT_SPEC int UpnpWriteHttpPost( 02301 void *handle, 02303 char *buf, 02305 unsigned int *size, 02308 int timeout); 02309 02310 02324 EXPORT_SPEC int UpnpCloseHttpPost( 02327 void *handle, 02329 int *httpStatus, 02332 int timeout); 02333 02334 02362 EXPORT_SPEC int UpnpDownloadXmlDoc( 02364 const char *url, 02366 IXML_Document **xmlDoc); 02367 02368 02371 /****************************************************************************** 02372 ****************************************************************************** 02373 * * 02374 * W E B S E R V E R A P I * 02375 * * 02376 ****************************************************************************** 02377 ******************************************************************************/ 02378 02401 EXPORT_SPEC int UpnpSetWebServerRootDir( 02403 const char *rootDir); 02404 02405 02409 typedef void *UpnpWebFileHandle; 02410 02411 02415 typedef int (*VDCallback_GetInfo)( 02417 const char *filename, 02419 UpnpFileInfo *info); 02420 02421 02430 EXPORT_SPEC int UpnpVirtualDir_set_GetInfoCallback(VDCallback_GetInfo callback); 02431 02432 02436 typedef UpnpWebFileHandle (*VDCallback_Open)( 02438 const char *filename, 02441 enum UpnpOpenFileMode Mode); 02442 02443 02452 EXPORT_SPEC int UpnpVirtualDir_set_OpenCallback(VDCallback_Open callback); 02453 02454 02458 typedef int (*VDCallback_Read)( 02460 UpnpWebFileHandle fileHnd, 02462 char *buf, 02464 size_t buflen); 02465 02466 02475 EXPORT_SPEC int UpnpVirtualDir_set_ReadCallback(VDCallback_Read callback); 02476 02477 02481 typedef int (*VDCallback_Write)( 02483 UpnpWebFileHandle fileHnd, 02485 char *buf, 02487 size_t buflen); 02488 02489 02498 EXPORT_SPEC int UpnpVirtualDir_set_WriteCallback(VDCallback_Write callback); 02499 02500 02504 typedef int (*VDCallback_Seek) ( 02506 UpnpWebFileHandle fileHnd, 02510 off_t offset, 02515 int origin); 02516 02517 02526 EXPORT_SPEC int UpnpVirtualDir_set_SeekCallback(VDCallback_Seek callback); 02527 02528 02532 typedef int (*VDCallback_Close)( 02534 UpnpWebFileHandle fileHnd); 02535 02536 02545 EXPORT_SPEC int UpnpVirtualDir_set_CloseCallback(VDCallback_Close callback); 02546 02547 02555 EXPORT_SPEC int UpnpEnableWebserver( 02557 int enable); 02558 02559 02567 EXPORT_SPEC int UpnpIsWebserverEnabled(void); 02568 02569 02584 EXPORT_SPEC int UpnpAddVirtualDir( 02586 const char *dirName); 02587 02588 02596 EXPORT_SPEC int UpnpRemoveVirtualDir( 02598 const char *dirName); 02599 02600 02604 EXPORT_SPEC void UpnpRemoveAllVirtualDirs(void); 02605 02606 02607 /* @} Web Server API */ 02608 02609 02610 02611 #ifdef __cplusplus 02612 } 02613 #endif /* __cplusplus */ 02614 02615 02616 /* @} UPnPAPI UPnP API */ 02617 02618 02619 #endif /* UPNP_H */ 02620