openobex-1.7.2-Source/AUTHORS000644 001750 001750 00000000607 11612777701 016774 0ustar00hendrikhendrik000000 000000 Dag Brattli Pontus Fuchs Fons Botman Andy Choi Jean Tourrilhes Marcel Holtmann Dmitry Kasatkin Christian W. Zuckschwerdt Alex Kanavin Johan Hedberg Hendrik Sattler openobex-1.7.2-Source/CMakeModules/000755 001750 001750 00000000000 12701534273 020225 5ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/CMakeModules/FindDocbook.cmake000644 001750 001750 00000005034 11612777701 023417 0ustar00hendrikhendrik000000 000000 # - Find DocBook/XML tools # This module can be used to translate Docbook/XML files to different # output formats using XSLT files. Currently support XSLT processors # that can be used for DocBook: # xsltproc # saxon-6.5.x # xalan-2.x # # Typical usage is: # find_package(DocBook REQUIRED) # include(${DocBook_USE_FILE}) # docbook_generate(manpage my-app.xml MANPAGE_FILE_LIST) # foreach(file ${MANPAGE_FILE_LIST}) # ... # endforeach(file) # # This modules uses the following variables that must be set before # includign the USE_FILE: # DOCBOOK_XSLT_PROCESSOR - select the xslt processor to use # # The following functions are provided: # DOCBOOK_GENERATE(format inputFile output) # This function determines the output file names from the input # file, depending on the format and stores it as cmake list in # output. The currently support formats for "manpage" and "html". # # The following variables are set by this module: # DocBook_FOUND - True is DocBook processing is available # DocBook_USE_FILE - Name of the USE_FILE # DOCBOOK_XSLT_PROCESSOR - If not set, one of the available XSLT processors # find_file ( JAVA_DOCBOOK_XSL_SAXON_LIBRARY NAMES docbook-xsl-saxon_1.00.jar PATH_SUFFIXES share/java DOC "location of saxon 6.5.x DocBook XSL extension JAR file" CMAKE_FIND_ROOT_PATH_BOTH ) mark_as_advanced ( JAVA_DOCBOOK_XSL_SAXON_LIBRARY ) set ( Xslt_SAXON_EXTENSIONS "${JAVA_DOCBOOK_XSL_SAXON_LIBRARY}" ) find_package ( Xslt ) if ( Xslt_FOUND ) if ( NOT DOCBOOK_XSLT_PROCESSOR ) if ( XSLT_XSLTPROC_EXECUTABLE ) set ( DOCBOOK_XSLT_PROCESSOR "xsltproc" ) elseif ( XSLT_SAXON_COMMAND AND JAVA_DOCBOOK_XSL_SAXON_LIBRARY ) set ( DOCBOOK_XSLT_PROCESSOR "saxon" ) elseif ( XSLT_XALAN2_COMMAND ) set ( DOCBOOK_XSLT_PROCESSOR "xalan2" ) endif ( XSLT_XSLTPROC_EXECUTABLE ) endif ( NOT DOCBOOK_XSLT_PROCESSOR ) set ( DOCBOOK_XSLT_PROCESSOR "${DOCBOOK_XSLT_PROCESSOR}" CACHE STRING "Docbook XSLT processor select (xsltproc, xalan2 or saxon)" ) set ( XSLT_PROCESSOR "${DOCBOOK_XSLT_PROCESSOR}" ) if ( DOCBOOK_XSLT_PROCESSOR ) set ( Docbook_FOUND true ) set ( Docbook_USE_FILE UseDocbook ) endif ( DOCBOOK_XSLT_PROCESSOR ) endif ( Xslt_FOUND ) if ( NOT Docbook_FOUND ) if ( NOT Docbook_FIND_QUIETLY ) message ( STATUS "No supported Docbook XSLT found." ) endif ( NOT Docbook_FIND_QUIETLY ) if ( Docbook_FIND_REQUIRED ) message ( FATAL_ERROR "No supported Docbook XSLT found but it is required." ) endif ( Docbook_FIND_REQUIRED ) endif ( NOT Docbook_FOUND ) openobex-1.7.2-Source/CMakeModules/FindIrda.cmake000644 001750 001750 00000002250 11612777701 022713 0ustar00hendrikhendrik000000 000000 # - Find system default IrDA implementation # # On Linux it will use PkgConfig if present and supported, # else and on all other architectures, it looks for it on its own. # The following standard variables get defined: # Irda_FOUND: true if Irda was found # Irda_INCLUDE_DIRS: the directory that contains the include file # Irda_LIBRARIES: full path to the libraries include ( CheckCSourceCompiles ) if ( CMAKE_SYSTEM_NAME STREQUAL "Linux" ) set ( Irda_FOUND true ) elseif ( WIN32 ) CHECK_C_SOURCE_COMPILES ( "#include #include int main () { return 0; }" Irda_FOUND ) else ( CMAKE_SYSTEM_NAME STREQUAL "Linux" ) set ( ${Irda_FOUND} no ) endif ( CMAKE_SYSTEM_NAME STREQUAL "Linux" ) if ( Irda_FOUND ) set ( Irda_FOUND true ) else ( Irda_FOUND ) set ( Irda_FOUND false ) endif ( Irda_FOUND ) if ( NOT Irda_FOUND ) if ( NOT Irda_FIND_QUIETLY ) message ( STATUS "Irda not found." ) endif ( NOT Irda_FIND_QUIETLY ) if ( Irda_FIND_REQUIRED ) message ( FATAL_ERROR "Irda not found but required." ) endif ( Irda_FIND_REQUIRED ) endif ( NOT Irda_FOUND ) openobex-1.7.2-Source/CMakeModules/FindBluetooth.cmake000644 001750 001750 00000007270 11614615543 024005 0ustar00hendrikhendrik000000 000000 # - Find system default bluetooth implementation # # On Linux it will use PkgConfig if present and supported, # else and on all other architectures, it looks for it on its own. # The following standard variables get defined: # Bluetooth_FOUND: true if Bluetooth was found # Bluetooth_INCLUDE_DIRS: the directory that contains the include file # Bluetooth_LIBRARIES: full path to the libraries include ( CheckCSourceCompiles ) include ( CheckLibraryExists ) include ( CheckIncludeFile ) if ( CMAKE_SYSTEM_NAME STREQUAL "Linux" ) find_package ( PkgConfig ) if ( PKG_CONFIG_FOUND ) pkg_check_modules ( PKGCONFIG_BLUEZ bluez ) endif ( PKG_CONFIG_FOUND ) find_path ( Bluetooth_INCLUDE_DIRS NAMES bluetooth/bluetooth.h PATH_SUFFIXES include ) mark_as_advanced ( Bluetooth_INCLUDE_DIRS ) if ( PKGCONFIG_BLUEZ_FOUND ) foreach ( i ${PKGCONFIG_BLUEZ_LIBRARIES} ) find_library ( ${i}_LIBRARY NAMES ${i} PATHS ${PKGCONFIG_BLUEZ_LIBRARY_DIRS} ) mark_as_advanced ( ${i}_LIBRARY ) if ( ${i}_LIBRARY ) list ( APPEND Bluetooth_LIBRARIES ${${i}_LIBRARY} ) endif ( ${i}_LIBRARY ) endforeach ( i ) add_definitions ( -DHAVE_SDPLIB ) else ( PKGCONFIG_BLUEZ_FOUND ) find_library ( bluetooth_LIBRARY NAMES bluetooth PATH_SUFFIXES lib ) mark_as_advanced ( bluetooth_LIBRARY ) if ( bluetooth_LIBRARY ) set ( Bluetooth_LIBRARIES ${bluetooth_LIBRARY} ) endif ( bluetooth_LIBRARY ) endif ( PKGCONFIG_BLUEZ_FOUND ) if ( Bluetooth_INCLUDE_DIRS AND Bluetooth_LIBRARIES ) set ( Bluetooth_FOUND true ) endif ( Bluetooth_INCLUDE_DIRS AND Bluetooth_LIBRARIES ) elseif ( CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" ) find_path ( Bluetooth_INCLUDE_DIRS NAMES bluetooth.h PATH_SUFFIXES include ) mark_as_advanced ( Bluetooth_INCLUDE_DIRS ) find_library ( Bluetooth_LIBRARIES NAMES bluetooth PATH_SUFFIXES lib ) mark_as_advanced ( Bluetooth_LIBRARIES ) if ( Bluetooth_INCLUDE_DIRS ) set ( CMAKE_REQUIRED_INCLUDES ${Bluetooth_INCLUDE_DIRS} ) CHECK_C_SOURCE_COMPILES ( "#include int main () { struct sockaddr_rfcomm f; return 0; }" Bluetooth_FOUND ) endif ( Bluetooth_INCLUDE_DIRS ) elseif ( CMAKE_SYSTEM_NAME STREQUAL "NetBSD" ) find_path ( Bluetooth_INCLUDE_DIRS NAMES bluetooth.h PATH_SUFFIXES include ) mark_as_advanced ( Bluetooth_INCLUDE_DIRS ) find_library ( Bluetooth_LIBRARIES NAMES bluetooth PATH_SUFFIXES lib ) mark_as_advanced ( Bluetooth_LIBRARIES ) if ( Bluetooth_INCLUDE_DIRS ) set ( CMAKE_REQUIRED_INCLUDES ${Bluetooth_INCLUDE_DIRS} ) CHECK_C_SOURCE_COMPILES ( "#include int main () { struct sockaddr_bt f; return 0; }" Bluetooth_FOUND ) endif ( Bluetooth_INCLUDE_DIRS ) elseif ( WIN32 ) CHECK_C_SOURCE_COMPILES ( "#include #include int main () { SOCKADDR_BTH f; return 0; }" Bluetooth_FOUND ) endif ( CMAKE_SYSTEM_NAME STREQUAL "Linux" ) if ( Bluetooth_FOUND ) set ( Bluetooth_FOUND true ) else ( Bluetooth_FOUND ) set ( Bluetooth_FOUND false ) endif ( Bluetooth_FOUND ) if ( NOT Bluetooth_FOUND ) if ( NOT Bluetooth_FIND_QUIETLY ) message ( STATUS "Bluetooth not found." ) endif ( NOT Bluetooth_FIND_QUIETLY ) if ( Bluetooth_FIND_REQUIRED ) message ( FATAL_ERROR "Bluetooth not found but required." ) endif ( Bluetooth_FIND_REQUIRED ) endif ( NOT Bluetooth_FOUND ) openobex-1.7.2-Source/CMakeModules/MaintainerMode.cmake000644 001750 001750 00000002746 12067336456 024144 0ustar00hendrikhendrik000000 000000 option ( USE_MAINTAINER_MODE "Enable some stuff only relevant to developers" OFF ) if ( USE_MAINTAINER_MODE ) if ( CMAKE_COMPILER_IS_GNUCC ) set ( MAINTAINER_MODE_WARN_FLAGS all extra no-unused-parameter no-missing-field-initializers declaration-after-statement missing-declarations redundant-decls cast-align error ) set ( MAINTAINER_MODE_FLAGS # pedantic # std=c99 ) foreach ( flag ${MAINTAINER_MODE_WARN_FLAGS} ) list ( APPEND MAINTAINER_MODE_FLAGS "W${flag}" ) endforeach ( flag ) foreach ( flag ${MAINTAINER_MODE_FLAGS} ) set ( cflag "-${flag}" ) set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${cflag}" ) foreach ( type DEBUG RELEASE MINSIZEREL RELWITHDEBINFO ) set ( CMAKE_C_FLAGS_${type} "${CMAKE_C_FLAGS_${type}} ${cflag}" ) endforeach ( type ) endforeach ( flag ) elseif ( MSVC ) set ( MAINTAINER_MODE_FLAGS W3 WX ) foreach ( flag ${MAINTAINER_MODE_FLAGS} ) set ( cflag "/${flag}" ) set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${cflag}" ) foreach ( type DEBUG RELEASE MINSIZEREL RELWITHDEBINFO ) set ( CMAKE_C_FLAGS_${type} "${CMAKE_C_FLAGS_${type}} ${cflag}" ) endforeach ( type ) endforeach ( flag ) endif ( CMAKE_COMPILER_IS_GNUCC ) # foreach ( type DEBUG RELEASE MINSIZEREL RELWITHDEBINFO ) # message ( "CMAKE_C_FLAGS_${type} set to \"${CMAKE_C_FLAGS_${type}}\"" ) # endforeach ( type ) endif ( USE_MAINTAINER_MODE ) openobex-1.7.2-Source/CMakeModules/exportheader.cmake.in000644 001750 001750 00000001617 12110253455 024325 0ustar00hendrikhendrik000000 000000 #ifndef @INCLUDE_GUARD_NAME@ #define @INCLUDE_GUARD_NAME@ #ifdef @STATIC_DEFINE@ # define @EXPORT_MACRO_NAME@ # define @NO_EXPORT_MACRO_NAME@ #else # ifndef @EXPORT_MACRO_NAME@ # ifdef @EXPORT_IMPORT_CONDITION@ /* We are building this library */ # define @EXPORT_MACRO_NAME@ @DEFINE_EXPORT@ # else /* We are using this library */ # define @EXPORT_MACRO_NAME@ @DEFINE_IMPORT@ # endif # endif # ifndef @NO_EXPORT_MACRO_NAME@ # define @NO_EXPORT_MACRO_NAME@ @DEFINE_NO_EXPORT@ # endif #endif #ifndef @DEPRECATED_MACRO_NAME@ # define @DEPRECATED_MACRO_NAME@ @DEFINE_DEPRECATED@ # define @DEPRECATED_MACRO_NAME@_EXPORT @EXPORT_MACRO_NAME@ @DEFINE_DEPRECATED@ # define @DEPRECATED_MACRO_NAME@_NO_EXPORT @NO_EXPORT_MACRO_NAME@ @DEFINE_DEPRECATED@ #endif #cmakedefine01 DEFINE_NO_DEPRECATED #if DEFINE_NO_DEPRECATED # define @NO_DEPRECATED_MACRO_NAME@ #endif #endif openobex-1.7.2-Source/CMakeModules/GenerateExportHeader.cmake000644 001750 001750 00000034510 12604170354 025275 0ustar00hendrikhendrik000000 000000 # - Function for generation of export macros for libraries # # Copy from CMake-2.8.10.2 and adapted for C (instead of C++). # # This module provides the function GENERATE_EXPORT_HEADER() and the # accompanying ADD_COMPILER_EXPORT_FLAGS() function. # # The GENERATE_EXPORT_HEADER function can be used to generate a file suitable # for preprocessor inclusion which contains EXPORT macros to be used in # library classes. # # GENERATE_EXPORT_HEADER( LIBRARY_TARGET # [BASE_NAME ] # [EXPORT_MACRO_NAME ] # [EXPORT_FILE_NAME ] # [DEPRECATED_MACRO_NAME ] # [NO_EXPORT_MACRO_NAME ] # [STATIC_DEFINE ] # [NO_DEPRECATED_MACRO_NAME ] # [DEFINE_NO_DEPRECATED] # [PREFIX_NAME ] # ) # # ADD_COMPILER_EXPORT_FLAGS( [] ) # # By default GENERATE_EXPORT_HEADER() generates macro names in a file name # determined by the name of the library. The ADD_COMPILER_EXPORT_FLAGS function # adds -fvisibility=hidden to CMAKE_CXX_FLAGS if supported, and is a no-op on # Windows which does not need extra compiler flags for exporting support. You # may optionally pass a single argument to ADD_COMPILER_EXPORT_FLAGS that will # be populated with the required CXX_FLAGS required to enable visibility support # for the compiler/architecture in use. # # This means that in the simplest case, users of these functions will be # equivalent to: # # add_compiler_export_flags() # add_library(somelib someclass.cpp) # generate_export_header(somelib) # install(TARGETS somelib DESTINATION ${LIBRARY_INSTALL_DIR}) # install(FILES # someclass.h # ${PROJECT_BINARY_DIR}/somelib_export.h DESTINATION ${INCLUDE_INSTALL_DIR} # ) # # And in the ABI header files: # # #include "somelib_export.h" # class SOMELIB_EXPORT SomeClass { # ... # }; # # The CMake fragment will generate a file in the ${CMAKE_CURRENT_BUILD_DIR} # called somelib_export.h containing the macros SOMELIB_EXPORT, SOMELIB_NO_EXPORT, # SOMELIB_DEPRECATED, SOMELIB_DEPRECATED_EXPORT and SOMELIB_DEPRECATED_NO_EXPORT. # The resulting file should be installed with other headers in the library. # # The BASE_NAME argument can be used to override the file name and the names # used for the macros # # add_library(somelib someclass.cpp) # generate_export_header(somelib # BASE_NAME other_name # ) # # Generates a file called other_name_export.h containing the macros # OTHER_NAME_EXPORT, OTHER_NAME_NO_EXPORT and OTHER_NAME_DEPRECATED etc. # # The BASE_NAME may be overridden by specifiying other options in the function. # For example: # # add_library(somelib someclass.cpp) # generate_export_header(somelib # EXPORT_MACRO_NAME OTHER_NAME_EXPORT # ) # # creates the macro OTHER_NAME_EXPORT instead of SOMELIB_EXPORT, but other macros # and the generated file name is as default. # # add_library(somelib someclass.cpp) # generate_export_header(somelib # DEPRECATED_MACRO_NAME KDE_DEPRECATED # ) # # creates the macro KDE_DEPRECATED instead of SOMELIB_DEPRECATED. # # If LIBRARY_TARGET is a static library, macros are defined without values. # # If the same sources are used to create both a shared and a static library, the # uppercased symbol ${BASE_NAME}_STATIC_DEFINE should be used when building the # static library # # add_library(shared_variant SHARED ${lib_SRCS}) # add_library(static_variant ${lib_SRCS}) # generate_export_header(shared_variant BASE_NAME libshared_and_static) # set_target_properties(static_variant PROPERTIES # COMPILE_FLAGS -DLIBSHARED_AND_STATIC_STATIC_DEFINE) # # This will cause the export macros to expand to nothing when building the # static library. # # If DEFINE_NO_DEPRECATED is specified, then a macro ${BASE_NAME}_NO_DEPRECATED # will be defined # This macro can be used to remove deprecated code from preprocessor output. # # option(EXCLUDE_DEPRECATED "Exclude deprecated parts of the library" FALSE) # if (EXCLUDE_DEPRECATED) # set(NO_BUILD_DEPRECATED DEFINE_NO_DEPRECATED) # endif() # generate_export_header(somelib ${NO_BUILD_DEPRECATED}) # # And then in somelib: # # class SOMELIB_EXPORT SomeClass # { # public: # #ifndef SOMELIB_NO_DEPRECATED # SOMELIB_DEPRECATED void oldMethod(); # #endif # }; # # #ifndef SOMELIB_NO_DEPRECATED # void SomeClass::oldMethod() { } # #endif # # If PREFIX_NAME is specified, the argument will be used as a prefix to all # generated macros. # # For example: # # generate_export_header(somelib PREFIX_NAME VTK_) # # Generates the macros VTK_SOMELIB_EXPORT etc. #============================================================================= # Copyright 2011 Stephen Kelly # Copyright 2013 Hendrik Sattler # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # * The names of Kitware, Inc., the Insight Consortium, or the names of # any consortium members, or of any contributors, may not be used to # endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #============================================================================= include(CMakeParseArguments) include(CheckCXXCompilerFlag) include(CheckCCompilerFlag) macro(_check_cxx_compiler_attribute _ATTRIBUTE _RESULT) check_cxx_source_compiles("${_ATTRIBUTE} int somefunc() { return 0; } int main() { return somefunc();}" ${_RESULT} ) endmacro() macro(_check_c_compiler_attribute _ATTRIBUTE _RESULT) check_c_source_compiles("${_ATTRIBUTE} int somefunc() { return 0; } int main() { return somefunc();}" ${_RESULT} ) endmacro() macro(_test_compiler_hidden_visibility lang) if(CMAKE_COMPILER_IS_GNU${lang} AND CMAKE_${lang}_COMPILER_VERSION VERSION_LESS "4.2") set(GCC_TOO_OLD TRUE) message(WARNING "GCC version older than 4.2") elseif(CMAKE_${lang}_COMPILER_ID MATCHES Intel AND CMAKE_${lang}_COMPILER_VERSION VERSION_LESS "12.0") set(_INTEL_TOO_OLD TRUE) message(WARNING "Intel compiler older than 12.0") endif() # Exclude XL here because it misinterprets -fvisibility=hidden even though # the check_cxx_compiler_flag passes # http://www.cdash.org/CDash/testDetails.php?test=109109951&build=1419259 if(NOT GCC_TOO_OLD AND NOT _INTEL_TOO_OLD AND NOT WIN32 AND NOT CYGWIN AND NOT "${CMAKE_${lang}_COMPILER_ID}" MATCHES XL AND NOT "${CMAKE_${lang}_COMPILER_ID}" MATCHES PGI AND NOT "${CMAKE_${lang}_COMPILER_ID}" MATCHES Watcom) option(USE_COMPILER_HIDDEN_VISIBILITY "Use HIDDEN visibility support if available." ON) mark_as_advanced(USE_COMPILER_HIDDEN_VISIBILITY) if(USE_COMPILER_HIDDEN_VISIBILITY) if(lang MATCHES "^CXX$") check_cxx_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY) check_cxx_compiler_flag(-fvisibility-inlines-hidden COMPILER_HAS_HIDDEN_INLINE_VISIBILITY) elseif(lang MATCHES "^C$") check_c_compiler_flag(-fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY) endif() endif(USE_COMPILER_HIDDEN_VISIBILITY) endif() endmacro() macro(_test_compiler_has_deprecated lang) if("${CMAKE_CXX_COMPILER_ID}" MATCHES Borland OR "${CMAKE_CXX_COMPILER_ID}" MATCHES HP OR GCC_TOO_OLD OR "${CMAKE_CXX_COMPILER_ID}" MATCHES PGI OR "${CMAKE_CXX_COMPILER_ID}" MATCHES Watcom) set(COMPILER_HAS_DEPRECATED "" CACHE INTERNAL "Compiler support for a deprecated attribute") else() if(lang MATCHES "^CXX$") _check_cxx_compiler_attribute("__attribute__((__deprecated__))" COMPILER_HAS_DEPRECATED_ATTR) elseif(lang MATCHES "^C$") _check_c_compiler_attribute("__attribute__((__deprecated__))" COMPILER_HAS_DEPRECATED_ATTR) endif() if(COMPILER_HAS_DEPRECATED_ATTR) set(COMPILER_HAS_DEPRECATED "${COMPILER_HAS_DEPRECATED_ATTR}" CACHE INTERNAL "Compiler support for a deprecated attribute") else() if("${lang}" MATCHES "^CXX$") _check_cxx_compiler_attribute("__declspec(deprecated)" COMPILER_HAS_DEPRECATED) elseif("${lang}" MATCHES "^C$") _check_c_compiler_attribute("__declspec(deprecated)" COMPILER_HAS_DEPRECATED) endif() endif() endif() endmacro() get_filename_component(_GENERATE_EXPORT_HEADER_MODULE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) macro(_DO_SET_MACRO_VALUES TARGET_LIBRARY) set(DEFINE_DEPRECATED) set(DEFINE_EXPORT) set(DEFINE_IMPORT) set(DEFINE_NO_EXPORT) if (COMPILER_HAS_DEPRECATED_ATTR) set(DEFINE_DEPRECATED "__attribute__ ((__deprecated__))") elseif(COMPILER_HAS_DEPRECATED) set(DEFINE_DEPRECATED "__declspec(deprecated)") endif() get_property(type TARGET ${TARGET_LIBRARY} PROPERTY TYPE) if(NOT ${type} STREQUAL "STATIC_LIBRARY") if(WIN32) set(DEFINE_EXPORT "__declspec(dllexport)") set(DEFINE_IMPORT "__declspec(dllimport)") elseif(COMPILER_HAS_HIDDEN_VISIBILITY AND USE_COMPILER_HIDDEN_VISIBILITY) set(DEFINE_EXPORT "__attribute__((visibility(\"default\")))") set(DEFINE_IMPORT "__attribute__((visibility(\"default\")))") set(DEFINE_NO_EXPORT "__attribute__((visibility(\"hidden\")))") endif() endif() endmacro() macro(_DO_GENERATE_EXPORT_HEADER TARGET_LIBRARY) # Option overrides set(options DEFINE_NO_DEPRECATED) set(oneValueArgs PREFIX_NAME BASE_NAME EXPORT_MACRO_NAME EXPORT_FILE_NAME DEPRECATED_MACRO_NAME NO_EXPORT_MACRO_NAME STATIC_DEFINE NO_DEPRECATED_MACRO_NAME) set(multiValueArgs) cmake_parse_arguments(_GEH "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) set(BASE_NAME "${TARGET_LIBRARY}") if(_GEH_BASE_NAME) set(BASE_NAME ${_GEH_BASE_NAME}) endif() string(TOUPPER ${BASE_NAME} BASE_NAME_UPPER) string(TOLOWER ${BASE_NAME} BASE_NAME_LOWER) # Default options set(EXPORT_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_EXPORT") set(NO_EXPORT_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_NO_EXPORT") set(EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${BASE_NAME_LOWER}_export.h") set(DEPRECATED_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_DEPRECATED") set(STATIC_DEFINE "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_STATIC_DEFINE") set(NO_DEPRECATED_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_NO_DEPRECATED") if(_GEH_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unknown keywords given to GENERATE_EXPORT_HEADER(): \"${_GEH_UNPARSED_ARGUMENTS}\"") endif() if(_GEH_EXPORT_MACRO_NAME) set(EXPORT_MACRO_NAME ${_GEH_PREFIX_NAME}${_GEH_EXPORT_MACRO_NAME}) endif() if(_GEH_EXPORT_FILE_NAME) if(IS_ABSOLUTE ${_GEH_EXPORT_FILE_NAME}) set(EXPORT_FILE_NAME ${_GEH_EXPORT_FILE_NAME}) else() set(EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${_GEH_EXPORT_FILE_NAME}") endif() endif() if(_GEH_DEPRECATED_MACRO_NAME) set(DEPRECATED_MACRO_NAME ${_GEH_PREFIX_NAME}${_GEH_DEPRECATED_MACRO_NAME}) endif() if(_GEH_NO_EXPORT_MACRO_NAME) set(NO_EXPORT_MACRO_NAME ${_GEH_PREFIX_NAME}${_GEH_NO_EXPORT_MACRO_NAME}) endif() if(_GEH_STATIC_DEFINE) set(STATIC_DEFINE ${_GEH_PREFIX_NAME}${_GEH_STATIC_DEFINE}) endif() if(_GEH_DEFINE_NO_DEPRECATED) set(DEFINE_NO_DEPRECATED TRUE) endif() if(_GEH_NO_DEPRECATED_MACRO_NAME) set(NO_DEPRECATED_MACRO_NAME ${_GEH_PREFIX_NAME}${_GEH_NO_DEPRECATED_MACRO_NAME}) endif() set(INCLUDE_GUARD_NAME "${EXPORT_MACRO_NAME}_H") get_target_property(EXPORT_IMPORT_CONDITION ${TARGET_LIBRARY} DEFINE_SYMBOL) if(NOT EXPORT_IMPORT_CONDITION) set(EXPORT_IMPORT_CONDITION ${TARGET_LIBRARY}_EXPORTS) endif() configure_file("${_GENERATE_EXPORT_HEADER_MODULE_DIR}/exportheader.cmake.in" "${EXPORT_FILE_NAME}" @ONLY) endmacro() function(GENERATE_EXPORT_HEADER TARGET_LIBRARY) get_property(type TARGET ${TARGET_LIBRARY} PROPERTY TYPE) if(${type} STREQUAL "MODULE") message(WARNING "This macro should not be used with libraries of type MODULE") return() endif() if(NOT ${type} STREQUAL "STATIC_LIBRARY" AND NOT ${type} STREQUAL "SHARED_LIBRARY") message(WARNING "This macro can only be used with libraries") return() endif() if(DEFINED CMAKE_CXX_COMPILER) _test_compiler_hidden_visibility(CXX) _test_compiler_has_deprecated(CXX) elseif(DEFINED CMAKE_C_COMPILER) _test_compiler_hidden_visibility(C) _test_compiler_has_deprecated(C) else() message ( FATAL_ERROR "No supported language enabled." ) endif() _do_set_macro_values(${TARGET_LIBRARY}) _do_generate_export_header(${TARGET_LIBRARY} ${ARGN}) endfunction() function(add_compiler_export_flags lang) _test_compiler_hidden_visibility(lang) _test_compiler_has_deprecated(lang) if(NOT (USE_COMPILER_HIDDEN_VISIBILITY AND COMPILER_HAS_HIDDEN_VISIBILITY)) # Just return if there are no flags to add. return() endif() set (EXTRA_FLAGS "-fvisibility=hidden") if(lang STREQUAL "CXX" AND COMPILER_HAS_HIDDEN_INLINE_VISIBILITY) set (EXTRA_FLAGS "${EXTRA_FLAGS} -fvisibility-inlines-hidden") endif() # Either return the extra flags needed in the supplied argument, or to the # CMAKE_CXX_FLAGS if no argument is supplied. if(ARGV1) set(${ARGV1} "${EXTRA_FLAGS}" PARENT_SCOPE) else() set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} ${EXTRA_FLAGS}" PARENT_SCOPE) endif() endfunction() openobex-1.7.2-Source/CMakeModules/FindXslt.cmake000644 001750 001750 00000015702 12114736755 022776 0ustar00hendrikhendrik000000 000000 # - Find XSLT processors. # This module provides easy integration of XSLT processors. # Currently xsltproc, Saxon 6.5.[345] and Xalan 2.x are supported. # # Typical usage is: # find_package(Xslt) # include_file(${Xslt_USE_FILE}) # # # The following variables are created: # Xslt_FOUND - true if at least one XSLT processor is found # Xslt_USE_FILE - name of the USE_FILE # Xslt_CLASSPATH - the Java classpath to use for XSLT processing # XSLT_XSLTPROC_EXECUTABLE - executable for xltproc # XSLT_SAXON_COMMAND - command for saxon-6.5.x # XSLT_XALAN2_COMMAND - command for xalan-2.x # # The following environment variables are considered: # CLASSPATH - initial value of Xslt_CLASSPATH (if empty) # # The following functions are provided: # xsl_transform(xsl-file xml-file ...) # This uses the xsl file to transform the xml file input to one or # more output files. Several variables can be used to change the # behaviour of the transformation: # XSLT_PARAMS: cmake list of parameters for the XSL transformation # in the form of param=value # XSLT__OPTIONS: extra option for each of XSLTPROC, # SAXON and XALAN2. find_package ( Java ) if ( JAVA_RUNTIME ) if ( NOT Xslt_CLASSPATH ) set ( Xslt_CLASSPATH $ENV{CLASSPATH} CACHE STRING "java classpath" ) endif ( NOT Xslt_CLASSPATH ) if ( NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" ) # Non-Windows classpath may use : instead of ; # so make this a cmake list here by always using ; string ( REPLACE ":" ";" Xslt_CLASSPATH "${Xslt_CLASSPATH}" ) endif ( NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" ) mark_as_advanced ( Xslt_CLASSPATH ) find_file ( JAVA_RESOLVER_LIBRARY NAMES resolver.jar xml-commons-resolver-1.1.jar PATH_SUFFIXES share/java DOC "location of the XML commons resolver java library from the apache project" CMAKE_FIND_ROOT_PATH_BOTH ) mark_as_advanced ( JAVA_RESOLVER_LIBRARY ) if ( JAVA_RESOLVER_LIBRARY ) list ( APPEND Xslt_CLASSPATH "${JAVA_RESOLVER_LIBRARY}" ) endif ( JAVA_RESOLVER_LIBRARY ) find_path ( JAVA_PROPERTIES_CATALOGMANAGER NAMES CatalogManager.properties PATHS /etc PATH_SUFFIXES xml/resolver share/java share/xml DOC "location of the catalog manager properties file from the XML commons resolver" CMAKE_FIND_ROOT_PATH_BOTH ) mark_as_advanced ( JAVA_PROPERTIES_CATALOGMANAGER ) if ( JAVA_PROPERTIES_CATALOGMANAGER ) list ( APPEND Xslt_CLASSPATH "${JAVA_PROPERTIES_CATALOGMANAGER}" ) endif ( JAVA_PROPERTIES_CATALOGMANAGER ) find_file ( JAVA_XERCES_IMPL_LIBRARY NAMES xercesImpl.jar PATH_SUFFIXES share/java DOC "location of Xalan2 Xerces Implementation JAR file" CMAKE_FIND_ROOT_PATH_BOTH ) mark_as_advanced ( JAVA_XERCES_IMPL_LIBRARY ) # # Find Xalan 2 # find_file ( XALAN2 NAMES xalan2.jar PATH_SUFFIXES share/java DOC "location of Xalan2 JAR file" CMAKE_FIND_ROOT_PATH_BOTH ) mark_as_advanced ( XALAN2 ) find_file ( JAVA_XML_APIS_LIBRARY NAMES xml-apis.jar PATH_SUFFIXES share/java DOC "location of Xalan2 XML-API JAR file" CMAKE_FIND_ROOT_PATH_BOTH ) mark_as_advanced ( JAVA_XML_APIS_LIBRARY ) if ( XALAN2 AND JAVA_XML_APIS_LIBRARY ) set ( XSLT_XALAN2_COMMAND org.apache.xalan.xslt.Process ) set ( Xslt_XALAN2_CLASSPATH ${Xslt_CLASSPATH} "${XALAN2}" "${JAVA_XML_APIS_LIBRARY}" ) if ( Xslt_XALAN2_EXTENSIONS ) list ( APPEND Xslt_XALAN2_CLASSPATH "${Xslt_XALAN2_EXTENSIONS}" ) endif ( Xslt_XALAN2_EXTENSIONS ) if ( JAVA_XERCES_IMPL_LIBRARY ) set ( XSLT_JAVA_OPTIONS -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl -Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration ) list ( APPEND Xslt_XALAN2_CLASSPATH "${JAVA_XERCES_IMPL_LIBRARY}" ) endif ( JAVA_XERCES_IMPL_LIBRARY ) if ( JAVA_RESOLVER_LIBRARY AND JAVA_PROPERTIES_CATALOGMANAGER ) list ( APPEND XSLT_XALAN2_OPTIONS -ENTITYRESOLVER org.apache.xml.resolver.tools.CatalogResolver -URIRESOLVER org.apache.xml.resolver.tools.CatalogResolver ) endif ( JAVA_RESOLVER_LIBRARY AND JAVA_PROPERTIES_CATALOGMANAGER ) if ( NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" ) string ( REPLACE ";" ":" Xslt_XALAN2_CLASSPATH "${Xslt_XALAN2_CLASSPATH}" ) endif ( NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" ) endif ( XALAN2 AND JAVA_XML_APIS_LIBRARY ) # # Find Saxon 6.5.x # find_file ( SAXON NAMES saxon.jar saxon-6.5.5.jar saxon-6.5.4.jar saxon-6.5.3.jar PATH_SUFFIXES share/java DOC "location of saxon 6.5.x JAR file" CMAKE_FIND_ROOT_PATH_BOTH ) mark_as_advanced ( SAXON ) if ( SAXON ) set ( XSLT_SAXON_COMMAND com.icl.saxon.StyleSheet ) set ( Xslt_SAXON_CLASSPATH ${Xslt_CLASSPATH} "${SAXON}" ) if ( Xslt_SAXON_EXTENSIONS ) list ( APPEND Xslt_SAXON_CLASSPATH "${Xslt_SAXON_EXTENSIONS}" ) endif ( Xslt_SAXON_EXTENSIONS ) if ( JAVA_XERCES_IMPL_LIBRARY ) set ( XSLT_JAVA_OPTIONS -Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl -Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl -Dorg.apache.xerces.xni.parser.XMLParserConfiguration=org.apache.xerces.parsers.XIncludeParserConfiguration ) list ( APPEND Xslt_SAXON_CLASSPATH "${JAVA_XERCES_IMPL_LIBRARY}" ) endif ( JAVA_XERCES_IMPL_LIBRARY ) if ( JAVA_RESOLVER_LIBRARY ) list ( APPEND XSLT_SAXON_OPTIONS -x org.apache.xml.resolver.tools.ResolvingXMLReader -y org.apache.xml.resolver.tools.ResolvingXMLReader -u ) if ( JAVA_PROPERTIES_CATALOGMANAGER ) list ( APPEND XSLT_SAXON_OPTIONS -r org.apache.xml.resolver.tools.CatalogResolver ) endif ( JAVA_PROPERTIES_CATALOGMANAGER ) endif ( JAVA_RESOLVER_LIBRARY ) if ( NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" ) string ( REPLACE ";" ":" Xslt_SAXON_CLASSPATH "${Xslt_SAXON_CLASSPATH}" ) endif ( NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" ) endif ( SAXON ) endif ( JAVA_RUNTIME ) find_program ( XSLT_XSLTPROC_EXECUTABLE NAMES xsltproc DOC "path to the libxslt XSLT processor xsltproc" ) mark_as_advanced ( XSLT_XSLTPROC_EXECUTABLE ) set ( XSLT_XSLTPROC_OPTIONS --xinclude ) set ( Xslt_USE_FILE UseXslt ) if ( XSLT_XSLTPROC_EXECUTABLE OR XSLT_SAXON_COMMAND OR XSLT_XALAN2_COMMAND ) set ( Xslt_FOUND true ) endif ( XSLT_XSLTPROC_EXECUTABLE OR XSLT_SAXON_COMMAND OR XSLT_XALAN2_COMMAND ) if ( NOT Xslt_FOUND ) if ( NOT Xslt_FIND_QUIETLY ) message ( STATUS "No supported XSLT processor found. Supported XSLT processors are: xsltproc, saxon-6.5.x, xalan-2.x" ) endif ( NOT Xslt_FIND_QUIETLY ) if ( Xslt_FIND_REQUIRED ) message ( FATAL_ERROR "No supported XSLT processor found but it is required." ) endif ( Xslt_FIND_REQUIRED ) endif ( NOT Xslt_FOUND ) openobex-1.7.2-Source/CMakeModules/UseDocbook.cmake000644 001750 001750 00000010500 12114736755 023267 0ustar00hendrikhendrik000000 000000 include ( ${Xslt_USE_FILE} ) if ( NOT DOCBOOK_XSL_VERSION ) set ( DOCBOOK_XSL_VERSION current ) endif ( NOT DOCBOOK_XSL_VERSION ) set ( DOCBOOK_XSL_PREFIX "http://docbook.sourceforge.net/release/xsl/${DOCBOOK_XSL_VERSION}" CACHE STRING "prefix to locate the docbook-XSL release files" ) mark_as_advanced ( DOCBOOK_XSL_PREFIX ) function ( _DOCBOOK_GET_HTML_FILES inFile outFileList ) find_program ( XMLLINT_EXECUTABLE xmllint ) if ( NOT XMLLINT_EXECUTABLE ) message ( FATAL_ERROR "Cannot find xmllint program (needed to resolve XIncludes)" ) endif ( NOT XMLLINT_EXECUTABLE ) execute_process ( COMMAND "${XMLLINT_EXECUTABLE}" ${XMLLINT_OPTIONS} --xinclude "${inFile}" OUTPUT_VARIABLE XML_FILE_CONTENTS ) # This assumes that every refentry has an unique id attribute string ( REPLACE ";" "" XML_FILE_CONTENTS "${XML_FILE_CONTENTS}" ) string ( REGEX MATCHALL "]*" XML_REFENTRYTITLE "${XML_FILE_CONTENTS}" ) foreach ( id ${XML_REFENTRYTITLE} ) string ( REGEX REPLACE ".*id=\"([^\"]*)\".*" "\\1" id "${id}" ) if ( "${id}" STREQUAL "" ) message ( FATAL_ERROR "At least one refentry in file ${infile} has no or an empty id attribute." ) endif ( "${id}" STREQUAL "" ) list ( APPEND FILES ${id}.html ) endforeach ( id ) string ( REGEX MATCH "]*" XML_ENTRY_ELEMENT "${XML_FILE_CONTENTS}" ) string ( REGEX REPLACE "" ENTRIES "${XML_FILE_CONTENTS}" ) string ( REPLACE "" ";" ENTRIES "${ENTRIES}" ) list ( REMOVE_ITEM ENTRIES "" ) list ( LENGTH ENTRIES COUNT ) math ( EXPR COUNT "${COUNT} - 1" ) foreach ( index RANGE ${COUNT} ) list ( GET ENTRIES ${index} entry ) string ( REGEX MATCH "[^<]*" MANPAGE_NAME "${entry}" ) string ( REGEX REPLACE "^" "" MANPAGE_NAME "${MANPAGE_NAME}" ) string ( REGEX REPLACE "[[:space:]]" "" MANPAGE_NAME "${MANPAGE_NAME}" ) if ( "${MANPAGE_NAME}" STREQUAL "" ) message ( FATAL_ERROR "At least one refentry in file ${infile} has no or an empty refname element." ) endif ( "${MANPAGE_NAME}" STREQUAL "" ) string ( REGEX MATCH "[^<]*" MANPAGE_VOLUME "${entry}" ) string ( REGEX REPLACE "^" "" MANPAGE_VOLUME "${MANPAGE_VOLUME}" ) string ( REGEX REPLACE "[[:space:]]" "" MANPAGE_VOLUME "${MANPAGE_VOLUME}" ) if ( "${MANPAGE_VOLUME}" STREQUAL "" ) message ( FATAL_ERROR "At least one refentry in file ${infile} has no or an empty manvolnum element." ) endif ( "${MANPAGE_VOLUME}" STREQUAL "" ) list ( APPEND FILES "${MANPAGE_NAME}.${MANPAGE_VOLUME}" ) endforeach ( index ) set ( ${outFileList} ${FILES} PARENT_SCOPE ) endfunction ( ) function ( _DOCBOOK_MANPAGE inFile outList ) _docbook_get_manpage_files ( "${inFile}" FILES ) xsl_transform ( "${DOCBOOK_XSL_PREFIX}/manpages/docbook.xsl" "${inFile}" ${FILES} ) set ( ${outList} ${FILES} PARENT_SCOPE ) endfunction ( ) function ( _DOCBOOK_HTML inFile outList ) _docbook_get_html_files ( "${inFile}" FILES ) list ( APPEND XSLT_PARAMS "use.id.as.filename=1" ) xsl_transform ( "${DOCBOOK_XSL_PREFIX}/xhtml/chunk.xsl" "${inFile}" ${FILES} ) set ( ${outList} ${FILES} PARENT_SCOPE ) endfunction ( ) function ( DOCBOOK_GENERATE format inFile outList ) if ( format STREQUAL "manpage" ) _docbook_manpage ( "${inFile}" ${outList} ) elseif ( format STREQUAL "html" ) _docbook_html ( "${inFile}" ${outList} ) else ( ) message ( FATAL_ERROR "Unsupported docbook output format." ) endif ( ) set ( ${outList} ${${outList}} PARENT_SCOPE ) endfunction ( ) openobex-1.7.2-Source/CMakeModules/UseXslt.cmake000644 001750 001750 00000005620 12114736755 022650 0ustar00hendrikhendrik000000 000000 # # call as XSLT_TRANSFORM(<.xsl file URL> ) # # The following variables are supported: # XSLT_PROCESSOR (mandatory): # select the xslt processor to use (xsltproc, xalan2, saxon) # XSLT_PARAMS (optional): # a list which may contain param=value entries. # XSLT_(XSLTPROC|XALAN2|SAXON)_OPTIONS (optional): # a list with extra options for those xslt processors. # function ( XSL_TRANSFORM xslurl infile ) if ( XSLT_PARAMS ) foreach ( param ${XSLT_PARAMS} ) set ( param_name ) string ( REGEX MATCH "[^=]+" param_name "${param}" ) if ( param_name ) set ( param_value ) string ( REGEX REPLACE "[^=]+=(.*)" "\\1" param_value "${param}" ) set ( XSLT_XSLTPROC_OPTIONS ${XSLT_XSLTPROC_OPTIONS} --param ${param_name} ${param_value} ) set ( XSLT_XALAN2_OPTIONS ${XSLT_XALAN2_OPTIONS} -param ${param_name} ${param_value} ) endif ( param_name ) endforeach ( param ) endif ( XSLT_PARAMS ) if ( XSLT_PROCESSOR STREQUAL "xsltproc" ) if ( XSLT_XSLTPROC_EXECUTABLE ) add_custom_command ( OUTPUT ${ARGN} COMMAND ${XSLT_XSLTPROC_EXECUTABLE} ${XSLT_XSLTPROC_OPTIONS} "${xslurl}" "${infile}" DEPENDS "${infile}" VERBATIM ) else ( XSLT_XSLTPROC_EXECUTABLE ) message ( FATAL_ERROR "xsltproc not found" ) endif ( XSLT_XSLTPROC_EXECUTABLE ) elseif ( XSLT_PROCESSOR STREQUAL "saxon" ) if ( XSLT_SAXON_COMMAND ) add_custom_command ( OUTPUT ${ARGN} COMMAND "${JAVA_RUNTIME}" ${XSLT_JAVA_OPTIONS} -cp "${Xslt_SAXON_CLASSPATH}" ${XSLT_SAXON_COMMAND} ${XSLT_SAXON_OPTIONS} "${infile}" "${xslurl}" ${Xslt_PARAMS} DEPENDS "${infile}" VERBATIM ) else ( XSLT_SAXON_COMMAND ) message ( FATAL_ERROR "Saxon-6.5.x not found" ) endif ( XSLT_SAXON_COMMAND ) elseif ( XSLT_PROCESSOR STREQUAL "xalan2" ) get_filename_component ( infile_name "${infile}" NAME ) if ( NOT infile STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/${infile_name}" ) # Xalan places the output in the source file's directory :-( add_custom_command ( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${infile_name} COMMAND ${CMAKE_COMMAND} -E copy_if_different "${infile}" "${CMAKE_CURRENT_BINARY_DIR}/${infile_name}" DEPENDS ${infile} VERBATIM ) set ( infile "${CMAKE_CURRENT_BINARY_DIR}/${infile_name}" ) endif ( NOT infile STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/${infile_name}" ) if ( XSLT_XALAN2_COMMAND ) add_custom_command ( OUTPUT ${ARGN} COMMAND "${JAVA_RUNTIME}" ${XSLT_JAVA_OPTIONS} -cp "${Xslt_XALAN2_CLASSPATH}" ${XSLT_XALAN2_COMMAND} ${XSLT_XALAN2_OPTIONS} -in "${infile}" -xsl "${xslurl}" DEPENDS "${infile}" VERBATIM ) else ( XSLT_XALAN2_COMMAND ) message ( FATAL_ERROR " Xalan 2.x not found" ) endif ( XSLT_XALAN2_COMMAND ) else ( XSLT_PROCESSOR STREQUAL "xsltproc" ) message ( FATAL_ERROR "Unsupported XSLT processor" ) endif ( XSLT_PROCESSOR STREQUAL "xsltproc" ) endfunction ( XSL_TRANSFORM ) openobex-1.7.2-Source/CMakeModules/FindLibUSB.cmake000644 001750 001750 00000007016 12374625554 023125 0ustar00hendrikhendrik000000 000000 # - Find libusb for portable USB support # This module will find libusb as published by # http://libusb.sf.net and # http://libusb-win32.sf.net # # It will use PkgConfig if present and supported, else search # it on its own. If the LibUSB_ROOT_DIR environment variable # is defined, it will be used as base path. # The following standard variables get defined: # LibUSB_FOUND: true if LibUSB was found # LibUSB_HEADER_FILE: the location of the C header file # LibUSB_INCLUDE_DIRS: the directory that contains the include file # LibUSB_LIBRARIES: the library include ( CheckLibraryExists ) include ( CheckIncludeFile ) find_package ( PkgConfig ) if ( PKG_CONFIG_FOUND ) pkg_check_modules ( PKGCONFIG_LIBUSB libusb-1.0 ) if ( NOT PKGCONFIG_LIBUSB_FOUND ) pkg_check_modules ( PKGCONFIG_LIBUSB libusb ) endif ( NOT PKGCONFIG_LIBUSB_FOUND ) endif ( PKG_CONFIG_FOUND ) if ( PKGCONFIG_LIBUSB_FOUND ) set ( LibUSB_INCLUDE_DIRS ${PKGCONFIG_LIBUSB_INCLUDE_DIRS} ) foreach ( i ${PKGCONFIG_LIBUSB_LIBRARIES} ) string ( REGEX MATCH "[^-]*" ibase "${i}" ) find_library ( ${ibase}_LIBRARY NAMES ${i} PATHS ${PKGCONFIG_LIBUSB_LIBRARY_DIRS} ) if ( ${ibase}_LIBRARY ) list ( APPEND LibUSB_LIBRARIES ${${ibase}_LIBRARY} ) endif ( ${ibase}_LIBRARY ) mark_as_advanced ( ${ibase}_LIBRARY ) endforeach ( i ) set ( LibUSB_FOUND true ) else ( PKGCONFIG_LIBUSB_FOUND ) find_file ( LibUSB_HEADER_FILE NAMES libusb.h usb.h PATHS $ENV{ProgramFiles}/LibUSB-Win32 $ENV{LibUSB_ROOT_DIR} PATH_SUFFIXES include ) mark_as_advanced ( LibUSB_HEADER_FILE ) get_filename_component ( LibUSB_INCLUDE_DIRS "${LibUSB_HEADER_FILE}" PATH ) if ( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" ) # LibUSB-Win32 binary distribution contains several libs. # Use the lib that got compiled with the same compiler. if ( MSVC ) if ( WIN32 ) set ( LibUSB_LIBRARY_PATH_SUFFIX lib/msvc ) else ( WIN32 ) set ( LibUSB_LIBRARY_PATH_SUFFIX lib/msvc_x64 ) endif ( WIN32 ) elseif ( BORLAND ) set ( LibUSB_LIBRARY_PATH_SUFFIX lib/bcc ) elseif ( CMAKE_COMPILER_IS_GNUCC ) set ( LibUSB_LIBRARY_PATH_SUFFIX lib/gcc ) endif ( MSVC ) endif ( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" ) find_library ( usb_LIBRARY NAMES usb-1.0 libusb usb PATHS $ENV{ProgramFiles}/LibUSB-Win32 $ENV{LibUSB_ROOT_DIR} PATH_SUFFIXES ${LibUSB_LIBRARY_PATH_SUFFIX} ) mark_as_advanced ( usb_LIBRARY ) if ( usb_LIBRARY ) set ( LibUSB_LIBRARIES ${usb_LIBRARY} ) endif ( usb_LIBRARY ) if ( LibUSB_INCLUDE_DIRS AND LibUSB_LIBRARIES ) set ( LibUSB_FOUND true ) endif ( LibUSB_INCLUDE_DIRS AND LibUSB_LIBRARIES ) if ( LibUSB_FOUND ) set ( CMAKE_REQUIRED_INCLUDES "${LibUSB_INCLUDE_DIRS}" ) check_include_file ( "{LibUSB_HEADER_FILE}" LibUSB_FOUND ) endif ( LibUSB_FOUND ) endif ( PKGCONFIG_LIBUSB_FOUND ) if ( LibUSB_FOUND ) check_library_exists ( "${usb_LIBRARY}" usb_open "" LibUSB_FOUND ) check_library_exists ( "${usb_LIBRARY}" libusb_get_device_list "" LibUSB_VERSION_1.0 ) endif ( LibUSB_FOUND ) if ( NOT LibUSB_FOUND ) if ( NOT LibUSB_FIND_QUIETLY ) message ( STATUS "LibUSB not found, try setting LibUSB_ROOT_DIR environment variable." ) endif ( NOT LibUSB_FIND_QUIETLY ) if ( LibUSB_FIND_REQUIRED ) message ( FATAL_ERROR "" ) endif ( LibUSB_FIND_REQUIRED ) endif ( NOT LibUSB_FOUND ) openobex-1.7.2-Source/COPYING000644 001750 001750 00000043133 11612777701 016760 0ustar00hendrikhendrik000000 000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. openobex-1.7.2-Source/COPYING.LIB000644 001750 001750 00000063500 11612777701 017365 0ustar00hendrikhendrik000000 000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! openobex-1.7.2-Source/NEWS000644 001750 001750 00000000000 11612777701 016406 0ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/apps/000755 001750 001750 00000000000 12701534273 016657 5ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/apps/ChangeLog000644 001750 001750 00000002543 11612777701 020442 0ustar00hendrikhendrik000000 000000 2005-08-30 Alex Kanavin * Add client-side USB support and interface discovery 2002-11-15 Marcel Holtmann * Add Bluetooth server support 2002-11-01 Marcel Holtmann * Add Bluetooth check * Add Bluetooth client support 2002-10-28 Marcel Holtmann * Remove GLib dependencies. * Remove default prefix statement. * Replace OBEX_TRANS_CUST with OBEX_TRANS_CUSTOM. 2002-10-25 Marcel Holtmann * Implement correct handling of OBEX_EV_REQDONE 2002-10-23 Marcel Holtmann * Add streaming support and push command. 2002-10-16 Marcel Holtmann * Cleanup of autoconf/automake stuff. * Fixes for the new API. * Bump version number to 1.0.0 2000-11-21 Pontus Fuchs * Make sure that win32 makefiles in in archive! * Bumped version to 0.9.7 2000-08-21 Pontus Fuchs * Fixes to win32 makefiles 2000-08-20 Pontus Fuchs * Added openobex-check in configure. 2000-08-14 Pontus Fuchs * Small win32 build changes. 2000-08-13 Pontus Fuchs * Remade this directory to use autoconf! * Lots of small changes especially to obex_test* * All programs are now using sync mode. openobex-1.7.2-Source/apps/ircp/000755 001750 001750 00000000000 12701534273 017614 5ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/apps/ircp/ChangeLog000644 001750 001750 00000001753 11612777701 021401 0ustar00hendrikhendrik000000 000000 2002-11-30 Marcel Holtmann * Remove GLib dependencies. 2002-10-16 Marcel Holtmann * Cleanup of autoconf/automake stuff. * Fixes for the new API. * Bump version number to 0.3 2000-12-05 Pontus Fuchs * Server is now streaming body! * Better, easier and smaller handling of setpath. 2000-12-04 Pontus Fuchs * Client is now streaming body, which leads to reduced memory usage. 2000-11-20 Pontus Fuchs * Specifying absoulte path as inbox didn't work. * Sending 0 bytes long files didn't work. * Don't continue if connect fails when beeing client. 2000-08-23 Pontus Fuchs * ircp is now printing status-messages while working. 2000-08-22 Pontus Fuchs * Most server-functions shall now work too. 2000-08-21 Pontus Fuchs * Client now work. Can send files and dirs to Win2K openobex-1.7.2-Source/apps/ircp/debug.h000644 001750 001750 00000000464 11612777701 021064 0ustar00hendrikhendrik000000 000000 //#define DEBUG_TCP 1 #if defined(_MSC_VER) && _MSC_VER < 1400 static void DEBUG(int n, char *format, ...) {} #elif IRCP_DEBUG # define DEBUG(n, format, ...) \ if(n <= IRCP_DEBUG) \ fprintf(stderr, "%s(): " format, __FUNCTION__ , ## __VA_ARGS__) #else # define DEBUG(n, format, ...) #endif openobex-1.7.2-Source/apps/ircp/dirtraverse.h000644 001750 001750 00000000414 11612777701 022323 0ustar00hendrikhendrik000000 000000 #ifndef DIRTRAVERSE_H #define DIRTRAVERSE_H typedef int (*visit_cb)(int action, char *name, char *path, void *userdata); #define VISIT_FILE 1 #define VISIT_GOING_DEEPER 2 #define VISIT_GOING_UP 3 int visit_all_files(char *name, visit_cb cb, void *userdata); #endif openobex-1.7.2-Source/apps/ircp/ircp.c000644 001750 001750 00000003600 11612777701 020721 0ustar00hendrikhendrik000000 000000 #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include "debug.h" #include "ircp.h" #include "ircp_client.h" #include "ircp_server.h" // // // static void ircp_info_cb(int event, char *param) { DEBUG(4, "\n"); switch (event) { case IRCP_EV_ERRMSG: printf("Error: %s\n", param); break; case IRCP_EV_ERR: printf("failed\n"); break; case IRCP_EV_OK: printf("done\n"); break; case IRCP_EV_CONNECTING: printf("Connecting..."); break; case IRCP_EV_DISCONNECTING: printf("Disconnecting..."); break; case IRCP_EV_SENDING: printf("Sending %s...", param); break; case IRCP_EV_RECEIVING: printf("Receiving %s...", param); break; case IRCP_EV_LISTENING: printf("Waiting for incoming connection\n"); break; case IRCP_EV_CONNECTIND: printf("Incoming connection\n"); break; case IRCP_EV_DISCONNECTIND: printf("Disconnecting\n"); break; } } // // // int main(int argc, char *argv[]) { int i; ircp_client_t *cli; ircp_server_t *srv; char *inbox; if(argc >= 2 && strcmp(argv[1], "-r") == 0) { srv = ircp_srv_open(ircp_info_cb); if(srv == NULL) { printf("Error opening ircp-server\n"); return -1; } if(argc >= 3) inbox = argv[2]; else inbox = "."; ircp_srv_recv(srv, inbox); #ifdef DEBUG_TCP sleep(2); #endif ircp_srv_close(srv); } else if(argc == 1) { printf("Usage: %s file1, file2, ...\n" " or: %s -r [DEST]\n\n" "Send files over IR. Use -r to receive files.\n", argv[0], argv[0]); return 0; } else { cli = ircp_cli_open(ircp_info_cb); if(cli == NULL) { printf("Error opening ircp-client\n"); return -1; } // Connect if(ircp_cli_connect(cli) >= 0) { // Send all files for(i = 1; i < argc; i++) { ircp_put(cli, argv[i]); } // Disconnect ircp_cli_disconnect(cli); } ircp_cli_close(cli); } return 0; } openobex-1.7.2-Source/apps/ircp/ircp.h000644 001750 001750 00000001042 11612777701 020724 0ustar00hendrikhendrik000000 000000 #ifndef IRCP_H #define IRCP_H #define ircp_return_if_fail(test) do { if (!(test)) return; } while(0); #define ircp_return_val_if_fail(test, val) do { if (!(test)) return val; } while(0); typedef void (*ircp_info_cb_t)(int event, char *param); enum { IRCP_EV_ERRMSG, IRCP_EV_OK, IRCP_EV_ERR, IRCP_EV_CONNECTING, IRCP_EV_DISCONNECTING, IRCP_EV_SENDING, IRCP_EV_LISTENING, IRCP_EV_CONNECTIND, IRCP_EV_DISCONNECTIND, IRCP_EV_RECEIVING, }; /* Number of bytes passed at one time to OBEX */ #define STREAM_CHUNK 4096 #endif openobex-1.7.2-Source/apps/ircp/ircp_client.h000644 001750 001750 00000000715 11612777701 022270 0ustar00hendrikhendrik000000 000000 #ifndef IRCP_CLIENT_H #define IRCP_CLIENT_H #include "ircp.h" typedef struct ircp_client { obex_t *obexhandle; int finished; int success; int obex_rsp; ircp_info_cb_t infocb; int fd; uint8_t *buf; } ircp_client_t; ircp_client_t *ircp_cli_open(ircp_info_cb_t infocb); void ircp_cli_close(ircp_client_t *cli); int ircp_cli_connect(ircp_client_t *cli); int ircp_cli_disconnect(ircp_client_t *cli); int ircp_put(ircp_client_t *cli, char *name); #endif openobex-1.7.2-Source/apps/ircp/ircp_io.h000644 001750 001750 00000000735 11612777701 021423 0ustar00hendrikhendrik000000 000000 #ifndef IRCP_IO_H #define IRCP_IO_H typedef enum { CD_CREATE=1, CD_ALLOWABS=2 } cd_flags; obex_object_t *build_object_from_file(obex_t *handle, const char *localname, const char *remotename); int ircp_open_safe(const char *path, const char *name); int ircp_checkdir(const char *path, const char *dir, cd_flags flags); int OBEX_UnicodeToChar(uint8_t *c, const uint8_t *uc, int size); int OBEX_CharToUnicode(uint8_t *uc, const uint8_t *c, int size); #endif /* IRCP_IO_H */ openobex-1.7.2-Source/apps/ircp/ircp_server.h000644 001750 001750 00000001014 11612777701 022311 0ustar00hendrikhendrik000000 000000 #ifndef IRCP_SERVER_H #define IRCP_SERVER_H #include "ircp.h" typedef struct ircp_server { obex_t *obexhandle; int finished; int success; char *inbox; ircp_info_cb_t infocb; int fd; int dirdepth; } ircp_server_t; int ircp_srv_receive(ircp_server_t *srv, obex_object_t *object, int finished); int ircp_srv_setpath(ircp_server_t *srv, obex_object_t *object); ircp_server_t *ircp_srv_open(ircp_info_cb_t infocb); void ircp_srv_close(ircp_server_t *srv); int ircp_srv_recv(ircp_server_t *srv, char *inbox); #endif openobex-1.7.2-Source/apps/ircp/dirtraverse.c000644 001750 001750 00000006060 11730665510 022314 0ustar00hendrikhendrik000000 000000 #ifdef HAVE_CONFIG_H #include #endif #define _XOPEN_SOURCE 500 #include #include #include #include #include #if ! defined(_WIN32) #include #include #else #define MAXPATHLEN 1024 #endif #include "dirtraverse.h" #include "debug.h" #define TRUE 1 #define FALSE 0 // // Read all files in a directory. Continue recusively down in directories. // static int visit_dir(char *path, visit_cb cb, void *userdata) { #if ! defined(_WIN32) struct stat statbuf; DIR *dir; struct dirent *dirent; char t[MAXPATHLEN]; int len; int ret = 1; dir = opendir(path); if(dir == NULL) { return -1; } dirent = readdir(dir); while(dirent != NULL) { if(strcmp(".", dirent->d_name) == 0) { } else if(strcmp("..", dirent->d_name) == 0) { } else { snprintf(t, MAXPATHLEN, "%s/%s", path, dirent->d_name); ret = lstat(t, &statbuf); if(ret < 0) goto out; else if(S_ISREG(statbuf.st_mode)) { ret = cb(VISIT_FILE, t, "", userdata); if( ret < 0) goto out; } else if(S_ISDIR(statbuf.st_mode)) { ret = cb(VISIT_GOING_DEEPER, dirent->d_name, path, userdata); if( ret < 0) goto out; len = strlen(path); strcat(path, "/"); strcat(path, dirent->d_name); ret = visit_dir(t, cb, userdata); if(ret < 0) goto out; ret = cb(VISIT_GOING_UP, "", "", userdata); if(ret < 0) goto out; path[len] = '\0'; } else { // This was probably a symlink. Just skip } } dirent = readdir(dir); } out: closedir(dir); return ret; #else /** TODO */ return -1; #endif } // // // int visit_all_files(char *name, visit_cb cb, void *userdata) { #ifdef _MSC_VER /** TODO */ return -1; #else struct stat statbuf; int ret; char path[MAXPATHLEN]; if(stat(name, &statbuf) < 0) { DEBUG(0, "Error stating %s\n", name); ret = -1; goto out; } if(S_ISREG(statbuf.st_mode)) { /* A single file. Just visit it, then we are done. */ ret = cb(VISIT_FILE, name, "", userdata); } else if(S_ISDIR(statbuf.st_mode)) { /* A directory! Enter it */ snprintf(path, MAXPATHLEN, "%s", name); /* Don't notify app if going "down" to "." */ if(strcmp(name, ".") == 0) ret = 1; else ret = cb(VISIT_GOING_DEEPER, name, "", userdata); if(ret < 0) goto out; ret = visit_dir(path, cb, userdata); if(ret < 0) goto out; ret = cb(VISIT_GOING_UP, "", "", userdata); if(ret < 0) goto out; } else { /* Not file, not dir, don't know what to do */ ret = -1; } out: return ret; #endif } #if 0 int visit(int action, char *name, char *path, void *userdata) { switch(action) { case VISIT_FILE: printf("Visiting %s\n", filename); break; case VISIT_GOING_DEEPER: printf("Going deeper %s\n", filename); break; case VISIT_GOING_UP: printf("Going up\n"); break; default: printf("going %d\n", action); } return 1; } // // // int main(int argc, char *argv[]) { // visit_all_files("Makefile", visit); // visit_all_files("/usr/local/apache/", visit); visit_all_files("testdir", visit); return 0; } #endif openobex-1.7.2-Source/apps/ircp/CMakeLists.txt000644 001750 001750 00000000672 12604171607 022361 0ustar00hendrikhendrik000000 000000 set ( ircp_SOURCES debug.h dirtraverse.c dirtraverse.h ircp.c ircp.h ircp_client.c ircp_client.h ircp_io.c ircp_io.h ircp_server.c ircp_server.h ) add_executable ( ircp EXCLUDE_FROM_ALL ${ircp_SOURCES} ) target_link_libraries ( ircp openobex ) install ( PROGRAMS $ DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT applications OPTIONAL ) add_dependencies ( openobex-apps ircp ) openobex-1.7.2-Source/apps/ircp/ircp_server.c000644 001750 001750 00000016311 12114605113 022273 0ustar00hendrikhendrik000000 000000 #ifdef HAVE_CONFIG_H #include #endif #include #ifdef _WIN32 #include #include #include #define chdir(s) _chdir(s) #endif #include #include #include #include #include "ircp.h" #include "ircp_io.h" #include "ircp_server.h" #include "debug.h" #define TRUE 1 #define FALSE 0 // // Incoming event from OpenOBEX // static void srv_obex_event(obex_t *handle, obex_object_t *object, int mode, int event, int obex_cmd, int obex_rsp) { ircp_server_t *srv; int ret; srv = OBEX_GetUserData(handle); // DEBUG(4, "\n"); switch (event) { case OBEX_EV_STREAMAVAIL: DEBUG(4, "Time to read some data from stream\n"); ret = ircp_srv_receive(srv, object, FALSE); break; case OBEX_EV_PROGRESS: break; case OBEX_EV_REQ: DEBUG(4, "Incoming request %02x, %d\n", obex_cmd, OBEX_CMD_SETPATH); switch(obex_cmd) { case OBEX_CMD_CONNECT: srv->infocb(IRCP_EV_CONNECTIND, ""); ret = 1; break; case OBEX_CMD_DISCONNECT: srv->infocb(IRCP_EV_DISCONNECTIND, ""); ret = 1; break; case OBEX_CMD_PUT: ret = ircp_srv_receive(srv, object, TRUE); break; case OBEX_CMD_SETPATH: ret = ircp_srv_setpath(srv, object); break; default: ret = 1; break; } if(ret < 0) { srv->finished = TRUE; srv->success = FALSE; } break; case OBEX_EV_REQHINT: /* An incoming request is about to come. Accept it! */ switch(obex_cmd) { case OBEX_CMD_PUT: DEBUG(4, "Going to turn streaming on!\n"); /* Set response to ok! */ OBEX_ObjectSetRsp(object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS); /* Turn streaming on */ OBEX_ObjectReadStream(handle, object, NULL); break; case OBEX_CMD_SETPATH: case OBEX_CMD_CONNECT: case OBEX_CMD_DISCONNECT: /* Set response to ok! */ OBEX_ObjectSetRsp(object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS); break; default: DEBUG(0, "Skipping unsupported command:%02x\n", obex_cmd); OBEX_ObjectSetRsp(object, OBEX_RSP_NOT_IMPLEMENTED, OBEX_RSP_NOT_IMPLEMENTED); break; } break; case OBEX_EV_REQDONE: if(obex_cmd == OBEX_CMD_DISCONNECT) { srv->finished = TRUE; srv->success = TRUE; } break; case OBEX_EV_LINKERR: DEBUG(0, "Link error\n"); srv->finished = TRUE; srv->success = FALSE; break; default: break; } } // // // static int ircp_srv_sync_wait(ircp_server_t *srv) { int ret; while(srv->finished == FALSE) { ret = OBEX_HandleInput(srv->obexhandle, 1); if (ret < 0) return -1; } if(srv->success) return 1; else return -1; } // // Change current dir after some sanity-checking // int ircp_srv_setpath(ircp_server_t *srv, obex_object_t *object) { obex_headerdata_t hv; uint8_t hi; uint32_t hlen; uint8_t *nonhdr_data = NULL; int nonhdr_data_len; char *name = NULL; int ret = -1; DEBUG(4, "\n"); nonhdr_data_len = OBEX_ObjectGetNonHdrData(object, &nonhdr_data); if(nonhdr_data_len != 2) { DEBUG(0, "Error parsing SetPath-command\n"); return -1; } while (OBEX_ObjectGetNextHeader(srv->obexhandle, object, &hi, &hv, &hlen)) { switch(hi) { case OBEX_HDR_NAME: if (name != NULL) free(name); name = malloc(hlen / 2); if (name != NULL) { if (OBEX_UnicodeToChar((uint8_t *) name, hv.bs, hlen) < 0) { free(name); name = NULL; } } break; default: DEBUG(2, "Skipped header %02x\n", hi); } } DEBUG(2, "Got setpath flags=%d, name=%s\n", nonhdr_data[0], name); // If bit 0 is set we shall go up if(nonhdr_data[0] & 1) { /* Cannot cd above inbox */ if(srv->dirdepth == 0) goto out; if(chdir("..") == -1) goto out; srv->dirdepth--; } else { if(name == NULL) goto out; // A setpath with empty name meens "goto root" if(strcmp(name, "") == 0) { if(chdir(srv->inbox) == -1) goto out; srv->dirdepth = 0; } else { DEBUG(4, "Going down to %s\n", name); if(ircp_checkdir("", name, CD_CREATE) < 0) goto out; if(chdir(name) == -1) goto out; srv->dirdepth++; } } ret = 1; out: if(ret < 0) OBEX_ObjectSetRsp(object, OBEX_RSP_FORBIDDEN, OBEX_RSP_FORBIDDEN); free(name); return ret; } // // Open a file for receivning // static int new_file(ircp_server_t *srv, obex_object_t *object) { obex_headerdata_t hv; uint8_t hi; uint32_t hlen; char *name = NULL; int ret = -1; /* First iterate through recieved header to find name */ while (OBEX_ObjectGetNextHeader(srv->obexhandle, object, &hi, &hv, &hlen)) { switch(hi) { case OBEX_HDR_NAME: if (name != NULL) free(name); name = malloc(hlen / 2); if (name != NULL) { if (OBEX_UnicodeToChar((uint8_t *) name, hv.bs, hlen) < 0) { free(name); name = NULL; } } break; default: DEBUG(4, "Skipped header %02x\n", hi); } } if(name == NULL) { DEBUG(0, "Got a PUT without a name. Refusing\n"); /* Send back error */ OBEX_ObjectSetRsp(object, OBEX_RSP_BAD_REQUEST, OBEX_RSP_BAD_REQUEST); srv->infocb(IRCP_EV_ERR, ""); goto out; } srv->infocb(IRCP_EV_RECEIVING, name); srv->fd = ircp_open_safe("", name); ret = srv->fd; out: free(name); return ret; } // // Extract interesting things from object and save to disk. // int ircp_srv_receive(ircp_server_t *srv, obex_object_t *object, int finished) { const uint8_t *body = NULL; int len, body_len = 0; if(srv->fd < 0 && finished == FALSE) { /* Not receiving a file */ if(new_file(srv, object) < 0) return 1; } if(finished == TRUE) { /* Recieve done! */ DEBUG(4, "Done!...\n"); return 1; } else if (srv->fd > 0) { /* fd is valid. We are currently receiving a file */ body_len = OBEX_ObjectReadStream(srv->obexhandle, object, &body); DEBUG(4, "Got %d bytes of stream-data\n", body_len); if(body_len < 0) { /* Error */ } else if(body_len == 0) { /* EOS */ close(srv->fd); srv->fd = -1; srv->infocb(IRCP_EV_OK, ""); } else { if(srv->fd > 0) { len = write(srv->fd, body, body_len); if (len < 0) { perror("write:"); return -1; } } } return 1; } return -1; } // // Create an ircp server // ircp_server_t *ircp_srv_open(ircp_info_cb_t infocb) { ircp_server_t *srv; DEBUG(4, "\n"); srv = malloc(sizeof(ircp_server_t)); if(srv == NULL) return NULL; srv->fd = -1; srv->infocb = infocb; #ifdef DEBUG_TCP srv->obexhandle = OBEX_Init(OBEX_TRANS_INET, srv_obex_event, 0); #else srv->obexhandle = OBEX_Init(OBEX_TRANS_IRDA, srv_obex_event, 0); #endif if(srv->obexhandle == NULL) { free(srv); return NULL; } OBEX_SetUserData(srv->obexhandle, srv); return srv; } // // Close an ircp server // void ircp_srv_close(ircp_server_t *srv) { DEBUG(4, "\n"); ircp_return_if_fail(srv != NULL); OBEX_Cleanup(srv->obexhandle); free(srv); } // // Wait for incoming files. // int ircp_srv_recv(ircp_server_t *srv, char *inbox) { int err, ret; if(ircp_checkdir("", inbox, CD_ALLOWABS) < 0) { srv->infocb(IRCP_EV_ERRMSG, "Specified desination directory does not exist."); return -1; } /* Start receiving files in inbox */ if(chdir(inbox) == -1) return -1; srv->dirdepth = 0; if(IrOBEX_ServerRegister(srv->obexhandle, "OBEX:IrXfer") < 0) return -1; srv->infocb(IRCP_EV_LISTENING, ""); srv->inbox = inbox; ret = ircp_srv_sync_wait(srv); /* Go back to inbox */ err = chdir(inbox); if (err < 0) perror("chdir:"); return ret; } openobex-1.7.2-Source/apps/ircp/ircp_io.c000644 001750 001750 00000012342 12114415365 021404 0ustar00hendrikhendrik000000 000000 #ifdef HAVE_CONFIG_H #include #endif #ifndef _WIN32 #define _GNU_SOURCE #endif #include #ifdef _WIN32 #include #include #include #define snprintf _snprintf #define open _open #define S_ISDIR(m) ((m & _S_IFDIR) != 0) #endif #if ! defined(_MSC_VER) #include #else #define MAXPATHLEN 1024 #endif #include #include #include #include #include #include #include #include #include "debug.h" #include "ircp_io.h" #define TRUE 1 #define FALSE 0 // // Get some file-info. (size and lastmod) // static int get_fileinfo(const char *name, char *lastmod) { struct stat stats; struct tm *tm; if (stat(name, &stats) != -1) { tm = gmtime(&stats.st_mtime); snprintf(lastmod, 21, "%04d-%02d-%02dT%02d:%02d:%02dZ", tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); return (int) stats.st_size; } else { DEBUG(1, "stat() error!\n"); return 0; } } // // Create an object from a file. Attach some info-headers to it // obex_object_t *build_object_from_file(obex_t *handle, const char *localname, const char *remotename) { obex_object_t *object = NULL; obex_headerdata_t hdd; uint8_t *ucname; int ucname_len, size; char lastmod[21*2] = {"1970-01-01T00:00:00Z"}; /* Get filesize and modification-time */ size = get_fileinfo(localname, lastmod); object = OBEX_ObjectNew(handle, OBEX_CMD_PUT); if(object == NULL) return NULL; ucname_len = strlen(remotename)*2 + 2; ucname = malloc(ucname_len); if(ucname == NULL) goto err; ucname_len = OBEX_CharToUnicode(ucname, (uint8_t *) remotename, ucname_len); if (ucname_len < 0) goto err; hdd.bs = ucname; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hdd, ucname_len, 0); free(ucname); hdd.bq4 = size; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_LENGTH, hdd, sizeof(uint32_t), 0); #if 0 /* Win2k excpects this header to be in unicode. I suspect this in incorrect so this will have to wait until that's investigated */ hdd.bs = lastmod; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_TIME, hdd, strlen(lastmod)+1, 0); #endif hdd.bs = NULL; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY, hdd, 0, OBEX_FL_STREAM_START); DEBUG(4, "Lastmod = %s\n", lastmod); return object; err: if(object != NULL) OBEX_ObjectDelete(handle, object); return NULL; } // // Check for dangerous filenames. // static int ircp_nameok(const char *name) { DEBUG(4, "\n"); /* No abs paths */ if(name[0] == '/') return FALSE; if(strlen(name) >= 3) { /* "../../vmlinuz" */ if(name[0] == '.' && name[1] == '.' && name[2] == '/') return FALSE; /* "dir/../../../vmlinuz" */ if(strstr(name, "/../") != NULL) return FALSE; } return TRUE; } // // Open a file, but do some sanity-checking first. // #ifndef DEFFILEMODE #define DEFFILEMODE 0 #endif int ircp_open_safe(const char *path, const char *name) { char diskname[MAXPATHLEN]; int fd; DEBUG(4, "\n"); /* Check for dangerous filenames */ if(ircp_nameok(name) == FALSE) return -1; if (path == NULL || path[0] == 0) path = "."; if (snprintf(diskname, sizeof(diskname), "%s/%s", path, name) >= (ssize_t) sizeof(diskname)) return -1; /* never overwrite an existing file */ fd = open(diskname, O_RDWR | O_CREAT | O_EXCL, DEFFILEMODE); #ifndef _WIN32 if (fd < 0 && snprintf(diskname, sizeof(diskname), "%s/%s_XXXXXX", path, name) < (ssize_t) sizeof(diskname)) fd = mkstemp(diskname); #endif if (fd >= 0) { DEBUG(4, "Creating file %s\n", diskname); } return fd; } // // Go to a directory. Create if not exists and create is true. // int ircp_checkdir(const char *path, const char *dir, cd_flags flags) { char newpath[MAXPATHLEN]; struct stat statbuf; int ret = -1; if(!(flags & CD_ALLOWABS)) { if(ircp_nameok(dir) == FALSE) return -1; } if (path[0] != 0) snprintf(newpath, sizeof(newpath), "%s/%s", path, dir); else { memset(newpath, 0, sizeof(newpath)); strncpy(newpath, dir, sizeof(newpath)-1); } DEBUG(4, "path = %s dir = %s, flags = %d\n", path, dir, flags); if(stat(newpath, &statbuf) == 0) { // If this directory aleady exist we are done if(S_ISDIR(statbuf.st_mode)) { DEBUG(4, "Using existing dir\n"); ret = 1; goto out; } else { // A non-directory with this name already exist. DEBUG(4, "A non-dir called %s already exist\n", newpath); ret = -1; goto out; } } if(flags & CD_CREATE) { DEBUG(4, "Will try to create %s\n", newpath); #ifdef _WIN32 ret = _mkdir(newpath); #else ret = mkdir(newpath, DEFFILEMODE | S_IXGRP | S_IXUSR | S_IXOTH); #endif } else { ret = -1; } out: return ret; } int OBEX_UnicodeToChar(uint8_t *c, const uint8_t *uc, int size) { int n; if (uc == NULL || c == NULL) return -1; /* Make sure buffer is big enough! */ for (n = 0; uc[n*2+1] != 0; n++); if (n >= size) return -1; for (n = 0; uc[n*2+1] != 0; n++) c[n] = uc[n*2+1]; c[n] = 0; return 0; } int OBEX_CharToUnicode(uint8_t *uc, const uint8_t *c, int size) { int len, n; if (uc == NULL || c == NULL) return -1; len = n = strlen((char *) c); if (n*2+2 > size) return -1; uc[n*2+1] = 0; uc[n*2] = 0; while (n--) { uc[n*2+1] = c[n]; uc[n*2] = 0; } return (len * 2) + 2; } openobex-1.7.2-Source/apps/ircp/ircp_client.c000644 001750 001750 00000017132 12112366575 022263 0ustar00hendrikhendrik000000 000000 #ifdef HAVE_CONFIG_H #include #endif #include #ifdef _WIN32 #include #define in_addr_t unsigned long #include #include #endif #include #include #include #include #include #include #include "ircp.h" #include "ircp_client.h" #include "ircp_io.h" #include "dirtraverse.h" #include "debug.h" #ifdef DEBUG_TCP #include #include #include #include #include #endif #ifdef _WIN32 #define getcwd(b,len) _getcwd(b,len) #define chdir(s) _chdir(s) #ifndef S_ISDIR #define S_ISDIR(x) ((x & _S_IFDIR) != 0) #endif #endif #define TRUE 1 #define FALSE 0 // // Add more data to stream. // static int cli_fillstream(ircp_client_t *cli, obex_object_t *object) { int actual; obex_headerdata_t hdd; DEBUG(4, "\n"); actual = read(cli->fd, cli->buf, STREAM_CHUNK); DEBUG(4, "Read %d bytes\n", actual); if(actual > 0) { /* Read was ok! */ hdd.bs = cli->buf; OBEX_ObjectAddHeader(cli->obexhandle, object, OBEX_HDR_BODY, hdd, actual, OBEX_FL_STREAM_DATA); } else if(actual == 0) { /* EOF */ hdd.bs = cli->buf; close(cli->fd); cli->fd = -1; OBEX_ObjectAddHeader(cli->obexhandle, object, OBEX_HDR_BODY, hdd, 0, OBEX_FL_STREAM_DATAEND); } else { /* Error */ hdd.bs = NULL; close(cli->fd); cli->fd = -1; OBEX_ObjectAddHeader(cli->obexhandle, object, OBEX_HDR_BODY, hdd, 0, OBEX_FL_STREAM_DATA); } return actual; } // // Incoming event from OpenOBEX. // static void cli_obex_event(obex_t *handle, obex_object_t *object, int mode, int event, int obex_cmd, int obex_rsp) { ircp_client_t *cli; cli = OBEX_GetUserData(handle); switch (event) { case OBEX_EV_PROGRESS: break; case OBEX_EV_REQDONE: cli->finished = TRUE; if(obex_rsp == OBEX_RSP_SUCCESS) cli->success = TRUE; else cli->success = FALSE; cli->obex_rsp = obex_rsp; break; case OBEX_EV_LINKERR: cli->finished = 1; cli->success = FALSE; break; case OBEX_EV_STREAMEMPTY: cli_fillstream(cli, object); break; default: DEBUG(1, "Unknown event %d\n", event); break; } } // // Do an OBEX request sync. // static int cli_sync_request(ircp_client_t *cli, obex_object_t *object) { int ret; DEBUG(4, "\n"); cli->finished = FALSE; OBEX_Request(cli->obexhandle, object); while(cli->finished == FALSE) { ret = OBEX_HandleInput(cli->obexhandle, 20); DEBUG(4, "ret = %d\n", ret); if (ret <= 0) return -1; } DEBUG(4, "Done success=%d\n", cli->success); if(cli->success) return 1; else return -1; } // // Create an ircp client // ircp_client_t *ircp_cli_open(ircp_info_cb_t infocb) { ircp_client_t *cli; DEBUG(4, "\n"); cli = malloc(sizeof(ircp_client_t)); if(cli == NULL) return NULL; cli->infocb = infocb; cli->fd = -1; #ifdef DEBUG_TCP cli->obexhandle = OBEX_Init(OBEX_TRANS_INET, cli_obex_event, 0); #else cli->obexhandle = OBEX_Init(OBEX_TRANS_IRDA, cli_obex_event, 0); #endif if(cli->obexhandle == NULL) { goto out_err; } OBEX_SetUserData(cli->obexhandle, cli); /* Buffer for body */ cli->buf = malloc(STREAM_CHUNK); return cli; out_err: if(cli->obexhandle != NULL) OBEX_Cleanup(cli->obexhandle); free(cli); return NULL; } // // Close an ircp client // void ircp_cli_close(ircp_client_t *cli) { DEBUG(4, "\n"); ircp_return_if_fail(cli != NULL); OBEX_Cleanup(cli->obexhandle); free(cli->buf); free(cli); } // // Do connect as client // int ircp_cli_connect(ircp_client_t *cli) { obex_object_t *object; int ret; DEBUG(4, "\n"); ircp_return_val_if_fail(cli != NULL, -1); cli->infocb(IRCP_EV_CONNECTING, ""); #ifdef DEBUG_TCP { struct sockaddr_in peer; in_addr_t inaddr; if ((inaddr = inet_addr("127.0.0.1")) != INADDR_NONE) { memcpy((char *) &peer.sin_addr, (char *) &inaddr, sizeof(inaddr)); } ret = OBEX_TransportConnect(cli->obexhandle, (struct sockaddr *) &peer, sizeof(struct sockaddr_in)); } #else ret = IrOBEX_TransportConnect(cli->obexhandle, "OBEX:IrXfer"); #endif if (ret < 0) { cli->infocb(IRCP_EV_ERR, ""); return -1; } object = OBEX_ObjectNew(cli->obexhandle, OBEX_CMD_CONNECT); ret = cli_sync_request(cli, object); if(ret < 0) cli->infocb(IRCP_EV_ERR, ""); else cli->infocb(IRCP_EV_OK, ""); return ret; } // // Do disconnect as client // int ircp_cli_disconnect(ircp_client_t *cli) { obex_object_t *object; int ret; DEBUG(4, "\n"); ircp_return_val_if_fail(cli != NULL, -1); cli->infocb(IRCP_EV_DISCONNECTING, ""); object = OBEX_ObjectNew(cli->obexhandle, OBEX_CMD_DISCONNECT); ret = cli_sync_request(cli, object); if(ret < 0) cli->infocb(IRCP_EV_ERR, ""); else cli->infocb(IRCP_EV_OK, ""); OBEX_TransportDisconnect(cli->obexhandle); return ret; } // // Do an OBEX PUT. // static int ircp_put_file(ircp_client_t *cli, char *localname, char *remotename) { obex_object_t *object; int ret; cli->infocb(IRCP_EV_SENDING, localname); DEBUG(4, "Sending %s -> %s\n", localname, remotename); ircp_return_val_if_fail(cli != NULL, -1); object = build_object_from_file(cli->obexhandle, localname, remotename); cli->fd = open(localname, O_RDONLY, 0); if(cli->fd < 0) { ret = -1; OBEX_ObjectDelete(cli->obexhandle, object); } else { ret = cli_sync_request(cli, object); close(cli->fd); } if(ret < 0) cli->infocb(IRCP_EV_ERR, localname); else cli->infocb(IRCP_EV_OK, localname); return ret; } // // Do OBEX SetPath // static int ircp_setpath(ircp_client_t *cli, char *name, int up) { obex_object_t *object; obex_headerdata_t hdd; uint8_t setpath_nohdr_data[2] = {0,}; uint8_t *ucname; int ucname_len; int ret; DEBUG(4, "%s\n", name); object = OBEX_ObjectNew(cli->obexhandle, OBEX_CMD_SETPATH); if(up) { setpath_nohdr_data[0] = 1; } else { ucname_len = strlen(name)*2 + 2; ucname = malloc(ucname_len); if(ucname == NULL) { OBEX_ObjectDelete(cli->obexhandle, object); return -1; } ucname_len = OBEX_CharToUnicode(ucname, (uint8_t *) name, ucname_len); hdd.bs = ucname; OBEX_ObjectAddHeader(cli->obexhandle, object, OBEX_HDR_NAME, hdd, ucname_len, 0); free(ucname); } OBEX_ObjectSetNonHdrData(object, setpath_nohdr_data, 2); ret = cli_sync_request(cli, object); return ret; } // // Callback from dirtraverse. // static int ircp_visit(int action, char *name, char *path, void *userdata) { char *remotename; int ret = -1; DEBUG(4, "\n"); switch(action) { case VISIT_FILE: // Strip /'s before sending file remotename = strrchr(name, '/'); if(remotename == NULL) remotename = name; else remotename++; ret = ircp_put_file(userdata, name, remotename); break; case VISIT_GOING_DEEPER: ret = ircp_setpath(userdata, name, FALSE); break; case VISIT_GOING_UP: ret = ircp_setpath(userdata, "", TRUE); break; } DEBUG(4, "returning %d\n", ret); return ret; } // // Put file or directory // int ircp_put(ircp_client_t *cli, char *name) { struct stat statbuf; char *origdir; int err, ret; /* Remember cwd */ origdir = getcwd(NULL, 0); if(origdir == NULL) return -1; if(stat(name, &statbuf) == -1) { return -1; } /* This is a directory. CD into it */ if(S_ISDIR(statbuf.st_mode)) { char *newrealdir = NULL; char *dirname; err = chdir(name); if (err < 0) { perror("chdir:"); return -1; } name = "."; /* Get real name of new wd, extract last part of and do setpath to it */ newrealdir = getcwd(NULL, 0); dirname = strrchr(newrealdir, '/') + 1; if(strlen(dirname) != 0) ircp_setpath(cli, dirname, FALSE); free(newrealdir); } ret = visit_all_files(name, ircp_visit, cli); err = chdir(origdir); free(origdir); return ret; } openobex-1.7.2-Source/apps/lib/000755 001750 001750 00000000000 12701534273 017425 5ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/apps/lib/obex_io.h000644 001750 001750 00000002114 11612777701 021225 0ustar00hendrikhendrik000000 000000 /** \file apps/obex_io.h Some useful disk-IO functions. OpenOBEX test applications and sample code. */ #ifndef OBEX_IO_H #define OBEX_IO_H /* Application defined headers */ #define HEADER_CREATOR_ID 0xcf #define ADDRESS_BOOK 0x61646472 /* "addr" *.vcf */ #define MEMO_PAD 0x6d656d6f /* "memo" *.txt */ #define TO_DO_LIST 0x746f646f /* "todo" *.vcs */ #define DATE_BOOK 0x64617465 /* "date" *.vcs */ #define PILOT_RESOURCE 0x6c6e6368 /* "Inch" *.prc */ int get_filesize(const char *filename); obex_object_t *build_object_from_file(obex_t *handle, const char *filename, uint32_t creator_id); int safe_save_file(char *name, const uint8_t *buf, int len); uint8_t* easy_readfile(const char *filename, int *file_size); /* hack to distinguish between different obex protocols */ extern int obex_protocol_type; #define OBEX_PROTOCOL_GENERIC 0 #define OBEX_PROTOCOL_WIN95_IRXFER 1 /* win95 irxfer ( does not like palm creatorid header ) */ int OBEX_UnicodeToChar(uint8_t *c, const uint8_t *uc, int size); int OBEX_CharToUnicode(uint8_t *uc, const uint8_t *c, int size); #endif openobex-1.7.2-Source/apps/lib/obex_put_common.h000644 001750 001750 00000002022 11734661776 023005 0ustar00hendrikhendrik000000 000000 /** \file apps/obex_put_common.h Utility-functions to act as a PUT server and client. OpenOBEX test applications and sample code. Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenOBEX. If not, see . */ #ifndef OBEX_PUT_COMMON_H #define OBEX_PUT_COMMON_H int do_sync_request(obex_t *handle, obex_object_t *object, int async); void obex_event(obex_t *handle, obex_object_t *object, int mode, int event, int obex_cmd, int obex_rsp); #endif openobex-1.7.2-Source/apps/lib/CMakeLists.txt000644 001750 001750 00000000370 11771377401 022171 0ustar00hendrikhendrik000000 000000 # # a static library to not compile those multiple times # add_library ( openobex-apps-common STATIC EXCLUDE_FROM_ALL obex_io.c obex_io.h obex_put_common.c obex_put_common.h ) target_link_libraries ( openobex-apps-common openobex ) openobex-1.7.2-Source/apps/lib/obex_io.c000644 001750 001750 00000012742 12114412362 021213 0ustar00hendrikhendrik000000 000000 /** \file apps/obex_io.c Some useful disk-IO functions. OpenOBEX test applications and sample code. Copyright (c) 1999 Dag Brattli, All Rights Reserved. Copyright (c) 2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #include #ifdef _WIN32 #include #include #else #include #include #endif /*_WIN32 */ #include #include #include #include #include "obex_io.h" extern obex_t *handle; int obex_protocol_type = OBEX_PROTOCOL_GENERIC; // // Get the filesize in a "portable" way // int get_filesize(const char *filename) { #ifdef _WIN32 HANDLE fh; int size; fh = CreateFile(filename, 0, 0, NULL, OPEN_EXISTING, 0, NULL); if(fh == INVALID_HANDLE_VALUE) { printf("Cannot open %s\n", filename); return -1; } size = GetFileSize(fh, NULL); printf("fize size was %d\n", size); CloseHandle(fh); return size; #else struct stat stats; /* Need to know the file length */ if (stat(filename, &stats) == -1) { printf("stat() error\n"); return -1; } else return (int) stats.st_size; #endif } // // Read a file and alloc a buffer for it // uint8_t* easy_readfile(const char *filename, int *file_size) { int actual; int fd; uint8_t *buf; *file_size = get_filesize(filename); printf("name=%s, size=%d\n", filename, *file_size); if (*file_size == -1) return NULL; #ifdef _WIN32 fd = open(filename, O_RDONLY | O_BINARY, 0); #else fd = open(filename, O_RDONLY, 0); #endif if (fd == -1) return NULL; buf = malloc(*file_size); if(!buf) { close(fd); return NULL; } actual = read(fd, buf, *file_size); close(fd); #ifdef _WIN32 if(actual != *file_size) { free(buf); buf = NULL; } #else *file_size = actual; #endif return buf; } // // // obex_object_t *build_object_from_file(obex_t *handle, const char *filename, uint32_t creator_id) { obex_headerdata_t hdd; uint8_t unicode_buf[200]; int namebuf_len; obex_object_t *object; //uint32_t creator_id; int file_size; char *name = NULL; uint8_t *buf; buf = easy_readfile(filename, &file_size); if(buf == NULL) return NULL; /* Set Memopad as the default creator ID */ if(creator_id == 0) creator_id = MEMO_PAD; /* Find the . in the filename */ name = strchr(filename, '.'); if (name) { name++; if (strcmp(name, "vcf") == 0) { printf( "This is a Address Book file\n"); creator_id = ADDRESS_BOOK; } else if (strcmp(name, "vcs") == 0) { printf( "This is a Date Book file\n"); creator_id = DATE_BOOK; } else if (strcmp(name, "txt") == 0) { printf("This is a Memo pad file\n"); creator_id = MEMO_PAD; } else if (strcmp(name, "prc") == 0) { printf("This is a Pilot resource file\n"); creator_id = PILOT_RESOURCE; } } /* Build object */ object = OBEX_ObjectNew(handle, OBEX_CMD_PUT); namebuf_len = OBEX_CharToUnicode(unicode_buf, (uint8_t *) filename, sizeof(unicode_buf)); hdd.bs = unicode_buf; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hdd, namebuf_len, 0); hdd.bq4 = file_size; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_LENGTH, hdd, sizeof(uint32_t), 0); #if 0 /* Optional header for win95 irxfer, allows date to be set on file */ OBEX_ObjectAddHeader(handle, object, OBEX_HDR_TIME2, (obex_headerdata_t) (uint32_t) stats.st_mtime, sizeof(uint32_t), 0); #endif if (obex_protocol_type != 1) { /* Optional header for Palm Pilot */ /* win95 irxfer does not seem to like this one */ hdd.bq4 = creator_id; OBEX_ObjectAddHeader(handle, object, HEADER_CREATOR_ID, hdd, sizeof(uint32_t), 0); } hdd.bs = buf; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY, hdd, file_size, 0); free(buf); return object; } /* * Function safe_save_file () * * First remove path and add "/tmp/". Then save. * */ #ifndef DEFFILEMODE #define DEFFILEMODE 0 #endif int safe_save_file(char *name, const uint8_t *buf, int len) { char *s = NULL; char filename[255] = {0,}; int fd; int actual; printf("Filename = %s\n", name); s = strrchr(name, '/'); if (s == NULL) s = name; else s++; strncat(filename, s, 250); fd = open(filename, O_RDWR | O_CREAT, DEFFILEMODE); if ( fd < 0) { perror( filename); return -1; } actual = write(fd, buf, len); close(fd); printf( "Wrote %s (%d bytes)\n", filename, actual); return actual; } int OBEX_UnicodeToChar(uint8_t *c, const uint8_t *uc, int size) { int n; if (uc == NULL || c == NULL) return -1; /* Make sure buffer is big enough! */ for (n = 0; uc[n*2+1] != 0; n++); if (n >= size) return -1; for (n = 0; uc[n*2+1] != 0; n++) c[n] = uc[n*2+1]; c[n] = 0; return 0; } int OBEX_CharToUnicode(uint8_t *uc, const uint8_t *c, int size) { int len, n; if (uc == NULL || c == NULL) return -1; len = n = strlen((char *) c); if (n*2+2 > size) return -1; uc[n*2+1] = 0; uc[n*2] = 0; while (n--) { uc[n*2+1] = c[n]; uc[n*2] = 0; } return (len * 2) + 2; } openobex-1.7.2-Source/apps/lib/obex_put_common.c000644 001750 001750 00000012160 12114736754 022774 0ustar00hendrikhendrik000000 000000 /** \file apps/obex_put_common.c Utility-functions to act as a PUT server and client. OpenOBEX test applications and sample code. Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #include #include "obex_put_common.h" #include "obex_io.h" #include #include #define TRUE 1 #define FALSE 0 extern obex_t *handle; extern volatile int finished; volatile int last_rsp = OBEX_RSP_BAD_REQUEST; /* * Function put_done() * * Parse what we got from a PUT * */ static void put_done(obex_object_t *object) { obex_headerdata_t hv; uint8_t hi; uint32_t hlen; const uint8_t *body = NULL; int body_len = 0; char *name = NULL; while (OBEX_ObjectGetNextHeader(handle, object, &hi, &hv, &hlen)) { switch(hi) { case OBEX_HDR_BODY: body = hv.bs; body_len = hlen; break; case OBEX_HDR_NAME: if (name) free(name); name = malloc(hlen / 2); if(name) { if (OBEX_UnicodeToChar((uint8_t *) name, hv.bs, hlen) < 0) { free(name); name = NULL; } } break; case OBEX_HDR_LENGTH: printf("HEADER_LENGTH = %d\n", hv.bq4); break; case HEADER_CREATOR_ID: printf("CREATORID = %#x\n", hv.bq4); break; default: printf("%s() Skipped header %02x\n", __FUNCTION__, hi); } } if (!body) { printf("Got a PUT without a body\n"); return; } if (!name) { printf("Got a PUT without a name. Setting name to %s\n", name); name = "OBEX_PUT_Unknown_object"; safe_save_file(name, body, body_len); } else { safe_save_file(name, body, body_len); free(name); } } /* * Function server_indication() * * Called when a request is about to come or has come. * */ static void server_request(obex_object_t *object, int event, int cmd) { switch(cmd) { case OBEX_CMD_SETPATH: printf("Received SETPATH command\n"); OBEX_ObjectSetRsp(object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS); break; case OBEX_CMD_PUT: OBEX_ObjectSetRsp(object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS); put_done(object); break; case OBEX_CMD_CONNECT: OBEX_ObjectSetRsp(object, OBEX_RSP_SUCCESS, OBEX_RSP_SUCCESS); break; case OBEX_CMD_DISCONNECT: OBEX_ObjectSetRsp(object, OBEX_RSP_SUCCESS, OBEX_RSP_SUCCESS); break; default: printf("%s() Denied %02x request\n", __FUNCTION__, cmd); OBEX_ObjectSetRsp(object, OBEX_RSP_NOT_IMPLEMENTED, OBEX_RSP_NOT_IMPLEMENTED); break; } return; } /* * Function client_done_indication() * * Called when a server-operation has finished * */ static void server_done(obex_object_t *object, int obex_cmd) { /* Quit if DISCONNECT has finished */ if(obex_cmd == OBEX_CMD_DISCONNECT) finished = 1; } /* * Function client_done() * * Called when a client-operation has finished * */ static void client_done(obex_object_t *object, int obex_cmd, int obex_rsp) { last_rsp = obex_rsp; finished = TRUE; } /* * Function obex_event () * * Called by the obex-layer when some event occurs. * */ void obex_event(obex_t *handle, obex_object_t *object, int mode, int event, int obex_cmd, int obex_rsp) { switch (event) { case OBEX_EV_PROGRESS: printf("."); break; case OBEX_EV_REQDONE: printf("\n"); /* Comes when a command has finished. */ if(mode == OBEX_MODE_CLIENT) client_done(object, obex_cmd, obex_rsp); else server_done(object, obex_cmd); break; case OBEX_EV_REQHINT: /* Comes BEFORE the lib parses anything. */ switch(obex_cmd) { case OBEX_CMD_PUT: case OBEX_CMD_CONNECT: case OBEX_CMD_DISCONNECT: OBEX_ObjectSetRsp(object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS); break; default: OBEX_ObjectSetRsp(object, OBEX_RSP_NOT_IMPLEMENTED, OBEX_RSP_NOT_IMPLEMENTED); break; } break; case OBEX_EV_REQ: /* Comes when a server-request has been received. */ server_request(object, event, obex_cmd); break; case OBEX_EV_LINKERR: printf("Link broken (this does not have to be an error)!\n"); finished = 1; break; default: printf("Unknown event!\n"); break; } } /* * Function wait_for_rsp() * * Wait for a request to finish! * * Timeout set to 10s. Should be more than good enough for most transport. */ static int wait_for_rsp() { int ret; while(!finished) { //printf("wait_for_rsp()\n"); ret = OBEX_HandleInput(handle, 10); if (ret < 0) return ret; } return last_rsp; } /* * Function do_sync_request() * * Execute an OBEX-request synchronously. * */ int do_sync_request(obex_t *handle, obex_object_t *object, int async) { int ret; OBEX_Request(handle, object); ret = wait_for_rsp(); finished = FALSE; return ret; } openobex-1.7.2-Source/apps/obex_test/000755 001750 001750 00000000000 12701534273 020653 5ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/apps/obex_test/obex_test_client.h000644 001750 001750 00000001723 11612777701 024366 0ustar00hendrikhendrik000000 000000 /** \file apps/obex_test_client.h Client OBEX Commands. OpenOBEX test applications and sample code. */ #ifndef OBEX_TEST_CLIENT_H #define OBEX_TEST_CLIENT_H #include "obex_test.h" void client_done(obex_t *handle, obex_object_t *object, int obex_cmd, int obex_rsp); void connect_client(obex_t *handle); void connect_client_done(obex_t *handle, obex_object_t *object, int obex_rsp); void disconnect_client(obex_t *handle); void disconnect_client_done(obex_t *handle, obex_object_t *object, int obex_rsp); int fillstream(obex_t *handle, obex_object_t *object); void push_client(obex_t *handle); void put_client(obex_t *handle); void put_client_done(obex_t *handle, obex_object_t *object, int obex_rsp); void get_client(obex_t *handle, struct context *gt); void get_client_done(obex_t *handle, obex_object_t *object, int obex_rsp, char *name); void setpath_client(obex_t *handle); void setpath_client_done(obex_t *handle, obex_object_t *object, int obex_rsp); #endif openobex-1.7.2-Source/apps/obex_test/obex_test_server.h000644 001750 001750 00000000561 11612777701 024415 0ustar00hendrikhendrik000000 000000 /** \file apps/obex_test_server.h Server OBEX Commands. OpenOBEX test applications and sample code. */ #ifndef OBEX_TEST_SERVER_H #define OBEX_TEST_SERVER_H void server_do(obex_t *handle); void server_done(obex_t *handle, obex_object_t *object, int obex_cmd, int obex_rsp); void server_request(obex_t *handle, obex_object_t *object, int event, int cmd); #endif openobex-1.7.2-Source/apps/obex_test/CMakeLists.txt000644 001750 001750 00000001071 12701164215 023405 0ustar00hendrikhendrik000000 000000 set ( obex_test_SOURCES obex_test.c obex_test.h obex_test_client.c obex_test_client.h obex_test_server.c obex_test_server.h ) add_executable ( obex_test EXCLUDE_FROM_ALL ${obex_test_SOURCES} ) target_link_libraries ( obex_test openobex-apps-common openobex ${Bluetooth_LIBRARIES} ) if ( WIN32 ) target_link_libraries ( obex_test ws2_32 ) endif ( WIN32 ) install ( PROGRAMS $ DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT applications OPTIONAL ) add_dependencies ( openobex-apps obex_test ) openobex-1.7.2-Source/apps/obex_test/obex_test.h000644 001750 001750 00000000540 12701165124 023012 0ustar00hendrikhendrik000000 000000 /** \file apps/obex_test.h Test IrOBEX, TCPOBEX and OBEX over cable to R320s. OpenOBEX test applications and sample code. */ #ifndef OBEX_TEST_H #define OBEX_TEST_H struct context { int serverdone; int clientdone; char *get_name; /* Name of last get-request */ }; int read_input(char *answer, size_t size, const char *question, ...); #endif openobex-1.7.2-Source/apps/obex_test/obex_test_client.c000644 001750 001750 00000025472 12114415751 024360 0ustar00hendrikhendrik000000 000000 /** \file apps/obex_test_client.c Client OBEX Commands. OpenOBEX test applications and sample code. Copyright (c) 2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #define _XOPEN_SOURCE 500 #include #include "obex_io.h" #include "obex_test_client.h" #include "obex_test.h" #if defined(_WIN32) #include #define read _read #define write _write #define open _open #if defined(_MSC_VER) static char *basename(const char *s) { static char base[_MAX_FNAME+_MAX_EXT] = {0}; _splitpath(s, NULL, NULL, base, NULL); _splitpath(s, NULL, NULL, NULL, base+strlen(base)); return base; } #else /* MinGW compiler */ #include #endif #else #include #endif #include #include #include #include #include #define TRUE 1 #define FALSE 0 #define OBEX_STREAM_CHUNK 4096 uint8_t buffer[OBEX_STREAM_CHUNK]; int fileDesc; // // Wait for an obex command to finish. // static void syncwait(obex_t *handle) { struct context *gt; int ret; gt = OBEX_GetUserData(handle); while(!gt->clientdone) { //printf("syncwait()\n"); ret = OBEX_HandleInput(handle, 10); if(ret < 0) { printf("Error while doing OBEX_HandleInput()\n"); break; } } gt->clientdone = FALSE; } // // // void client_done(obex_t *handle, obex_object_t *object, int obex_cmd, int obex_rsp) { struct context *gt; gt = OBEX_GetUserData(handle); switch(obex_cmd) { case OBEX_CMD_CONNECT: connect_client_done(handle, object, obex_rsp); break; case OBEX_CMD_DISCONNECT: disconnect_client_done(handle, object, obex_rsp); break; case OBEX_CMD_PUT: put_client_done(handle, object, obex_rsp); break; case OBEX_CMD_GET: get_client_done(handle, object, obex_rsp, gt->get_name); break; case OBEX_CMD_SETPATH: setpath_client_done(handle, object, obex_rsp); break; } gt->clientdone = TRUE; } // // // void connect_client(obex_t *handle) { obex_object_t *object; obex_headerdata_t hd; int err; object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT); if(object == NULL) { printf("Error\n"); return; } hd.bs = (uint8_t *) "Linux"; if(OBEX_ObjectAddHeader(handle, object, OBEX_HDR_WHO, hd, 6, OBEX_FL_FIT_ONE_PACKET) < 0) { printf("Error adding header\n"); OBEX_ObjectDelete(handle, object); return; } err = OBEX_Request(handle, object); if (err) { OBEX_ObjectDelete(handle, object); printf("Error: %s\n", strerror(err)); return; } syncwait(handle); } // // // void connect_client_done(obex_t *handle, obex_object_t *object, int obex_rsp) { uint8_t *nonhdrdata; if(obex_rsp == OBEX_RSP_SUCCESS) { printf("Connect OK!\n"); if(OBEX_ObjectGetNonHdrData(object, &nonhdrdata) == 4) { printf("Version: 0x%02x. Flags: 0x%02x\n", nonhdrdata[0], nonhdrdata[1]); } } else { printf("Connect failed 0x%02x!\n", obex_rsp); } } // // // void disconnect_client(obex_t *handle) { obex_object_t *object; int err; object = OBEX_ObjectNew(handle, OBEX_CMD_DISCONNECT); if(object == NULL) { printf("Error\n"); return; } err = OBEX_Request(handle, object); if (err) { OBEX_ObjectDelete(handle, object); printf("Error: %s\n", strerror(err)); return; } syncwait(handle); } // // // void disconnect_client_done(obex_t *handle, obex_object_t *object, int obex_rsp) { printf("Disconnect done!\n"); OBEX_TransportDisconnect(handle); } int fillstream(obex_t *handle, obex_object_t *object) { int actual; obex_headerdata_t hv; printf("Filling stream!\n"); actual = read(fileDesc, buffer, OBEX_STREAM_CHUNK); if(actual > 0) { /* Read was ok! */ hv.bs = buffer; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY, hv, actual, OBEX_FL_STREAM_DATA); } else if(actual == 0) { /* EOF */ hv.bs = buffer; close(fileDesc); fileDesc = -1; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY, hv, 0, OBEX_FL_STREAM_DATAEND); } else { /* Error */ hv.bs = NULL; close(fileDesc); fileDesc = -1; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY, hv, 0, OBEX_FL_STREAM_DATA); } return actual; } void push_client(obex_t *handle) { obex_object_t *object; char fname[200]; int uname_size; char *bfname; uint8_t *uname; obex_headerdata_t hd; uint8_t *buf; int file_size; int err; if (read_input(fname, sizeof(fname), "PUSH file> ") <= 0) { perror("Error reading file name"); return; } bfname = strdup(basename(fname)); if (bfname == NULL) { perror("Error"); return; } buf = easy_readfile(fname, &file_size); if (buf == NULL) { printf("file not found: %s\n", fname); free(bfname); printf("Error\n"); return; } fileDesc = open(fname, O_RDONLY, 0); if (fileDesc < 0) { free(buf); free(bfname); printf("Error\n"); return; } printf("Going to send %s(%s), %d bytes\n",fname,bfname, file_size); /* Build object */ object = OBEX_ObjectNew(handle, OBEX_CMD_PUT); if (object == NULL) { free(buf); free(bfname); printf("Error\n"); return; } uname_size = (strlen(bfname) + 1) << 1; uname = malloc(uname_size); uname_size = OBEX_CharToUnicode(uname, (uint8_t *) bfname, uname_size); if (uname_size < 0) { free(buf); free(bfname); OBEX_ObjectDelete(handle, object); printf("Error\n"); return; } hd.bs = uname; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hd, uname_size, 0); hd.bq4 = file_size; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_LENGTH, hd, sizeof(uint32_t), 0); hd.bs = NULL; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY, hd, 0, OBEX_FL_STREAM_START); free(buf); free(uname); free(bfname); err = OBEX_Request(handle, object); if (err) { OBEX_ObjectDelete(handle, object); printf("Error: %s\n", strerror(err)); return; } syncwait(handle); } // // // void put_client(obex_t *handle) { obex_object_t *object; char lname[200]; char rname[200]; int rname_size; obex_headerdata_t hd; uint8_t *buf; int file_size; int err; if (read_input(lname, sizeof(lname), "PUT file (local)> ") <= 0) { perror("Error reading file name"); return; } buf = easy_readfile(lname, &file_size); if(buf == NULL) { printf("Error: file not found: %s\n", lname); return; } if (read_input(rname, sizeof(rname), "PUT remote filename (default: %s)> ", lname) < 0) { free(buf); perror("Error reading file name"); return; } if (strlen(rname) == 0) strcpy(rname, lname); printf("Going to send %d bytes\n", file_size); /* Build object */ object = OBEX_ObjectNew(handle, OBEX_CMD_PUT); if (object == NULL) { free(buf); printf("Error\n"); return; } rname_size = OBEX_CharToUnicode((uint8_t *) rname, (uint8_t *) rname, sizeof(rname)); if (rname_size < 0) { free(buf); OBEX_ObjectDelete(handle, object); printf("Error\n"); return; } hd.bq4 = file_size; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_LENGTH, hd, 4, 0); hd.bs = (uint8_t *) rname; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hd, rname_size, 0); hd.bs = buf; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY, hd, file_size, 0); free(buf); err = OBEX_Request(handle, object); if (err) { OBEX_ObjectDelete(handle, object); printf("Error: %s\n", strerror(err)); return; } syncwait(handle); } // // // void put_client_done(obex_t *handle, obex_object_t *object, int obex_rsp) { if(obex_rsp == OBEX_RSP_SUCCESS) { printf("PUT successful!\n"); } else { printf("PUT failed 0x%02x!\n", obex_rsp); } } // // // void get_client(obex_t *handle, struct context *gt) { obex_object_t *object; uint8_t rname[200]; char req_name[200]; int rname_size; obex_headerdata_t hd; int err; if (read_input(req_name, sizeof(req_name), "GET file> ") <= 0) { perror("Error reading file name"); return; } object = OBEX_ObjectNew(handle, OBEX_CMD_GET); if(object == NULL) { printf("Error\n"); return; } rname_size = OBEX_CharToUnicode(rname, (uint8_t *) req_name, sizeof(rname)); if (rname_size < 0) { OBEX_ObjectDelete(handle, object); printf("Error\n"); return; } hd.bs = rname; if (OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hd, rname_size, OBEX_FL_FIT_ONE_PACKET) < 0) { printf("Error adding header\n"); OBEX_ObjectDelete(handle, object); return; } /* Remember the name of the file we are getting so we can save it when we get the response */ gt->get_name = req_name; err = OBEX_Request(handle, object); if (err) { OBEX_ObjectDelete(handle, object); printf("Error: %s\n", strerror(err)); return; } syncwait(handle); } // // // void get_client_done(obex_t *handle, obex_object_t *object, int obex_rsp, char *name) { obex_headerdata_t hv; uint8_t hi; uint32_t hlen; const uint8_t *body = NULL; int body_len = 0; if(obex_rsp != OBEX_RSP_SUCCESS) { printf("GET failed 0x%02x!\n", obex_rsp); return; } while (OBEX_ObjectGetNextHeader(handle, object, &hi, &hv, &hlen)) { if(hi == OBEX_HDR_BODY) { printf("%s() Found body\n", __FUNCTION__); body = hv.bs; body_len = hlen; break; } else { printf("%s() Skipped header %02x\n", __FUNCTION__, hi); } } if(!body) { printf("No body found in answer!\n"); return; } printf("GET successful!\n"); safe_save_file(name, body, body_len); } // // // void setpath_client(obex_t *handle) { uint8_t setpath_data[2] = { 0, 0 }; obex_object_t *object; char path[200]; int path_size; obex_headerdata_t hd; int err; if (read_input(path, sizeof(path), "SETPATH> ") <= 0) { perror("Error reading path"); return; } object = OBEX_ObjectNew(handle, OBEX_CMD_SETPATH); if(object == NULL) { printf("Error\n"); return; } path_size = OBEX_CharToUnicode((uint8_t *) path, (uint8_t *) path, sizeof(path)); if (path_size < 0) { OBEX_ObjectDelete(handle, object); printf("Error\n"); return; } hd.bs = (uint8_t *) path; if (OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hd, path_size, OBEX_FL_FIT_ONE_PACKET) < 0) { printf("Error adding header\n"); OBEX_ObjectDelete(handle, object); return; } OBEX_ObjectSetNonHdrData(object, setpath_data, 2); err = OBEX_Request(handle, object); if (err) { OBEX_ObjectDelete(handle, object); printf("Error: %s\n", strerror(err)); return; } syncwait(handle); } // // // void setpath_client_done(obex_t *handle, obex_object_t *object, int obex_rsp) { if(obex_rsp == OBEX_RSP_SUCCESS) { printf("SETPATH successful!\n"); } else { printf("SETPATH failed 0x%02x!\n", obex_rsp); } } openobex-1.7.2-Source/apps/obex_test/obex_test_server.c000644 001750 001750 00000013307 12114605205 024375 0ustar00hendrikhendrik000000 000000 /** \file apps/obex_test_server.c Server OBEX Commands. OpenOBEX test applications and sample code. Copyright (c) 2000, Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #include #include "obex_io.h" #include "obex_test.h" #include "obex_test_server.h" #include #include #include #include #define TRUE 1 #define FALSE 0 // // // static void put_server(obex_t *handle, obex_object_t *object) { obex_headerdata_t hv; uint8_t hi; uint32_t hlen; const uint8_t *body = NULL; int body_len = 0; char *name = NULL; printf("%s()\n", __FUNCTION__); while (OBEX_ObjectGetNextHeader(handle, object, &hi, &hv, &hlen)) { switch(hi) { case OBEX_HDR_BODY: printf("%s() Found body\n", __FUNCTION__); body = hv.bs; body_len = hlen; break; case OBEX_HDR_NAME: printf("%s() Found name\n", __FUNCTION__); if (name != NULL) free(name); name = malloc(hlen / 2); if (name != NULL) { if (OBEX_UnicodeToChar((uint8_t *)name, hv.bs, hlen) < 0) { free(name); name = NULL; } } break; default: printf("%s() Skipped header %02x\n", __FUNCTION__, hi); } } if(!body) { printf("Got a PUT without a body\n"); free(name); return; } if(!name) { name = "OBEX_PUT_Unknown_object"; printf("Got a PUT without a name. Setting name to %s\n", name); safe_save_file(name, body, body_len); } else { safe_save_file(name, body, body_len); free(name); } } // // // static void get_server(obex_t *handle, obex_object_t *object) { uint8_t *buf; obex_headerdata_t hv; uint8_t hi; uint32_t hlen; int file_size; char *name = NULL; printf("%s()\n", __FUNCTION__); while (OBEX_ObjectGetNextHeader(handle, object, &hi, &hv, &hlen)) { switch(hi) { case OBEX_HDR_NAME: if (name == NULL) printf("%s() Found name\n", __FUNCTION__); else free(name); name = malloc(hlen / 2); if (name != NULL) { if (OBEX_UnicodeToChar((uint8_t *) name, hv.bs, hlen) < 0) { free(name); name = NULL; } } break; default: printf("%s() Skipped header %02x\n", __FUNCTION__, hi); } } if(!name) { printf("%s() Got a GET without a name-header!\n", __FUNCTION__); OBEX_ObjectSetRsp(object, OBEX_RSP_NOT_FOUND, OBEX_RSP_NOT_FOUND); return; } printf("%s() Got a request for %s\n", __FUNCTION__, name); buf = easy_readfile(name, &file_size); if(buf == NULL) { printf("Can't find file %s\n", name); OBEX_ObjectSetRsp(object, OBEX_RSP_NOT_FOUND, OBEX_RSP_NOT_FOUND); free(name); return; } OBEX_ObjectSetRsp(object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS); hv.bs = buf; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY, hv, file_size, 0); hv.bq4 = file_size; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_LENGTH, hv, sizeof(uint32_t), 0); free(name); free(buf); return; } // // // static void connect_server(obex_t *handle, obex_object_t *object) { obex_headerdata_t hv; uint8_t hi; uint32_t hlen; const uint8_t *who = NULL; int who_len = 0; printf("%s()\n", __FUNCTION__); while (OBEX_ObjectGetNextHeader(handle, object, &hi, &hv, &hlen)) { if(hi == OBEX_HDR_WHO) { who = hv.bs; who_len = hlen; } else { printf("%s() Skipped header %02x\n", __FUNCTION__, hi); } } if (who_len == 6) { if(memcmp("Linux", who, 6) == 0) { printf("Weeeha. I'm talking to the coolest OS ever!\n"); } } OBEX_ObjectSetRsp(object, OBEX_RSP_SUCCESS, OBEX_RSP_SUCCESS); } // // // void server_request(obex_t *handle, obex_object_t *object, int event, int cmd) { switch(cmd) { case OBEX_CMD_CONNECT: connect_server(handle, object); break; case OBEX_CMD_DISCONNECT: printf("We got a disconnect-request\n"); OBEX_ObjectSetRsp(object, OBEX_RSP_SUCCESS, OBEX_RSP_SUCCESS); break; case OBEX_CMD_GET: /* A Get always fits one package */ get_server(handle, object); break; case OBEX_CMD_PUT: OBEX_ObjectSetRsp(object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS); put_server(handle, object); break; case OBEX_CMD_SETPATH: printf("Got a SETPATH request\n"); OBEX_ObjectSetRsp(object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS); break; default: printf("%s() Denied %02x request\n", __FUNCTION__, cmd); OBEX_ObjectSetRsp(object, OBEX_RSP_NOT_IMPLEMENTED, OBEX_RSP_NOT_IMPLEMENTED); break; } return; } // // // void server_done(obex_t *handle, obex_object_t *object, int obex_cmd, int obex_rsp) { struct context *gt; gt = OBEX_GetUserData(handle); printf("Server request finished!\n"); switch (obex_cmd) { case OBEX_CMD_DISCONNECT: printf("Disconnect done!\n"); OBEX_TransportDisconnect(handle); gt->serverdone = TRUE; break; default: printf("%s() Command (%02x) has now finished\n", __FUNCTION__, obex_cmd); break; } } // // // void server_do(obex_t *handle) { int ret; struct context *gt; gt = OBEX_GetUserData(handle); gt->serverdone = FALSE; while(!gt->serverdone) { ret = OBEX_HandleInput(handle, 60); if(ret < 0) { printf("Error while doing OBEX_HandleInput()\n"); break; } else if (ret == 0) { printf("Timeout while doing OBEX_HandleInput()\n"); break; } else { printf("OBEX_HandleInput() returned %d\n",ret); } } } openobex-1.7.2-Source/apps/obex_test/obex_test.c000644 001750 001750 00000024135 12701164401 023010 0ustar00hendrikhendrik000000 000000 /** \file apps/obex_test.c Test IrOBEX, TCPOBEX and OBEX over cable to R320s. OpenOBEX test applications and sample code. Copyright (c) 2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #ifdef HAVE_BLUETOOTH #include "../lib/transport/bluez_compat.h" #ifdef _WIN32 bdaddr_t bluez_compat_bdaddr_any = { BTH_ADDR_NULL }; static int str2ba(const char *str, bdaddr_t *ba) { //TODO *ba = *BDADDR_ANY; return 0; } #endif #endif #include #include "obex_test.h" #include "obex_test_client.h" #include "obex_test_server.h" #if defined(_WIN32) #define in_addr_t unsigned long #else #include #include #include #include #endif #include #include #include #include #include #define TRUE 1 #define FALSE 0 #define IR_SERVICE "OBEX" #define BT_CHANNEL 4 // // Called by the obex-layer when some event occurs. // static void obex_event(obex_t *handle, obex_object_t *object, int mode, int event, int obex_cmd, int obex_rsp) { switch (event) { case OBEX_EV_PROGRESS: printf("Made some progress...\n"); break; case OBEX_EV_ABORT: printf("Request aborted!\n"); break; case OBEX_EV_REQDONE: if (mode == OBEX_MODE_CLIENT) { client_done(handle, object, obex_cmd, obex_rsp); } else { server_done(handle, object, obex_cmd, obex_rsp); } break; case OBEX_EV_REQHINT: /* Accept any command. Not rellay good, but this is a test-program :) */ OBEX_ObjectSetRsp(object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS); break; case OBEX_EV_REQ: server_request(handle, object, event, obex_cmd); break; case OBEX_EV_LINKERR: OBEX_TransportDisconnect(handle); printf("Link broken!\n"); break; case OBEX_EV_STREAMEMPTY: fillstream(handle, object); break; default: printf("Unknown event %02x!\n", event); break; } } int read_input(char *answer, size_t size, const char *question, ...) { va_list ap; va_start(ap, question); vfprintf(stdout, question, ap); va_end(ap); fflush(stdout); if (fgets(answer, size, stdin) == NULL) return -1; answer[strlen(answer)-1] = '\0'; /* remove trailing newline */ return strlen(answer); } #if 0 /* * Function get_peer_addr (name, peer) * * * */ static int get_peer_addr(char *name, struct sockaddr_in *peer) { struct hostent *host; in_addr_t inaddr; /* Is the address in dotted decimal? */ if ((inaddr = inet_addr(name)) != INADDR_NONE) { memcpy((char *) &peer->sin_addr, (char *) &inaddr, sizeof(inaddr)); } else { if ((host = gethostbyname(name)) == NULL) { printf( "Bad host name: "); exit(-1); } memcpy((char *) &peer->sin_addr, host->h_addr, host->h_length); } return 0; } // // // static int inet_connect(obex_t *handle) { struct sockaddr_in peer; get_peer_addr("localhost", &peer); return OBEX_TransportConnect(handle, (struct sockaddr *) &peer, sizeof(struct sockaddr_in)); } #endif // // // int main (int argc, char *argv[]) { char cmd[3]; int end = 0; int tcpobex = FALSE; obex_t *handle = NULL; struct context global_context = {0}; unsigned int flags = 0; int i = 1; #ifdef HAVE_BLUETOOTH int btobex = FALSE; bdaddr_t bdaddr; uint8_t channel = 0; #endif #ifdef HAVE_USB int usbobex = FALSE; obex_interface_t *obex_intf = NULL; #endif if (argc == 2 && strcmp(argv[1], "-h") == 0) { printf( "Usage: obex_test [options]\n" "\n" "Options:\n" " -f [flags] Set some flags: n=non-blocking\n" #ifdef HAVE_BLUETOOTH " -b [addr] [chan] Use bluetooth RFCOMM transport\n" #endif #ifdef HAVE_USB " -u [interface] Use USB transport\n" #endif " -i Use IP/TCP transport\n" " -h Print this help message\n" "\n" "If no transport is selected, IrDA is used.\n" ); return 0; } /* Read flags for OBEX_Init() */ if (argc >= i+1 && strcmp(argv[i], "-f") == 0) { ++i; if (argc >= i+1 && argv[i][0] != '-') { char *flag = argv[i++]; for (; *flag != 0; ++flag) switch(*flag) { case 'n': fprintf(stderr, "Using non-blocking mode\n"); flags |= OBEX_FL_NONBLOCK; break; default: fprintf(stderr, "Unknown flag %c\n", *flag); break; }; } } #ifdef HAVE_BLUETOOTH if (argc >= i+1 && strcmp(argv[i], "-b") == 0) btobex = 1; #endif #ifdef HAVE_USB if (argc >= i+1 && strcmp(argv[i], "-u") == 0) usbobex = TRUE; #endif if (argc == i+1 && strcmp(argv[i], "-i") == 0) tcpobex = TRUE; #ifdef HAVE_BLUETOOTH if (btobex) { const char *channel_arg = NULL; switch (argc-i) { case 3: str2ba(argv[i+1], &bdaddr); channel_arg = argv[i+2]; break; case 2: str2ba(argv[i+1], &bdaddr); if (bacmp(&bdaddr, BDADDR_ANY) == 0) channel_arg = argv[i+1]; break; case 1: bacpy(&bdaddr, BDADDR_ANY); break; default: printf("Wrong number of arguments\n"); exit(0); } switch (btobex) { case TRUE: printf("Using Bluetooth RFCOMM transport\n"); handle = OBEX_Init(OBEX_TRANS_BLUETOOTH, obex_event, flags); if (channel_arg) channel = (atoi(channel_arg) & 0xFF); else channel = BT_CHANNEL; break; } if (!handle) { perror( "OBEX_Init failed"); exit(0); } } else #endif #ifdef HAVE_USB if (usbobex) { int k, interfaces_number, intf_num; switch (argc-i) { case 1: printf("Using USB transport, " "querying available interfaces\n"); handle = OBEX_Init(OBEX_TRANS_USB, obex_event, flags); if (!handle) { perror( "OBEX_Init failed"); exit(0); } interfaces_number = OBEX_EnumerateInterfaces(handle); for (k = 0; k < interfaces_number; k++) { obex_intf = OBEX_GetInterfaceByIndex(handle, k); printf("Interface %d: idVendor: %#x, " "idProduct: %#x, bus %d, dev %d, " "intf %d, %s %s %s\n", k, obex_intf->usb.idVendor, obex_intf->usb.idProduct, obex_intf->usb.bus_number, obex_intf->usb.device_address, obex_intf->usb.interface_number, obex_intf->usb.manufacturer, obex_intf->usb.product, obex_intf->usb.control_interface); } printf("Use '%s -u interface_number' to run " "interactive OBEX test client\n", argv[0]); OBEX_Cleanup(handle); exit(0); break; case 2: intf_num = atoi(argv[i+1]); printf("Using USB transport \n"); handle = OBEX_Init(OBEX_TRANS_USB, obex_event, flags); if (!handle) { perror( "OBEX_Init failed"); exit(0); } interfaces_number = OBEX_EnumerateInterfaces(handle); if (intf_num >= interfaces_number) { printf( "Invalid interface number\n"); exit(0); } obex_intf = OBEX_GetInterfaceByIndex(handle, intf_num); break; default: printf("Wrong number of arguments\n"); exit(0); } } else #endif if (tcpobex) { printf("Using TCP transport\n"); handle = OBEX_Init(OBEX_TRANS_INET, obex_event, flags); if (!handle) { perror( "OBEX_Init failed"); exit(0); } } else { printf("Using IrDA transport\n"); handle = OBEX_Init(OBEX_TRANS_IRDA, obex_event, flags); if (!handle) { perror( "OBEX_Init failed"); exit(0); } } OBEX_SetUserData(handle, &global_context); printf( "OBEX Interactive test client/server.\n"); while (!end) { if (read_input(cmd, sizeof(cmd), "> ") < 0) break; switch(cmd[0]) { case 'h': printf("Commands:\n" " c - connect\n" " d - disconnect\n" " g - get\n" " p - put\n" " t - set path\n" " s - server\n" " x - push\n" " h - help\n" " q - quit\n" ); break; case 'q': end=1; break; case 'g': get_client(handle, &global_context); break; case 't': setpath_client(handle); break; case 'p': put_client(handle); break; case 'x': push_client(handle); break; case 'c': /* First connect transport */ #ifdef HAVE_BLUETOOTH if (btobex) { if (bacmp(&bdaddr, BDADDR_ANY) == 0) { printf("Device address error! (Bluetooth)\n"); break; } if (BtOBEX_TransportConnect(handle, BDADDR_ANY, &bdaddr, channel) <0) { printf("Transport connect error! (Bluetooth)\n"); break; } } else #endif #ifdef HAVE_USB if (usbobex) { if (OBEX_InterfaceConnect(handle, obex_intf) < 0) { printf("Transport connect error! (USB)\n"); break; } } else #endif if (tcpobex) { if (TcpOBEX_TransportConnect(handle, NULL, 0) < 0) { printf("Transport connect error! (TCP)\n"); break; } } else { if (IrOBEX_TransportConnect(handle, IR_SERVICE) < 0) { printf("Transport connect error! (IrDA)\n"); break; } } // Now send OBEX-connect. connect_client(handle); break; case 'd': disconnect_client(handle); break; case 's': /* First register server */ #ifdef HAVE_BLUETOOTH if (btobex) { if (BtOBEX_ServerRegister(handle, BDADDR_ANY, channel) < 0) { printf("Server register error! (Bluetooth)\n"); break; } } else #endif #ifdef HAVE_USB if (usbobex) { printf("Transport not found! (USB)\n"); } else #endif if (tcpobex) { if (TcpOBEX_ServerRegister(handle, NULL, 0) < 0) { printf("Server register error! (TCP)\n"); break; } } else { if (IrOBEX_ServerRegister(handle, IR_SERVICE) < 0) { printf("Server register error! (IrDA)\n"); break; } } /* No process server events */ server_do(handle); OBEX_TransportDisconnect(handle); break; default: printf("Unknown command %s\n", cmd); } } return 0; } openobex-1.7.2-Source/apps/CMakeLists.txt000644 001750 001750 00000002310 12604171661 021413 0ustar00hendrikhendrik000000 000000 add_subdirectory ( lib ) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/lib ) add_subdirectory ( obex_test ) add_subdirectory ( ircp ) set ( OPENOBEX_COMMON_APPS irxfer irobex_palm3 ) set ( OPENOBEX_APPS obex_find ) if ( NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" ) #obex_tcp uses functions that are only available #under Windows7, so we do not compile for now. list ( APPEND OPENOBEX_COMMON_APPS obex_tcp ) endif ( NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" ) foreach ( prog ${OPENOBEX_COMMON_APPS} ) list ( APPEND ${prog}_LIBS openobex-apps-common ) list ( APPEND OPENOBEX_APPS ${prog} ) endforeach ( prog ) foreach ( prog ${OPENOBEX_APPS} ) set ( ${prog}_SOURCES ${prog}.c ) list ( APPEND ${prog}_LIBS openobex ) endforeach ( prog ) if ( WIN32 ) list ( APPEND obex_tcp_LIBS ws2_32 ) endif ( WIN32 ) foreach ( prog ${OPENOBEX_APPS} ) add_executable ( ${prog} EXCLUDE_FROM_ALL ${${prog}_SOURCES} ) target_link_libraries ( ${prog} ${${prog}_LIBS} ) install ( PROGRAMS $ DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT applications OPTIONAL ) endforeach ( prog ) add_dependencies ( openobex-apps ${OPENOBEX_APPS} ) openobex-1.7.2-Source/apps/irobex_palm3.c000644 001750 001750 00000006261 11734661776 021432 0ustar00hendrikhendrik000000 000000 /** \file apps/irobex_palm3.c Demonstrates use of PUT command. OpenOBEX test applications and sample code. Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenOBEX. If not, see . */ /* The Palm 3 always sends a HEADER_CREATORID (0xcf). Start without arguments to receive a file. Start with filename as argument to send a file. */ #ifdef HAVE_CONFIG_H #include #endif #include #include "obex_put_common.h" #include "obex_io.h" #include #include #ifndef _WIN32 #include #include #endif #define TRUE 1 #define FALSE 0 obex_t *handle = NULL; volatile int finished = FALSE; extern int last_rsp; /* * Function usage (void) */ static int usage(char *argv[]) { printf ("Usage: %s [-h id] [name]\n", argv[0]); printf (" where id is the header_creator_id (default: memo)\n"); return -1; } /* * Function main (argc, ) * * Starts all the fun! * */ int main(int argc, char *argv[]) { obex_object_t *object; int ret, exitval = EXIT_SUCCESS; uint32_t creator_id = 0; printf("Send and receive files to Palm3\n"); if ((argc < 1) || (argc > 4)) { return usage(argv); } handle = OBEX_Init(OBEX_TRANS_IRDA, obex_event, 0); if (argc == 1) { /* We are server*/ printf("Waiting for files\n"); IrOBEX_ServerRegister(handle, "OBEX"); while (!finished) OBEX_HandleInput(handle, 1); } else { /* We are a client */ /* Check for parameters */ if(argc > 2) { if(strcmp("-h", argv[1]) || strlen(argv[2]) != 4) return usage(argv); creator_id = argv[2][0] << 24 | argv[2][1] << 16 | argv[2][2] << 8 | argv[2][3]; printf("debug: %s %d;", argv[2], creator_id); } /* Try to connect to peer */ ret = IrOBEX_TransportConnect(handle, "OBEX"); if (ret < 0) { printf("Sorry, unable to connect!\n"); return EXIT_FAILURE; } object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT); ret = do_sync_request(handle, object, FALSE); if ((last_rsp != OBEX_RSP_SUCCESS) || (ret < 0)) { printf("Sorry, unable to connect!\n"); return EXIT_FAILURE; } if ((object = build_object_from_file(handle, argv[(creator_id ? 3 : 1)], creator_id))) { ret = do_sync_request(handle, object, FALSE); if ((last_rsp != OBEX_RSP_SUCCESS) || (ret < 0)) exitval = EXIT_FAILURE; } else exitval = EXIT_FAILURE; object = OBEX_ObjectNew(handle, OBEX_CMD_DISCONNECT); ret = do_sync_request(handle, object, FALSE); if ((last_rsp != OBEX_RSP_SUCCESS) || (ret < 0)) exitval = EXIT_FAILURE; if (exitval == EXIT_SUCCESS) printf("PUT successful\n"); else printf("PUT failed\n"); } // sleep(1); return exitval; } openobex-1.7.2-Source/apps/irxfer.c000644 001750 001750 00000004520 11734661776 020341 0ustar00hendrikhendrik000000 000000 /** \file apps/irxfer.c Send and receive files using IRDA. OpenOBEX test applications and sample code. Copyright (c) 1999, 2000 Fons Botman, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenOBEX. If not, see . */ /* Based on irobex_palm3.c Start without arguments to receive a file. Start with filename as argument to send a file. */ #ifdef HAVE_CONFIG_H #include #endif #include #include "obex_put_common.h" #include "obex_io.h" #ifdef _WIN32 #include #define sleep(sec) Sleep(1000*sec) #endif #include #include #include #define TRUE 1 #define FALSE 0 volatile int finished = FALSE; obex_t *handle = NULL; /* * Function main (argc, argv) * * Starts all the fun! * */ int main(int argc, char *argv[]) { obex_object_t *object; int ret; if ((argc < 1) || (argc > 2) ) { printf ("Usage: %s [name]\n", argv[0]); return -1; } handle = OBEX_Init(OBEX_TRANS_IRDA, obex_event, 0); obex_protocol_type = OBEX_PROTOCOL_WIN95_IRXFER; if (argc == 1) { /* We are server */ printf("Waiting for files\n"); IrOBEX_ServerRegister(handle, "OBEX:IrXfer"); while (!finished) { OBEX_HandleInput(handle, 1); } } else { /* We are a client */ /* Try to connect to peer */ ret = IrOBEX_TransportConnect(handle, "OBEX:IrXfer"); if (ret < 0) { printf("Sorry, unable to connect!\n"); exit(ret); } object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT); ret = do_sync_request(handle, object, 0); if( (object = build_object_from_file(handle, argv[1], 0)) ) { ret = do_sync_request(handle, object, 0); } else { perror("PUT failed"); } object = OBEX_ObjectNew(handle, OBEX_CMD_DISCONNECT); ret = do_sync_request(handle, object, 0); printf("PUT successful\n"); sleep(3); } return 0; } openobex-1.7.2-Source/apps/obex_find.c000644 001750 001750 00000007132 12114410520 020745 0ustar00hendrikhendrik000000 000000 /** \file apps/obex_find.c * Find connectable OBEX devices (IrDA, USB). * OpenOBEX test applications and sample code. * * Copyright (c) 2010 Hendrik Sattler * * OpenOBEX is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with OpenOBEX. If not, see . */ #define _XOPEN_SOURCE 500 #include #include #include #include #include #ifdef _WIN32 #define strcasecmp _stricmp #else #include #endif static int verbose = 0; static void obex_event_cb(obex_t *handle, obex_object_t *obj, int mode, int event, int obex_cmd, int obex_rsp) { } static void usb_print(obex_interface_t *intf) { if (verbose > 0) { printf("\tPath: %d:%d:%d\n", intf->usb.bus_number, intf->usb.device_address, intf->usb.interface_number); printf("\tManufacturer: %s (%04x)\n", intf->usb.manufacturer, intf->usb.idVendor); printf("\tProduct: %s (%04x)\n", intf->usb.product, intf->usb.idProduct); } else { printf("\tManufacturer: %s\n", intf->usb.manufacturer); printf("\tProduct: %s\n", intf->usb.product); } printf("\tSerial: %s\n", intf->usb.serial); printf("\tDescription: %s\n", intf->usb.control_interface); } static void irda_print(obex_interface_t *intf) { const char* charsets[] = { "ASCII", "ISO-8859-1", "ISO-8859-2", "ISO-8859-3", "ISO-8859-4", "ISO-8859-5", "ISO-8859-6", "ISO-8859-7", "ISO-8859-8", "ISO-8859-9", }; const char *charset = ""; if (intf->irda.local) printf("\tLocal address: %08x\n", intf->irda.local); printf("\tRemote address: %08x\n", intf->irda.remote); if (intf->irda.charset == 0xFF) { charset = "Unicode"; } else if (intf->irda.charset < sizeof(charsets)/sizeof(charsets[0])) { charset = charsets[intf->irda.charset]; } printf("\tDescription character set: %s\n", charset); if (intf->irda.charset == 0x00) printf("\tDescription: %s\n", intf->irda.info); } static void find_devices(int trans, int flags) { obex_t *handle; int found; int i = 0; const char *descr = NULL; void (*trans_print)(obex_interface_t *); switch (trans) { case OBEX_TRANS_IRDA: descr = "irda"; trans_print = irda_print; break; case OBEX_TRANS_USB: descr = "usb"; trans_print = usb_print; break; default: return; } handle = OBEX_Init(trans, obex_event_cb, flags); found = OBEX_EnumerateInterfaces(handle); printf("Found %d %s devices.\n", found, descr); for (; i < found; ++i) { obex_interface_t *intf = OBEX_GetInterfaceByIndex(handle, i); printf("Device %d:\n", i); trans_print(intf); } OBEX_Cleanup(handle); } int main (int argc, char **argv) { int t = 1; char *default_argv[] = { argv[0], "-f", "irda", "usb", "bt", NULL }; int flags = 0; if (argc < 2) argv = default_argv; for (; argv[t] != NULL; ++t) { if (0 == strcmp(argv[t], "-v")) ++verbose; else if (0 == strcmp(argv[t], "-f")) flags |= OBEX_FL_FILTERHINT; else if (0 == strcasecmp(argv[t], "irda")) find_devices(OBEX_TRANS_IRDA, flags); else if (0 == strcasecmp(argv[t], "usb")) find_devices(OBEX_TRANS_USB, flags); } return 0; } openobex-1.7.2-Source/apps/obex_tcp.c000644 001750 001750 00000006354 12701163531 020631 0ustar00hendrikhendrik000000 000000 /** \file apps/obex_tcp.c Do an OBEX PUT over TCP. OpenOBEX test applications and sample code. Copyright (c) 1999 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #define _XOPEN_SOURCE 520 #define _POSIX_C_SOURCE 201112L // for getaddrinfo() #ifdef _WIN32 #include #define in_addr_t unsigned long #else #include #include #include #include #include #include #include #endif /* _WIN32 */ #include #include "obex_put_common.h" #include "obex_io.h" #include #include #include #define TRUE 1 #define FALSE 0 obex_t *handle = NULL; volatile int finished = FALSE; static int get_peer_addr(char *name, struct sockaddr_storage *peer) { struct addrinfo hint = { .ai_family = AF_UNSPEC, .ai_socktype = SOCK_STREAM, .ai_protocol = 0, #if defined(AI_ADDRCONFIG) .ai_flags = AI_ADDRCONFIG #endif }; struct addrinfo *info; int err = getaddrinfo(name, NULL, &hint, &info); if (err) return err; memcpy(peer, info->ai_addr, info->ai_addrlen); freeaddrinfo(info); return 0; } /* * Function main (argc, ) * * Starts all the fun! * */ int main(int argc, char *argv[]) { struct sockaddr_storage peer; obex_object_t *object; int ret; printf("Send and receive files over TCP OBEX\n"); if ( ((argc < 3) || (argc > 3)) && (argc != 1) ) { printf ("Usage: %s [name] [peer]\n", argv[0]); return -1; } handle = OBEX_Init(OBEX_TRANS_INET, obex_event, 0); if (argc == 1) { printf("Waiting for files\n"); ret = TcpOBEX_ServerRegister(handle, NULL, 0); if(ret < 0) { printf("Cannot listen to socket\n"); exit(ret); } while (!finished) { ret = OBEX_HandleInput(handle, 10); if (ret == 0) { printf("Timeout waiting for connection\n"); break; } else if (ret < 0) { printf("Error waiting for connection\n"); break; } } } else { /* We are a client */ ret = get_peer_addr(argv[2], &peer); if (ret) { perror("Bad name"); exit(1); } ret = TcpOBEX_TransportConnect(handle, (struct sockaddr *) &peer, sizeof(peer)); if (ret < 0) { printf("Sorry, unable to connect!\n"); exit(1); } object = OBEX_ObjectNew(handle, OBEX_CMD_CONNECT); ret = do_sync_request(handle, object, 0); if( (object = build_object_from_file(handle, argv[1], 0)) ) { ret = do_sync_request(handle, object, 0); } else { perror("PUT failed"); } object = OBEX_ObjectNew(handle, OBEX_CMD_DISCONNECT); ret = do_sync_request(handle, object, 0); printf("PUT successful\n"); } return 0; } openobex-1.7.2-Source/doc/000755 001750 001750 00000000000 12701534273 016461 5ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/doc/Doxyfile.in000644 001750 001750 00000002627 12110201575 020571 0ustar00hendrikhendrik000000 000000 DOXYFILE_ENCODING = ASCII PROJECT_NAME = OpenOBEX PROJECT_NUMBER = @VERSION@ OUTPUT_DIRECTORY = @top_builddir@/doc ABBREVIATE_BRIEF = "The $name class" \ "The $name widget" \ "The $name file" \ is \ provides \ specifies \ contains \ represents \ a \ an \ the FULL_PATH_NAMES = NO JAVADOC_AUTOBRIEF = YES QT_AUTOBRIEF = YES OPTIMIZE_OUTPUT_FOR_C = YES MARKDOWN_SUPPORT = NO EXTRACT_ALL = YES EXTRACT_LOCAL_CLASSES = NO INPUT = @DOC_SOURCE_FILES@ INPUT_ENCODING = ASCII FILE_PATTERNS = *.c *.h EXAMPLE_PATTERNS = * VERBATIM_HEADERS = NO ALPHABETICAL_INDEX = NO GENERATE_HTML = @DOC_HTML_OUTPUT@ SEARCHENGINE = NO GENERATE_LATEX = @DOC_LATEX_OUTPUT@ ENABLE_PREPROCESSING = YES MACRO_EXPANSION = YES EXPAND_ONLY_PREDEF = YES PREDEFINED = "LIB_SYMBOL=" \ "CALLAPI=" \ "OPENOBEX_SYMBOL(retval)=retval" \ HAVE_IRDA \ HAVE_USB \ HAVE_USB1 \ HAVE_BLUETOOTH openobex-1.7.2-Source/doc/openobex.coverpage000644 001750 001750 00000020112 12110201575 022157 0ustar00hendrikhendrik000000 000000 /** \mainpage \section legal_sec Legal notice OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . \section intro_sec Introduction This library tries to implement a generic OBEX Session Protocol. It does not implement the OBEX Application FrameWork. When you read this it's very useful to have a copy of the OBEX specification. It was available for download on IrDA's website http://www.irda.org. Make sure you have obex.h and obex_const.h, too. You might also find the OpenOBEX test applications useful. \section programming_sec Programming the library \subsection preparations_sec Preparations To be able to use the OpenOBEX API you must include the files openobex/obex_const.h and openobex/obex.h. First of all you must create an OBEX instance by calling #OBEX_Init. In this call you specify what transport you want to use, an event callback, and optional flags. #OBEX_Init will return a handle which shall be passed to almost all other functions. To let the parser do some work you must call #OBEX_Work. It will block for at-most the specified timeout for read and write actions. You can call #OBEX_GetFD if you want to do select() yourself (this may not work with all transports). \subsection callback_sec The event callback The event callback shall be a function with the #obex_event_t prototype: \code void my_obex_event(obex_t *handle, obex_object_t *obj, int obex_mode, int obex_event, int obex_cmd, int obex_rsp) \endcode Arguments: - handle : OBEX handle - obj : OBEX object - mode : OBEX_MODE_CLIENT for client event or OBEX_MODE_SERVER, for server event - event : The event. See obex_const.h for possible events (OBEX_EV_*) - obex_cmd : Command if any (depending on event type). See obex_const.h for commands (OBEX_CMD_*) - obex_rsp : Response if any (depending on event type). See obex_const.h for responses (OBEX_RSP_*) To this function events from the library will be passed to you, for example when an operation finishes. #OBEX_SetUserData and #OBEX_GetUserData are useful if you need to access your own private data from inside the event callback. \subsection client_sec Client Operations First of all you must connect the transport. For this you can use the discovery API by calling functions in the following order: - #OBEX_EnumerateInterfaces - #OBEX_GetInterfaceByIndex - #OBEX_InterfaceConnect This is supported for USB and IrDA (bluetooth not implemented, yet). Instead of the discovery API, you can also use the generic #OBEX_TransportConnect or one of the specialized: - #TcpOBEX_TransportConnect - #IrOBEX_TransportConnect - #BtOBEX_TransportConnect - #FdOBEX_TransportSetup. When the transport is connected you shall most likely also send an OBEX Connect to let the library negotiate MTU etc. OBEX Connect is sent as any other OBEX command. When you are done sending your requests you shall end by sending an OBEX Disconnect request and then call #OBEX_TransportDisconnect. To send a request to you must first create an OBEX Object by calling #OBEX_ObjectNew with the command opcode as argument. Next you add headers to it using #OBEX_ObjectAddHeader. Finally you send away the request using #OBEX_Request. When the request has finished you'll get an #OBEX_EV_REQDONE event. You can get any headers sent in response (like in a OBEX Get) by calling #OBEX_ObjectGetNextHeader. A Put would look something like this: \subsubsection putexample_sec OBEX Put example \code obex_object_t *object; obex_headerdata_t hd; object = OBEX_ObjectNew(handle, OBEX_CMD_PUT); if(object == NULL) { /* Error */ } /* Add length header */ hd.bq4 = body_size; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_LENGTH, hd, 4, 0); /* Add unicode name header*/ hdd.bs = unicodename; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_NAME, hd, name_size, 0); /* Add body header*/ hd.bs = body; OBEX_ObjectAddHeader(handle, object, OBEX_HDR_BODY, hd, body_size, 0); if(OBEX_Request(handle, object) < 0) { /* Error */ } \endcode \subsection server_sec Server Operations To act as a server you must first tell the transport to receive incoming connections via the generic function #OBEX_ServerRegister or one of the specialized: - #TcpOBEX_ServerRegister - #IrOBEX_ServerRegister - #BtOBEX_ServerRegister. When an incoming connection is coming you'll get an #OBEX_EV_ACCEPTHINT event. If you ignore this event no more incoming connections will be accepted but if you call #OBEX_ServerAccept, you'll get back a new OBEX handle and the old handle will still be listening to connections. When an incoming request comes, you will first get an #OBEX_EV_REQHINT event. The supplied OBEX object is allocated by the library so you do not need to create it yourself. The #OBEX_EV_REQHINT event comes before the parser start receiving the request, so you can cancel requests that your application does not support early. Set the response to the request using #OBEX_ObjectSetRsp. The #OBEX_EV_REQCHECK event allows to check non-header data and non-body headers. This is only called for multi-packet messages. You can tell the parser to deliver the body-header as a stream either at the time of #OBEX_EV_REQHINT or #OBEX_EV_REQCHECK using #OBEX_ObjectReadStream. If you use the latter event, you must support non-stream mode, too. When the request is received you'll get an #OBEX_EV_REQ event. Get the headers from the object by calling #OBEX_ObjectGetNextHeader. You can now change the response if you decide to reject the request. Add any headers you want in the response here too. When your response is successfully sent you'll get an #OBEX_EV_REQDONE event. After you have received and answered an OBEX Disconnect request you shall call #OBEX_TransportDisconnect. \subsubsection callbackexample_sec Event callback of a typical server \code switch (event) { case OBEX_EV_REQ: /* An incoming request */ switch(obex_cmd) { case OBEX_CMD_CONNECT: case OBEX_CMD_DISCONNECT: /* Dont need to do anything here. Response is already set to success by OBEX_EV_REQHINT event */ break; case OBEX_CMD_PUT: deliver_put_to_app(object); break; } break; case OBEX_EV_REQHINT: /* A new request is coming in */ switch(obex_cmd) { /* Accept xome commands! */ case OBEX_CMD_PUT: case OBEX_CMD_CONNECT: case OBEX_CMD_DISCONNECT: OBEX_ObjectSetRsp(object, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS); break; default: /* Reject any other commands */ OBEX_ObjectSetRsp(object, OBEX_RSP_NOT_IMPLEMENTED, OBEX_RSP_NOT_IMPLEMENTED); break; } break; case OBEX_EV_REQDONE: if(obex_cmd == OBEX_CMD_DISCONNECT) { /* Disconnect transport here */ } break; case OBEX_EV_LINKERR: /* Not good */ break; default: break; } \endcode \section apiref_sec API Reference See: lib/obex.c, include/openobex/obex.h, include/openobex/obex_const.h. \section contact_sec Authors and Contact Authors and major contributors: - Dag Brattli - Pontus Fuchs - Jean Tourrilhes - Marcel Holtmann - Dmitry Kasatkin - Christian W. Zuckschwerdt - Herton Ronaldo Krzesinski - Alex Kanavin - Johan Hedberg - Hendrik Sattler See: - http://dev.zuckschwerdt.org/openobex/ - http://openobex.sourceforge.net/ - http://sourceforge.net/tracker/?group_id=8960 - http://sourceforge.net/forum/?group_id=8960 */ openobex-1.7.2-Source/doc/ircp.xml000644 001750 001750 00000003667 12116463723 020155 0ustar00hendrikhendrik000000 000000 openobex ircp 1 User commands ircp send or receive files via infrared connection ircp ircp file... Description ircp is a small utility to transfer files from or to a remote Linux machine, Windows computer, or various PDAs by using an infrared (IrDA) port. It is designed for working e.g. with Quickbeam. This program is designed to be an example application for the openobex library. Options Use ircp to receive files. If destination is given, the received files are stored in that directory; if not, the files are copied to your current directory. If this options is not given, the specified files are sent See also irobex_palm3(1), irxfer(1) openobex-1.7.2-Source/doc/irobex_palm3.xml000644 001750 001750 00000003555 12116463723 021600 0ustar00hendrikhendrik000000 000000 openobex irobex_palm3 1 User commands irobex_palm3 Send to or receive files from a Palm handheld device irobex_palm3 file... Description irobex_palm3 is a small utility to transfer files from or to a Palm handheld device by using an infrared (IrDA) port. If no parameter is specified, the program goes into receive mode. This program is designed to be an example application for the openobex library. Options Choose a creator ID, e.g. "memo", "addr", "todo", "date" or "Inch". The id must be exactly 4 characters long and serves as hint for the remote device and thus may be case-sensitive. The default is "memo". See also ircp(1), irxfer(1) openobex-1.7.2-Source/doc/irxfer.xml000644 001750 001750 00000002426 12116463723 020507 0ustar00hendrikhendrik000000 000000 openobex irxfer 1 User commands irxfer Send to or receive files from a Palm handheld device irxfer file Description irxfer is a small utility to transfer files by using an infrared (IrDA) port. It uses the "OBEX:IrXfer" identifier. If no parameter is specified, the program goes into receive mode. This program is designed to be an example application for the openobex library. See also ircp(1), irobex_palm3(1) openobex-1.7.2-Source/doc/obex_find.xml000644 001750 001750 00000002346 12116463723 021146 0ustar00hendrikhendrik000000 000000 openobex obex_find 1 User commands obex_find Find connectable OBEX devices (IrDA, USB). obex_find Description obex_tcp is a small utility to find devices that support OBEX. If no transport is specified, all OpenOBEX transports that have search capability are tried. Currently, supported transports are "irda" and "usb". This program is designed to be an example application for the openobex library. openobex-1.7.2-Source/doc/obex_tcp.xml000644 001750 001750 00000002341 12116463723 021007 0ustar00hendrikhendrik000000 000000 openobex obex_tcp 1 User commands obex_tcp Send or receive files via TCP obex_tcp file target Description obex_tcp is a small utility to transfer files from or to a remote machine. The target is either an IPv4 numeric address or a hostname. If no parameter is specified, the program goes into receive mode. This program is designed to be an example application for the openobex library. openobex-1.7.2-Source/doc/obex_test.xml000644 001750 001750 00000011331 12116463723 021177 0ustar00hendrikhendrik000000 000000 openobex obex_test 1 User commands obex_test interactive test application for the openobex library obex_test port port address channel interface Description obex_test is a test application for the openobex library. It uses an interactive mode but the access method is selcted with command line arguments. This program is designed to be an example application for the openobex library. Options This is the default. It selects cable obex. The port argument is optional (default: /dev/ttyS0) Select cable obex for the Ericsson R320 mobile phone. The port argument is optional (default: /dev/ttyS0) Select obex over IrDA. Select obex over bluetooth. Both, address and channel are actually optional. Default channel is 4, default address is ANY. Select usb obex (CDC). If the interface argument is omitted, a list of available interface is written to stdout. Interactive Mode: Commands connect to the remote side (client mode) disconnect from the remote side issue a GET request issue a PUT request quit the program go into server mode change the path on the remote side issue a PUSH request openobex-1.7.2-Source/doc/openobex-apps.xml000644 001750 001750 00000001606 12116463723 021767 0ustar00hendrikhendrik000000 000000 openobex openobex-1.7.2-Source/doc/referenceinfo.xml.in000644 001750 001750 00000001061 12116463736 022425 0ustar00hendrikhendrik000000 000000 openobex @VERSION@ Hendrik Sattler initial version of manpage post@hendrik-sattler.de openobex-1.7.2-Source/doc/CMakeLists.txt000644 001750 001750 00000007504 12604167677 021243 0ustar00hendrikhendrik000000 000000 add_custom_target ( doc ) set ( SOURCES "${CMAKE_SOURCE_DIR}/lib/api.c" "${CMAKE_SOURCE_DIR}/include/openobex/obex.h" "${CMAKE_SOURCE_DIR}/include/openobex/obex_const.h" "${CMAKE_SOURCE_DIR}/doc/openobex.coverpage" ) find_package( Doxygen ) if ( DOXYGEN_FOUND ) set ( DOC_OUTPUT_TYPES HTML LATEX ) set ( DOC_HTML_OUTPUT_FILE "index.html" ) set ( DOC_LATEX_OUTPUT_FILE "refman.tex" ) foreach ( type ${DOC_OUTPUT_TYPES} ) foreach ( i ${DOC_OUTPUT_TYPES} ) set ( DOC_${i}_OUTPUT "NO" ) endforeach ( i ) set ( DOC_${type}_OUTPUT "YES" ) foreach ( src ${SOURCES} ) set ( DOC_SOURCE_FILES "${DOC_SOURCE_FILES} ${src}" ) endforeach ( src ) configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_${type} @ONLY ) if ( DOC_${type}_OUTPUT_FILE ) string ( TOLOWER "${type}" type_low ) set ( DOC_${type}_OUTPUT_FILE_ABS "${CMAKE_CURRENT_BINARY_DIR}/${type_low}/${DOC_${type}_OUTPUT_FILE}" ) add_custom_command ( OUTPUT "${DOC_${type}_OUTPUT_FILE_ABS}" COMMAND "${DOXYGEN_EXECUTABLE}" "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_${type}" DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_${type}" ${SOURCES} VERBATIM ) add_custom_target ( apidoc_${type_low} DEPENDS ${DOC_${type}_OUTPUT_FILE_ABS} ) endif ( DOC_${type}_OUTPUT_FILE ) endforeach ( type ) set_directory_properties ( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "html;latex" ) add_dependencies ( openobex apidoc_html ) add_dependencies ( doc apidoc_html ) install ( DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/html" DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT documentation ) endif ( DOXYGEN_FOUND ) find_package ( Docbook ) if ( Docbook_FOUND ) include ( ${Docbook_USE_FILE} ) if ( UNIX ) option (BUILD_APPS_HELP_MAN "Build manpage application help files" ON) option (BUILD_APPS_HELP_HTML "Build HTML application help files" OFF) else ( UNIX ) option (BUILD_APPS_HELP_HTML "Build HTML application help files" ON) endif ( UNIX ) configure_file ( referenceinfo.xml.in referenceinfo.xml @ONLY ) set ( OPENOBEX_APP_XML_FILE "${CMAKE_CURRENT_SOURCE_DIR}/openobex-apps.xml" ) list ( APPEND XMLLINT_OPTIONS --path "${CMAKE_CURRENT_BINARY_DIR}" ) list ( APPEND XSLT_XSLTPROC_OPTIONS --path "${CMAKE_CURRENT_BINARY_DIR}" ) if ( BUILD_APPS_HELP_MAN ) docbook_generate ( manpage "${OPENOBEX_APP_XML_FILE}" XSLT_FILES_MAN ) foreach ( file ${XSLT_FILES_MAN} ) list ( APPEND OPENOBEX_HELP_FILES ${file} ) get_filename_component ( fileExt ${file} EXT ) string ( REGEX REPLACE "^[.]" "" fileExt ${fileExt} ) install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/${file} DESTINATION ${CMAKE_INSTALL_MANDIR}/man${fileExt} PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT documentation OPTIONAL ) endforeach ( file ) endif ( BUILD_APPS_HELP_MAN ) if ( BUILD_APPS_HELP_HTML ) docbook_generate ( html "${OPENOBEX_APP_XML_FILE}" XSLT_FILES_HTML ) foreach ( file ${XSLT_FILES_HTML} ) list ( APPEND OPENOBEX_HELP_FILES ${file} ) install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/${file} DESTINATION ${CMAKE_INSTALL_DOCDIR} PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ COMPONENT documentation OPTIONAL ) endforeach ( file ) endif ( BUILD_APPS_HELP_HTML ) if ( OPENOBEX_HELP_FILES ) add_custom_target ( openobex-apps-doc DEPENDS ${OPENOBEX_HELP_FILES} ) add_dependencies ( openobex-apps openobex-apps-doc ) add_dependencies ( doc openobex-apps-doc ) endif ( OPENOBEX_HELP_FILES ) endif ( Docbook_FOUND ) openobex-1.7.2-Source/include/000755 001750 001750 00000000000 12701534273 017337 5ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/include/linux/000755 001750 001750 00000000000 12701534273 020476 5ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/include/linux/irda.h000644 001750 001750 00000013620 11612777701 021575 0ustar00hendrikhendrik000000 000000 /** \file irda.h IrDA header file to be used by IrDA applications. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenOBEX. If not, see . */ #ifndef IRDA_H #define IRDA_H #include #include /* Hint bit positions for first hint byte */ #define HINT_PNP 0x01 #define HINT_PDA 0x02 #define HINT_COMPUTER 0x04 #define HINT_PRINTER 0x08 #define HINT_MODEM 0x10 #define HINT_FAX 0x20 #define HINT_LAN 0x40 #define HINT_EXTENSION 0x80 /* Hint bit positions for second hint byte (first extension byte) */ #define HINT_TELEPHONY 0x01 #define HINT_FILE_SERVER 0x02 #define HINT_COMM 0x04 #define HINT_MESSAGE 0x08 #define HINT_HTTP 0x10 #define HINT_OBEX 0x20 /* IrLMP character code values */ #define CS_ASCII 0x00 #define CS_ISO_8859_1 0x01 #define CS_ISO_8859_2 0x02 #define CS_ISO_8859_3 0x03 #define CS_ISO_8859_4 0x04 #define CS_ISO_8859_5 0x05 #define CS_ISO_8859_6 0x06 #define CS_ISO_8859_7 0x07 #define CS_ISO_8859_8 0x08 #define CS_ISO_8859_9 0x09 #define CS_UNICODE 0xff /* These are the currently known dongles */ typedef enum { IRDA_TEKRAM_DONGLE = 0, IRDA_ESI_DONGLE = 1, IRDA_ACTISYS_DONGLE = 2, IRDA_ACTISYS_PLUS_DONGLE = 3, IRDA_GIRBIL_DONGLE = 4, IRDA_LITELINK_DONGLE = 5, IRDA_AIRPORT_DONGLE = 6, IRDA_OLD_BELKIN_DONGLE = 7, } IRDA_DONGLE; /* Protocol types to be used for SOCK_DGRAM */ enum { IRDAPROTO_UNITDATA = 0, IRDAPROTO_ULTRA = 1, IRDAPROTO_MAX }; #define SOL_IRLMP 266 /* Same as SOL_IRDA for now */ #define SOL_IRTTP 266 /* Same as SOL_IRDA for now */ #define IRLMP_ENUMDEVICES 1 /* Return discovery log */ #define IRLMP_IAS_SET 2 /* Set an attribute in local IAS */ #define IRLMP_IAS_QUERY 3 /* Query remote IAS for attribute */ #define IRLMP_HINTS_SET 4 /* Set hint bits advertised */ #define IRLMP_QOS_SET 5 #define IRLMP_QOS_GET 6 #define IRLMP_MAX_SDU_SIZE 7 #define IRLMP_IAS_GET 8 /* Get an attribute from local IAS */ #define IRLMP_IAS_DEL 9 /* Remove attribute from local IAS */ #define IRLMP_HINT_MASK_SET 10 /* Set discovery filter */ #define IRLMP_WAITDEVICE 11 /* Wait for a new discovery */ #define IRTTP_MAX_SDU_SIZE IRLMP_MAX_SDU_SIZE /* Compatibility */ /* LM-IAS Limits */ #define IAS_MAX_STRING 256 #define IAS_MAX_OCTET_STRING 1024 #define IAS_MAX_CLASSNAME 64 #define IAS_MAX_ATTRIBNAME 256 /* LM-IAS Attribute types */ #define IAS_MISSING 0 #define IAS_INTEGER 1 #define IAS_OCT_SEQ 2 #define IAS_STRING 3 #define LSAP_ANY 0xff struct sockaddr_irda { sa_family_t sir_family; /* AF_IRDA */ uint8_t sir_lsap_sel; /* LSAP selector */ uint32_t sir_addr; /* Device address */ char sir_name[25]; /* Usually :IrDA:TinyTP */ }; struct irda_device_info { uint32_t saddr; /* Address of local interface */ uint32_t daddr; /* Address of remote device */ char info[22]; /* Description */ uint8_t charset; /* Charset used for description */ uint8_t hints[2]; /* Hint bits */ }; struct irda_device_list { uint32_t len; struct irda_device_info dev[1]; }; struct irda_ias_set { char irda_class_name[IAS_MAX_CLASSNAME]; char irda_attrib_name[IAS_MAX_ATTRIBNAME]; unsigned int irda_attrib_type; union { unsigned int irda_attrib_int; struct { unsigned short len; uint8_t octet_seq[IAS_MAX_OCTET_STRING]; } irda_attrib_octet_seq; struct { uint8_t len; uint8_t charset; uint8_t string[IAS_MAX_STRING]; } irda_attrib_string; } attribute; uint32_t daddr; /* Address of device (for IAS query only) */ }; /* Some private IOCTL's (max 16) */ #define SIOCSDONGLE (SIOCDEVPRIVATE + 0) #define SIOCGDONGLE (SIOCDEVPRIVATE + 1) #define SIOCSBANDWIDTH (SIOCDEVPRIVATE + 2) #define SIOCSMEDIABUSY (SIOCDEVPRIVATE + 3) #define SIOCGMEDIABUSY (SIOCDEVPRIVATE + 4) #define SIOCGRECEIVING (SIOCDEVPRIVATE + 5) #define SIOCSMODE (SIOCDEVPRIVATE + 6) #define SIOCGMODE (SIOCDEVPRIVATE + 7) #define SIOCSDTRRTS (SIOCDEVPRIVATE + 8) #define SIOCGQOS (SIOCDEVPRIVATE + 9) /* No reason to include just because of this one ;-) */ #define IRNAMSIZ 16 /* IrDA quality of service information (must not exceed 16 bytes) */ struct if_irda_qos { uint32_t baudrate; uint16_t data_size; uint16_t window_size; uint16_t min_turn_time; uint16_t max_turn_time; uint8_t add_bofs; uint8_t link_disc; }; /* For setting RTS and DTR lines of a dongle */ struct if_irda_line { uint8_t dtr; uint8_t rts; }; /* IrDA interface configuration (data part must not exceed 16 bytes) */ struct if_irda_req { union { char ifrn_name[IRNAMSIZ]; /* if name, e.g. "irda0" */ } ifr_ifrn; /* Data part */ union { struct if_irda_line ifru_line; struct if_irda_qos ifru_qos; unsigned short ifru_flags; unsigned int ifru_receiving; unsigned int ifru_mode; unsigned int ifru_dongle; } ifr_ifru; }; #define ifr_baudrate ifr_ifru.ifru_qos.baudrate #define ifr_receiving ifr_ifru.ifru_receiving #define ifr_dongle ifr_ifru.ifru_dongle #define ifr_mode ifr_ifru.ifru_mode #define ifr_dtr ifr_ifru.ifru_line.dtr #define ifr_rts ifr_ifru.ifru_line.rts #endif /* IRDA_H */ openobex-1.7.2-Source/include/msvc/000755 001750 001750 00000000000 12701534273 020307 5ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/include/msvc/inttypes.h000644 001750 001750 00000017504 11612777701 022353 0ustar00hendrikhendrik000000 000000 // ISO C9x compliant inttypes.h for Microsoft Visual Studio // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 // // Copyright (c) 2006 Alexander Chemeris // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // 3. The name of the author may be used to endorse or promote products // derived from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // /////////////////////////////////////////////////////////////////////////////// #ifndef _MSC_VER // [ #error "Use this header only with Microsoft Visual C++ compilers!" #endif // _MSC_VER ] #ifndef _MSC_INTTYPES_H_ // [ #define _MSC_INTTYPES_H_ #if _MSC_VER > 1000 #pragma once #endif #include // 7.8 Format conversion of integer types typedef struct { intmax_t quot; intmax_t rem; } imaxdiv_t; // 7.8.1 Macros for format specifiers #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 // The fprintf macros for signed integers are: #define PRId8 "d" #define PRIi8 "i" #define PRIdLEAST8 "d" #define PRIiLEAST8 "i" #define PRIdFAST8 "d" #define PRIiFAST8 "i" #define PRId16 "hd" #define PRIi16 "hi" #define PRIdLEAST16 "hd" #define PRIiLEAST16 "hi" #define PRIdFAST16 "hd" #define PRIiFAST16 "hi" #define PRId32 "I32d" #define PRIi32 "I32i" #define PRIdLEAST32 "I32d" #define PRIiLEAST32 "I32i" #define PRIdFAST32 "I32d" #define PRIiFAST32 "I32i" #define PRId64 "I64d" #define PRIi64 "I64i" #define PRIdLEAST64 "I64d" #define PRIiLEAST64 "I64i" #define PRIdFAST64 "I64d" #define PRIiFAST64 "I64i" #define PRIdMAX "I64d" #define PRIiMAX "I64i" #define PRIdPTR "Id" #define PRIiPTR "Ii" // The fprintf macros for unsigned integers are: #define PRIo8 "o" #define PRIu8 "u" #define PRIx8 "x" #define PRIX8 "X" #define PRIoLEAST8 "o" #define PRIuLEAST8 "u" #define PRIxLEAST8 "x" #define PRIXLEAST8 "X" #define PRIoFAST8 "o" #define PRIuFAST8 "u" #define PRIxFAST8 "x" #define PRIXFAST8 "X" #define PRIo16 "ho" #define PRIu16 "hu" #define PRIx16 "hx" #define PRIX16 "hX" #define PRIoLEAST16 "ho" #define PRIuLEAST16 "hu" #define PRIxLEAST16 "hx" #define PRIXLEAST16 "hX" #define PRIoFAST16 "ho" #define PRIuFAST16 "hu" #define PRIxFAST16 "hx" #define PRIXFAST16 "hX" #define PRIo32 "I32o" #define PRIu32 "I32u" #define PRIx32 "I32x" #define PRIX32 "I32X" #define PRIoLEAST32 "I32o" #define PRIuLEAST32 "I32u" #define PRIxLEAST32 "I32x" #define PRIXLEAST32 "I32X" #define PRIoFAST32 "I32o" #define PRIuFAST32 "I32u" #define PRIxFAST32 "I32x" #define PRIXFAST32 "I32X" #define PRIo64 "I64o" #define PRIu64 "I64u" #define PRIx64 "I64x" #define PRIX64 "I64X" #define PRIoLEAST64 "I64o" #define PRIuLEAST64 "I64u" #define PRIxLEAST64 "I64x" #define PRIXLEAST64 "I64X" #define PRIoFAST64 "I64o" #define PRIuFAST64 "I64u" #define PRIxFAST64 "I64x" #define PRIXFAST64 "I64X" #define PRIoMAX "I64o" #define PRIuMAX "I64u" #define PRIxMAX "I64x" #define PRIXMAX "I64X" #define PRIoPTR "Io" #define PRIuPTR "Iu" #define PRIxPTR "Ix" #define PRIXPTR "IX" // The fscanf macros for signed integers are: #define SCNd8 "d" #define SCNi8 "i" #define SCNdLEAST8 "d" #define SCNiLEAST8 "i" #define SCNdFAST8 "d" #define SCNiFAST8 "i" #define SCNd16 "hd" #define SCNi16 "hi" #define SCNdLEAST16 "hd" #define SCNiLEAST16 "hi" #define SCNdFAST16 "hd" #define SCNiFAST16 "hi" #define SCNd32 "ld" #define SCNi32 "li" #define SCNdLEAST32 "ld" #define SCNiLEAST32 "li" #define SCNdFAST32 "ld" #define SCNiFAST32 "li" #define SCNd64 "I64d" #define SCNi64 "I64i" #define SCNdLEAST64 "I64d" #define SCNiLEAST64 "I64i" #define SCNdFAST64 "I64d" #define SCNiFAST64 "I64i" #define SCNdMAX "I64d" #define SCNiMAX "I64i" #ifdef _WIN64 // [ # define SCNdPTR "I64d" # define SCNiPTR "I64i" #else // _WIN64 ][ # define SCNdPTR "ld" # define SCNiPTR "li" #endif // _WIN64 ] // The fscanf macros for unsigned integers are: #define SCNo8 "o" #define SCNu8 "u" #define SCNx8 "x" #define SCNX8 "X" #define SCNoLEAST8 "o" #define SCNuLEAST8 "u" #define SCNxLEAST8 "x" #define SCNXLEAST8 "X" #define SCNoFAST8 "o" #define SCNuFAST8 "u" #define SCNxFAST8 "x" #define SCNXFAST8 "X" #define SCNo16 "ho" #define SCNu16 "hu" #define SCNx16 "hx" #define SCNX16 "hX" #define SCNoLEAST16 "ho" #define SCNuLEAST16 "hu" #define SCNxLEAST16 "hx" #define SCNXLEAST16 "hX" #define SCNoFAST16 "ho" #define SCNuFAST16 "hu" #define SCNxFAST16 "hx" #define SCNXFAST16 "hX" #define SCNo32 "lo" #define SCNu32 "lu" #define SCNx32 "lx" #define SCNX32 "lX" #define SCNoLEAST32 "lo" #define SCNuLEAST32 "lu" #define SCNxLEAST32 "lx" #define SCNXLEAST32 "lX" #define SCNoFAST32 "lo" #define SCNuFAST32 "lu" #define SCNxFAST32 "lx" #define SCNXFAST32 "lX" #define SCNo64 "I64o" #define SCNu64 "I64u" #define SCNx64 "I64x" #define SCNX64 "I64X" #define SCNoLEAST64 "I64o" #define SCNuLEAST64 "I64u" #define SCNxLEAST64 "I64x" #define SCNXLEAST64 "I64X" #define SCNoFAST64 "I64o" #define SCNuFAST64 "I64u" #define SCNxFAST64 "I64x" #define SCNXFAST64 "I64X" #define SCNoMAX "I64o" #define SCNuMAX "I64u" #define SCNxMAX "I64x" #define SCNXMAX "I64X" #ifdef _WIN64 // [ # define SCNoPTR "I64o" # define SCNuPTR "I64u" # define SCNxPTR "I64x" # define SCNXPTR "I64X" #else // _WIN64 ][ # define SCNoPTR "lo" # define SCNuPTR "lu" # define SCNxPTR "lx" # define SCNXPTR "lX" #endif // _WIN64 ] #endif // __STDC_FORMAT_MACROS ] // 7.8.2 Functions for greatest-width integer types // 7.8.2.1 The imaxabs function #define imaxabs _abs64 // 7.8.2.2 The imaxdiv function // This is modified version of div() function from Microsoft's div.c found // in %MSVC.NET%\crt\src\div.c #ifdef STATIC_IMAXDIV // [ static #else // STATIC_IMAXDIV ][ _inline #endif // STATIC_IMAXDIV ] imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) { imaxdiv_t result; result.quot = numer / denom; result.rem = numer % denom; if (numer < 0 && result.rem > 0) { // did division wrong; must fix up ++result.quot; result.rem -= denom; } return result; } // 7.8.2.3 The strtoimax and strtoumax functions #define strtoimax _strtoi64 #define strtoumax _strtoui64 // 7.8.2.4 The wcstoimax and wcstoumax functions #define wcstoimax _wcstoi64 #define wcstoumax _wcstoui64 #endif // _MSC_INTTYPES_H_ ] openobex-1.7.2-Source/include/msvc/stdint.h000644 001750 001750 00000016201 11612777701 021772 0ustar00hendrikhendrik000000 000000 // ISO C9x compliant stdint.h for Microsoft Visual Studio // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 // // Copyright (c) 2006-2008 Alexander Chemeris // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // 3. The name of the author may be used to endorse or promote products // derived from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // /////////////////////////////////////////////////////////////////////////////// #ifndef _MSC_VER // [ #error "Use this header only with Microsoft Visual C++ compilers!" #endif // _MSC_VER ] #ifndef _MSC_STDINT_H_ // [ #define _MSC_STDINT_H_ #if _MSC_VER > 1000 #pragma once #endif #include // For Visual Studio 6 in C++ mode wrap include with 'extern "C++" {}' // or compiler give many errors like this: // error C2733: second C linkage of overloaded function 'wmemchr' not allowed #if (_MSC_VER < 1300) && defined(__cplusplus) extern "C++" { #endif # include #if (_MSC_VER < 1300) && defined(__cplusplus) } #endif // Define _W64 macros to mark types changing their size, like intptr_t. #ifndef _W64 # if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300 # define _W64 __w64 # else # define _W64 # endif #endif // 7.18.1 Integer types // 7.18.1.1 Exact-width integer types typedef __int8 int8_t; typedef __int16 int16_t; typedef __int32 int32_t; typedef __int64 int64_t; typedef unsigned __int8 uint8_t; typedef unsigned __int16 uint16_t; typedef unsigned __int32 uint32_t; typedef unsigned __int64 uint64_t; // 7.18.1.2 Minimum-width integer types typedef int8_t int_least8_t; typedef int16_t int_least16_t; typedef int32_t int_least32_t; typedef int64_t int_least64_t; typedef uint8_t uint_least8_t; typedef uint16_t uint_least16_t; typedef uint32_t uint_least32_t; typedef uint64_t uint_least64_t; // 7.18.1.3 Fastest minimum-width integer types typedef int8_t int_fast8_t; typedef int16_t int_fast16_t; typedef int32_t int_fast32_t; typedef int64_t int_fast64_t; typedef uint8_t uint_fast8_t; typedef uint16_t uint_fast16_t; typedef uint32_t uint_fast32_t; typedef uint64_t uint_fast64_t; // 7.18.1.4 Integer types capable of holding object pointers #ifdef _WIN64 // [ typedef __int64 intptr_t; typedef unsigned __int64 uintptr_t; #else // _WIN64 ][ typedef _W64 int intptr_t; typedef _W64 unsigned int uintptr_t; #endif // _WIN64 ] // 7.18.1.5 Greatest-width integer types typedef int64_t intmax_t; typedef uint64_t uintmax_t; // 7.18.2 Limits of specified-width integer types #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) // [ See footnote 220 at page 257 and footnote 221 at page 259 // 7.18.2.1 Limits of exact-width integer types #define INT8_MIN ((int8_t)_I8_MIN) #define INT8_MAX _I8_MAX #define INT16_MIN ((int16_t)_I16_MIN) #define INT16_MAX _I16_MAX #define INT32_MIN ((int32_t)_I32_MIN) #define INT32_MAX _I32_MAX #define INT64_MIN ((int64_t)_I64_MIN) #define INT64_MAX _I64_MAX #define UINT8_MAX _UI8_MAX #define UINT16_MAX _UI16_MAX #define UINT32_MAX _UI32_MAX #define UINT64_MAX _UI64_MAX // 7.18.2.2 Limits of minimum-width integer types #define INT_LEAST8_MIN INT8_MIN #define INT_LEAST8_MAX INT8_MAX #define INT_LEAST16_MIN INT16_MIN #define INT_LEAST16_MAX INT16_MAX #define INT_LEAST32_MIN INT32_MIN #define INT_LEAST32_MAX INT32_MAX #define INT_LEAST64_MIN INT64_MIN #define INT_LEAST64_MAX INT64_MAX #define UINT_LEAST8_MAX UINT8_MAX #define UINT_LEAST16_MAX UINT16_MAX #define UINT_LEAST32_MAX UINT32_MAX #define UINT_LEAST64_MAX UINT64_MAX // 7.18.2.3 Limits of fastest minimum-width integer types #define INT_FAST8_MIN INT8_MIN #define INT_FAST8_MAX INT8_MAX #define INT_FAST16_MIN INT16_MIN #define INT_FAST16_MAX INT16_MAX #define INT_FAST32_MIN INT32_MIN #define INT_FAST32_MAX INT32_MAX #define INT_FAST64_MIN INT64_MIN #define INT_FAST64_MAX INT64_MAX #define UINT_FAST8_MAX UINT8_MAX #define UINT_FAST16_MAX UINT16_MAX #define UINT_FAST32_MAX UINT32_MAX #define UINT_FAST64_MAX UINT64_MAX // 7.18.2.4 Limits of integer types capable of holding object pointers #ifdef _WIN64 // [ # define INTPTR_MIN INT64_MIN # define INTPTR_MAX INT64_MAX # define UINTPTR_MAX UINT64_MAX #else // _WIN64 ][ # define INTPTR_MIN INT32_MIN # define INTPTR_MAX INT32_MAX # define UINTPTR_MAX UINT32_MAX #endif // _WIN64 ] // 7.18.2.5 Limits of greatest-width integer types #define INTMAX_MIN INT64_MIN #define INTMAX_MAX INT64_MAX #define UINTMAX_MAX UINT64_MAX // 7.18.3 Limits of other integer types #ifdef _WIN64 // [ # define PTRDIFF_MIN _I64_MIN # define PTRDIFF_MAX _I64_MAX #else // _WIN64 ][ # define PTRDIFF_MIN _I32_MIN # define PTRDIFF_MAX _I32_MAX #endif // _WIN64 ] #define SIG_ATOMIC_MIN INT_MIN #define SIG_ATOMIC_MAX INT_MAX #ifndef SIZE_MAX // [ # ifdef _WIN64 // [ # define SIZE_MAX _UI64_MAX # else // _WIN64 ][ # define SIZE_MAX _UI32_MAX # endif // _WIN64 ] #endif // SIZE_MAX ] // WCHAR_MIN and WCHAR_MAX are also defined in #ifndef WCHAR_MIN // [ # define WCHAR_MIN 0 #endif // WCHAR_MIN ] #ifndef WCHAR_MAX // [ # define WCHAR_MAX _UI16_MAX #endif // WCHAR_MAX ] #define WINT_MIN 0 #define WINT_MAX _UI16_MAX #endif // __STDC_LIMIT_MACROS ] // 7.18.4 Limits of other integer types #if !defined(__cplusplus) || defined(__STDC_CONSTANT_MACROS) // [ See footnote 224 at page 260 // 7.18.4.1 Macros for minimum-width integer constants #define INT8_C(val) val##i8 #define INT16_C(val) val##i16 #define INT32_C(val) val##i32 #define INT64_C(val) val##i64 #define UINT8_C(val) val##ui8 #define UINT16_C(val) val##ui16 #define UINT32_C(val) val##ui32 #define UINT64_C(val) val##ui64 // 7.18.4.2 Macros for greatest-width integer constants #define INTMAX_C INT64_C #define UINTMAX_C UINT64_C #endif // __STDC_CONSTANT_MACROS ] #endif // _MSC_STDINT_H_ ] openobex-1.7.2-Source/include/msvc/stdbool.h000644 001750 001750 00000000274 12115174310 022120 0ustar00hendrikhendrik000000 000000 #ifndef _STDBOOL_H #define _STDBOOL_H #if ! defined(__cplusplus) typedef int bool; #define false 0 #define true 1 #endif #define __bool_true_false_are_defined 1 #endif /* _STDBOOL_H */ openobex-1.7.2-Source/include/msvc/unistd.h000644 001750 001750 00000000601 12115174310 021752 0ustar00hendrikhendrik000000 000000 /* unistd.h for Microsoft compiler * This replaces the standard header and provides common * type definitions. */ #ifndef _MSC_VER // [ #error "Use this header only with Microsoft Visual C++ compilers!" #endif // _MSC_VER ] #ifndef _MSC_UNISTD_H #define _MSC_UNISTD_H /* the type returned by function like _write() and send() */ typedef long ssize_t; #endif /* _MSC_UNISTD_H */ openobex-1.7.2-Source/include/openobex/000755 001750 001750 00000000000 12701534273 021156 5ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/include/openobex/CMakeLists.txt000644 001750 001750 00000000550 12112117634 023710 0ustar00hendrikhendrik000000 000000 configure_file ( version.h.in version.h @ONLY ) set ( HEADER_FILES ${CMAKE_CURRENT_SOURCE_DIR}/obex.h ${CMAKE_CURRENT_SOURCE_DIR}/obex_const.h ${CMAKE_CURRENT_BINARY_DIR}/version.h ) set ( openobex_PUBLIC_HEADERS "${HEADER_FILES}" PARENT_SCOPE ) install ( FILES ${HEADER_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/openobex COMPONENT devel ) openobex-1.7.2-Source/include/openobex/version.h.in000644 001750 001750 00000000272 12173014762 023421 0ustar00hendrikhendrik000000 000000 #define OPENOBEX_VERSION "@VERSION@" #define OPENOBEX_VERSION_MAJOR @VERSION_MAJOR@ #define OPENOBEX_VERSION_MINOR @VERSION_MINOR@ #define OPENOBEX_VERSION_PATCH @VERSION_PATCH@ openobex-1.7.2-Source/include/openobex/obex.h000644 001750 001750 00000015324 12701160572 022266 0ustar00hendrikhendrik000000 000000 /** \file openobex/obex.h OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (C) 1999-2000 Dag Brattli Copyright (C) 1999-2000 Pontus Fuchs Copyright (C) 2001-2002 Jean Tourrilhes Copyright (C) 2002-2006 Marcel Holtmann Copyright (C) 2002-2008 Christian W. Zuckschwerdt Copyright (C) 2002 Dmitry Kasatkin Copyright (C) 2005 Herton Ronaldo Krzesinski Copyright (C) 2005-2008 Alex Kanavin Copyright (C) 2006 Johan Hedberg Copyright (C) 2007-2008 Hendrik Sattler OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef OPENOBEX_OBEX_H #define OPENOBEX_OBEX_H #ifdef __cplusplus extern "C" { #endif #ifdef _WIN32 #include #ifndef OPENOBEX_SYMBOL #ifdef OPENOBEX_DLL #define OPENOBEX_SYMBOL(retval) __declspec(dllimport) retval WINAPI #else /* OPENOBEX_DLL */ #define OPENOBEX_SYMBOL(retval) retval WINAPI #endif /* OPENOBEX_DLL */ #endif /* OPENOBEX_SYMBOL */ #else /* _WIN32 */ #include #endif /* _WIN32 */ #include #ifndef OPENOBEX_SYMBOL #define OPENOBEX_SYMBOL(retval) retval #endif struct obex; struct obex_object; typedef struct obex obex_t; typedef struct obex_object obex_object_t; typedef void (*obex_event_t)(obex_t *handle, obex_object_t *obj, int mode, int event, int obex_cmd, int obex_rsp); #include /* * OBEX API */ OPENOBEX_SYMBOL(obex_t *) OBEX_Init(int transport, obex_event_t eventcb, unsigned int flags); OPENOBEX_SYMBOL(void) OBEX_Cleanup(obex_t *self); OPENOBEX_SYMBOL(void) OBEX_SetUserData(obex_t *self, void * data); OPENOBEX_SYMBOL(void *) OBEX_GetUserData(obex_t *self); OPENOBEX_SYMBOL(void) OBEX_SetUserCallBack(obex_t *self, obex_event_t eventcb, void * data); OPENOBEX_SYMBOL(int) OBEX_SetTransportMTU(obex_t *self, uint16_t mtu_rx, uint16_t mtu_tx_max); OPENOBEX_SYMBOL(int) OBEX_GetFD(obex_t *self); OPENOBEX_SYMBOL(int) OBEX_RegisterCTransport(obex_t *self, obex_ctrans_t *ctrans); OPENOBEX_SYMBOL(int) OBEX_SetCustomData(obex_t *self, void * data); OPENOBEX_SYMBOL(void *) OBEX_GetCustomData(obex_t *self); OPENOBEX_SYMBOL(int) OBEX_TransportConnect(obex_t *self, struct sockaddr *saddr, int addlen); OPENOBEX_SYMBOL(int) OBEX_TransportDisconnect(obex_t *self); OPENOBEX_SYMBOL(int) OBEX_CustomDataFeed(obex_t *self, uint8_t *inputbuf, int actual); OPENOBEX_SYMBOL(void) OBEX_SetTimeout(obex_t *self, int64_t timeout); OPENOBEX_SYMBOL(int) OBEX_Work(obex_t *self); OPENOBEX_SYMBOL(enum obex_data_direction) OBEX_GetDataDirection(obex_t *self); OPENOBEX_SYMBOL(int) OBEX_HandleInput(obex_t *self, int timeout); OPENOBEX_SYMBOL(int) OBEX_ServerRegister(obex_t *self, struct sockaddr *saddr, int addrlen); OPENOBEX_SYMBOL(obex_t *) OBEX_ServerAccept(obex_t *server, obex_event_t eventcb, void * data); OPENOBEX_SYMBOL(int) OBEX_Request(obex_t *self, obex_object_t *object); OPENOBEX_SYMBOL(int) OBEX_CancelRequest(obex_t *self, int nice); OPENOBEX_SYMBOL(int) OBEX_SuspendRequest(obex_t *self, obex_object_t *object); OPENOBEX_SYMBOL(int) OBEX_ResumeRequest(obex_t *self); OPENOBEX_SYMBOL(obex_object_t *) OBEX_ObjectNew(obex_t *self, uint8_t cmd); OPENOBEX_SYMBOL(int) OBEX_ObjectDelete(obex_t *self, obex_object_t *object); OPENOBEX_SYMBOL(int) OBEX_ObjectGetSpace(obex_t *self, obex_object_t *object, unsigned int flags); OPENOBEX_SYMBOL(void) OBEX_SetReponseMode(obex_t *self, enum obex_rsp_mode rsp_mode); OPENOBEX_SYMBOL(int) OBEX_ObjectAddHeader(obex_t *self, obex_object_t *object, uint8_t hi, obex_headerdata_t hv, uint32_t hv_size, unsigned int flags); OPENOBEX_SYMBOL(int) OBEX_ObjectGetNextHeader(obex_t *self, obex_object_t *object, uint8_t *hi, obex_headerdata_t *hv, uint32_t *hv_size); OPENOBEX_SYMBOL(int) OBEX_ObjectReParseHeaders(obex_t *self, obex_object_t *object); OPENOBEX_SYMBOL(int) OBEX_ObjectSetRsp(obex_object_t *object, uint8_t rsp, uint8_t lastrsp); OPENOBEX_SYMBOL(int) OBEX_ObjectGetNonHdrData(obex_object_t *object, uint8_t **buffer); OPENOBEX_SYMBOL(int) OBEX_ObjectSetNonHdrData(obex_object_t *object, const uint8_t *buffer, unsigned int len); OPENOBEX_SYMBOL(int) OBEX_ObjectSetHdrOffset(obex_object_t *object, unsigned int offset); OPENOBEX_SYMBOL(int) OBEX_ObjectReadStream(obex_t *self, obex_object_t *object, const uint8_t **buf); OPENOBEX_SYMBOL(int) OBEX_ObjectGetCommand(obex_t *self, obex_object_t *object); OPENOBEX_SYMBOL(char *) OBEX_ResponseToString(int rsp); /* * TcpOBEX API (IPv4/IPv6) */ OPENOBEX_SYMBOL(int) TcpOBEX_ServerRegister(obex_t *self, struct sockaddr *addr, int addrlen); OPENOBEX_SYMBOL(int) TcpOBEX_TransportConnect(obex_t *self, struct sockaddr *addr, int addrlen); /* * IrOBEX API */ OPENOBEX_SYMBOL(int) IrOBEX_ServerRegister(obex_t *self, const char *service); OPENOBEX_SYMBOL(int) IrOBEX_TransportConnect(obex_t *self, const char *service); /* * Bluetooth OBEX API */ #if !defined(bt_addr_t) # if defined(_WIN32) # if defined(BTH_ADDR_NULL) # define bt_addr_t BTH_ADDR # endif # elif defined(__FreeBSD__) # if defined(NG_HCI_BDADDR_ANY) # define bt_addr_t bdaddr_t # endif # else /* Linux, NetBSD, etc.. */ # if defined(BDADDR_ANY) # define bt_addr_t bdaddr_t # endif # endif #endif #if defined(bt_addr_t) OPENOBEX_SYMBOL(int) BtOBEX_ServerRegister(obex_t *self, const bt_addr_t *src, uint8_t channel); OPENOBEX_SYMBOL(int) BtOBEX_TransportConnect(obex_t *self, const bt_addr_t *src, const bt_addr_t *dst, uint8_t channel); #endif /* * OBEX File API */ OPENOBEX_SYMBOL(int) FdOBEX_TransportSetup(obex_t *self, int rfd, int wfd, int mtu); /* * OBEX interface discovery API */ OPENOBEX_SYMBOL(int) OBEX_EnumerateInterfaces(obex_t *self); OPENOBEX_SYMBOL(obex_interface_t *) OBEX_GetInterfaceByIndex(obex_t *self, int i); OPENOBEX_SYMBOL(int) OBEX_InterfaceConnect(obex_t *self, obex_interface_t *intf); OPENOBEX_SYMBOL(void) OBEX_FreeInterfaces(obex_t *self); #ifdef __cplusplus } #endif #endif /* OPENOBEX_OBEX_H */ openobex-1.7.2-Source/include/openobex/obex_const.h000644 001750 001750 00000034206 12701160572 023474 0ustar00hendrikhendrik000000 000000 /** \file openobex/obex_const.h OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (C) 1999-2000 Dag Brattli Copyright (C) 1999-2000 Pontus Fuchs Copyright (C) 2001-2002 Jean Tourrilhes Copyright (C) 2002-2006 Marcel Holtmann Copyright (C) 2002-2008 Christian W. Zuckschwerdt Copyright (C) 2002 Dmitry Kasatkin Copyright (C) 2005 Herton Ronaldo Krzesinski Copyright (C) 2005-2008 Alex Kanavin Copyright (C) 2006 Johan Hedberg Copyright (C) 2007-2012 Hendrik Sattler OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef __OBEX_CONST_H #define __OBEX_CONST_H #ifdef __cplusplus extern "C" { #endif #include #include /** OBEX object tag information */ typedef union { /** use this when header type is #OBEX_HDR_TYPE_UINT32 */ uint32_t bq4; /** use this when header type is #OBEX_HDR_TYPE_UINT8 */ uint8_t bq1; /** use this when header type is #OBEX_HDR_TYPE_BYTES * or #OBEX_HDR_TYPE_UNICODE */ const uint8_t *bs; } obex_headerdata_t; /** Function definition for custom transports */ typedef struct { /** connect to a server (client-only) */ int (*connect)(obex_t *handle, void *customdata); /** disconnect (server/client) */ int (*disconnect)(obex_t *handle, void *customdata); /** listen to incoming connections (server-only) */ int (*listen)(obex_t *handle, void *customdata); /** remote connection input * This function is optional as it is an alternative to providing the * data with #OBEX_CustomDataFeed(). The memory that 'buf' points to has * enough room for RX MTU bytes. The minimum number of bytes needed to * go on is specified by 'size'.*/ int (*read)(obex_t *handle, void *customdata, uint8_t *buf, int size); /** remote connection output */ int (*write)(obex_t *handle, void *customdata, uint8_t *buf, int len); /** directly called by #OBEX_HandleInput */ int (*handleinput)(obex_t *handle, void *customdata, int timeout); void *customdata; } obex_ctrans_t; /** USB-specific OBEX service information * provided by optional Service Identification Functional Descriptor * (CDC WMC specification section 6.5.2.5) */ typedef struct { /** Role bit mask: bit 0 is set if client, unset if server */ uint8_t role; /** Service UUID */ uint8_t uuid[16]; /** Service version */ uint16_t version; /** Set if the service provides/expects * an OBEX Default Server (spec section 6.5.2.5.2) */ int is_default_uuid; } obex_usb_intf_service_t; /** USB-specific OBEX interface information */ typedef struct { /** Manufacturer, e.g. Nokia */ char *manufacturer; /** Product, e.g. Nokia 6680 */ char *product; /** Product serial number */ char *serial; /** USB device configuration description */ char *configuration; /** Control interface description */ char *control_interface; /** Idle data interface description, typically empty */ char *data_interface_idle; /** Active data interface description, typically empty */ char *data_interface_active; /** Service information descriptor, may be NULL if absent */ obex_usb_intf_service_t *service; /** USB-IF vendor ID */ unsigned int idVendor; /** USB-IF product ID */ unsigned int idProduct; /** Bus number that a USB device is connected to */ unsigned int bus_number; /** Device address on the bus */ unsigned int device_address; /** USB device interface number */ unsigned int interface_number; /** Internal information for the transport layer in the library */ struct obex_usb_intf_transport_t *intf; } obex_usb_intf_t; /** IrDA-specific OBEX interface information */ typedef struct { /** Address of local interface */ uint32_t local; /** Address of remote device */ uint32_t remote; /** Description */ char *info; /** Charset used for description */ uint8_t charset; /** Hint bits */ uint8_t hints[2]; /** service selector, filled by application, "OBEX" if NULL */ const char *service; } obex_irda_intf_t; /** Generic OBEX interface information */ typedef union { /** IrDA-specific OBEX interface information */ obex_irda_intf_t irda; /** USB-specific OBEX interface information */ obex_usb_intf_t usb; } obex_interface_t; /** Possible modes */ enum obex_mode { OBEX_MODE_CLIENT = 0, /**< client mode */ OBEX_MODE_SERVER = 1, /**< server mode */ }; /** Possible data direction */ enum obex_data_direction { OBEX_DATA_NONE = 0, OBEX_DATA_IN = 1, OBEX_DATA_OUT = 2, }; /** Possible events */ enum obex_event { /** Progress has been made */ OBEX_EV_PROGRESS = 0, /** An incoming request is about to come */ OBEX_EV_REQHINT = 1, /** An incoming request has arrived */ OBEX_EV_REQ = 2, /** Request has finished */ OBEX_EV_REQDONE = 3, /** Link has been disconnected */ OBEX_EV_LINKERR = 4, /** Malformed data encountered */ OBEX_EV_PARSEERR = 5, /** Connection accepted */ OBEX_EV_ACCEPTHINT = 6, /** Request was aborted */ OBEX_EV_ABORT = 7, /** Need to feed more data when sending a stream */ OBEX_EV_STREAMEMPTY = 8, /** Time to pick up data when receiving a stream */ OBEX_EV_STREAMAVAIL = 9, /** Unexpected data, not fatal */ OBEX_EV_UNEXPECTED = 10, /** First packet of an incoming request has been parsed */ OBEX_EV_REQCHECK = 11, /** A Continue response was received and a new request is about to be sent. * CancelRequest() can be used to stop the request processing. */ OBEX_EV_CONTINUE = 12, }; /* For OBEX_Init() */ #define OBEX_FL_KEEPSERVER (1 << 1) /**< Keep the server alive */ #define OBEX_FL_FILTERHINT (1 << 2) /**< Filter devices based on hint bit */ #define OBEX_FL_FILTERIAS (1 << 3) /**< Filter devices based on IAS entry */ #define OBEX_FL_CLOEXEC (1 << 4) /**< Set CLOEXEC flag on file descriptors */ #define OBEX_FL_NONBLOCK (1 << 5) /**< Set the NONBLOCK flag on file descriptors */ /* For OBEX_ObjectAddHeader */ #define OBEX_FL_FIT_ONE_PACKET (1 << 0) /**< This header must fit in one packet */ #define OBEX_FL_STREAM_START (1 << 1) /**< Start of streaming body */ #define OBEX_FL_STREAM_DATA (1 << 2) /**< Set data for body stream */ #define OBEX_FL_STREAM_DATAEND (1 << 3) /**< Set data (or no data) for body stream and finish it */ #define OBEX_FL_SUSPEND (1 << 4) /**< Suspend after sending this header */ #define OBEX_FL_STREAM_CONTINUE (1 << 5) /**< Continue body stream after all remaining headers */ /** Possible transports */ enum obex_transport_type { OBEX_TRANS_IRDA = 1, /**< Infrared */ OBEX_TRANS_INET = 2, /**< TCP over IPv4/v6 */ OBEX_TRANS_CUSTOM = 3, /**< Custom transport with callbacks */ OBEX_TRANS_BLUETOOTH = 4, /**< Bluetooth RFCOMM */ OBEX_TRANS_FD = 5, /**< file descriptors */ OBEX_TRANS_USB = 6, /**< USB CDC OBEX */ }; /* Standard headers */ #define OBEX_HDR_TYPE_SHIFT 6 #define OBEX_HDR_TYPE_MASK 0xc0 #define OBEX_HDR_ID_MASK 0x3f /** Type part of an obex header value */ enum obex_hdr_type { /** used as invalid return value */ OBEX_HDR_TYPE_INVALID = -1, /** zero terminated unicode string (network byte order) */ OBEX_HDR_TYPE_UNICODE = (0 << OBEX_HDR_TYPE_SHIFT), /** byte array */ OBEX_HDR_TYPE_BYTES = (1 << OBEX_HDR_TYPE_SHIFT), /** 8bit unsigned integer */ OBEX_HDR_TYPE_UINT8 = (2 << OBEX_HDR_TYPE_SHIFT), /** 32bit unsigned integer */ OBEX_HDR_TYPE_UINT32 = (3 << OBEX_HDR_TYPE_SHIFT), }; /** Identifier part of an obex header value */ enum obex_hdr_id { /** used as invalid return value */ OBEX_HDR_ID_INVALID = -1, /** Number of objects (used by connect) */ OBEX_HDR_ID_COUNT = 0, /** Name of the object */ OBEX_HDR_ID_NAME = 1, /** Type of the object */ OBEX_HDR_ID_TYPE = 2, /** Total length of object */ OBEX_HDR_ID_LENGTH = 3, /** Last modification time of (ISO8601) */ OBEX_HDR_ID_TIME = 4, /** Description of object */ OBEX_HDR_ID_DESCRIPTION = 5, /** Identifies the target for the object */ OBEX_HDR_ID_TARGET = 6, /** An HTTP 1.x header */ OBEX_HDR_ID_HTTP = 7, /** Data part of the object */ OBEX_HDR_ID_BODY = 8, /** Last data part of the object */ OBEX_HDR_ID_BODY_END = 9, /** Identifies the sender of the object */ OBEX_HDR_ID_WHO = 10, /** Connection identifier */ OBEX_HDR_ID_CONNECTION = 11, /** Application parameters */ OBEX_HDR_ID_APPARAM = 12, /** Authentication challenge */ OBEX_HDR_ID_AUTHCHAL = 13, /** Authentication response */ OBEX_HDR_ID_AUTHRESP = 14, /** indicates the creator of an object */ OBEX_HDR_ID_CREATOR = 15, /** uniquely identifies the network client (OBEX server) */ OBEX_HDR_ID_WANUUID = 16, /** OBEX Object class of object */ OBEX_HDR_ID_OBJECTCLASS = 17, /** Parameters used in session commands/responses */ OBEX_HDR_ID_SESSIONPARAM = 18, /** Sequence number used in each OBEX packet for reliability */ OBEX_HDR_ID_SESSIONSEQ = 19, /** Specifies the action for the ACTION command */ OBEX_HDR_ID_ACTION_ID = 20, /** Destination object name */ OBEX_HDR_ID_DESTNAME = 21, /** bit mask for setting permissions */ OBEX_HDR_ID_PERMISSIONS = 22, /** response mode selection */ OBEX_HDR_ID_SRM = 23, /** flags for single response mode */ OBEX_HDR_ID_SRM_FLAGS = 24, }; #define OBEX_HDR_EMPTY 0x00 /* Empty header (buggy OBEX servers) */ #define OBEX_HDR_COUNT (OBEX_HDR_ID_COUNT | OBEX_HDR_TYPE_UINT32 ) #define OBEX_HDR_NAME (OBEX_HDR_ID_NAME | OBEX_HDR_TYPE_UNICODE) #define OBEX_HDR_TYPE (OBEX_HDR_ID_TYPE | OBEX_HDR_TYPE_BYTES ) #define OBEX_HDR_LENGTH (OBEX_HDR_ID_LENGTH | OBEX_HDR_TYPE_UINT32 ) #define OBEX_HDR_TIME (OBEX_HDR_ID_TIME | OBEX_HDR_TYPE_BYTES ) /* Format: ISO 8601 */ #define OBEX_HDR_TIME2 (OBEX_HDR_ID_TIME | OBEX_HDR_TYPE_UINT32 ) /* Deprecated use HDR_TIME instead */ #define OBEX_HDR_DESCRIPTION (OBEX_HDR_ID_DESCRIPTION | OBEX_HDR_TYPE_UNICODE) #define OBEX_HDR_TARGET (OBEX_HDR_ID_TARGET | OBEX_HDR_TYPE_BYTES ) #define OBEX_HDR_HTTP (OBEX_HDR_ID_HTTP | OBEX_HDR_TYPE_BYTES ) #define OBEX_HDR_BODY (OBEX_HDR_ID_BODY | OBEX_HDR_TYPE_BYTES ) #define OBEX_HDR_BODY_END (OBEX_HDR_ID_BODY_END | OBEX_HDR_TYPE_BYTES ) #define OBEX_HDR_WHO (OBEX_HDR_ID_WHO | OBEX_HDR_TYPE_BYTES ) #define OBEX_HDR_CONNECTION (OBEX_HDR_ID_CONNECTION | OBEX_HDR_TYPE_UINT32 ) #define OBEX_HDR_APPARAM (OBEX_HDR_ID_APPARAM | OBEX_HDR_TYPE_BYTES ) #define OBEX_HDR_AUTHCHAL (OBEX_HDR_ID_AUTHCHAL | OBEX_HDR_TYPE_BYTES ) #define OBEX_HDR_AUTHRESP (OBEX_HDR_ID_AUTHRESP | OBEX_HDR_TYPE_BYTES ) #define OBEX_HDR_CREATOR (OBEX_HDR_ID_CREATOR | OBEX_HDR_TYPE_BYTES ) #define OBEX_HDR_WANUUID (OBEX_HDR_ID_WANUUID | OBEX_HDR_TYPE_BYTES ) #define OBEX_HDR_OBJECTCLASS (OBEX_HDR_ID_OBJECTCLASS | OBEX_HDR_TYPE_BYTES ) #define OBEX_HDR_SESSIONPARAM (OBEX_HDR_ID_SESSIONPARAM | OBEX_HDR_TYPE_BYTES ) #define OBEX_HDR_SESSIONSEQ (OBEX_HDR_ID_SESSIONSEQ | OBEX_HDR_TYPE_UINT8 ) #define OBEX_HDR_ACTION_ID (OBEX_HDR_ID_ACTION_ID | OBEX_HDR_TYPE_UINT8 ) #define OBEX_HDR_DESTNAME (OBEX_HDR_ID_DESTNAME | OBEX_HDR_TYPE_UNICODE) #define OBEX_HDR_PERMISSIONS (OBEX_HDR_ID_PERMISSIONS | OBEX_HDR_TYPE_UINT32 ) #define OBEX_HDR_SRM (OBEX_HDR_ID_SRM | OBEX_HDR_TYPE_UINT8 ) #define OBEX_HDR_SRM_FLAGS (OBEX_HDR_ID_SRM_FLAGS | OBEX_HDR_TYPE_UINT8 ) /** Obex commands */ enum obex_cmd { OBEX_CMD_CONNECT = 0x00, OBEX_CMD_DISCONNECT = 0x01, OBEX_CMD_PUT = 0x02, OBEX_CMD_GET = 0x03, OBEX_CMD_SETPATH = 0x05, OBEX_CMD_ACTION = 0x06, OBEX_CMD_SESSION = 0x07, /**< used for reliable session support */ OBEX_CMD_ABORT = 0x7f, }; #define OBEX_FINAL 0x80 /** Obex responses */ enum obex_rsp { OBEX_RSP_CONTINUE = 0x10, OBEX_RSP_SWITCH_PRO = 0x11, OBEX_RSP_SUCCESS = 0x20, OBEX_RSP_CREATED = 0x21, OBEX_RSP_ACCEPTED = 0x22, OBEX_RSP_NON_AUTHORITATIVE = 0x23, OBEX_RSP_NO_CONTENT = 0x24, OBEX_RSP_RESET_CONTENT = 0x25, OBEX_RSP_PARTIAL_CONTENT = 0x26, OBEX_RSP_MULTIPLE_CHOICES = 0x30, OBEX_RSP_MOVED_PERMANENTLY = 0x31, OBEX_RSP_MOVED_TEMPORARILY = 0x32, OBEX_RSP_SEE_OTHER = 0x33, OBEX_RSP_NOT_MODIFIED = 0x34, OBEX_RSP_USE_PROXY = 0x35, OBEX_RSP_BAD_REQUEST = 0x40, OBEX_RSP_UNAUTHORIZED = 0x41, OBEX_RSP_PAYMENT_REQUIRED = 0x42, OBEX_RSP_FORBIDDEN = 0x43, OBEX_RSP_NOT_FOUND = 0x44, OBEX_RSP_METHOD_NOT_ALLOWED = 0x45, OBEX_RSP_NOT_ACCEPTABLE = 0x46, OBEX_RSP_PROXY_AUTH_REQUIRED = 0x47, OBEX_RSP_REQUEST_TIME_OUT = 0x48, OBEX_RSP_CONFLICT = 0x49, OBEX_RSP_GONE = 0x4a, OBEX_RSP_LENGTH_REQUIRED = 0x4b, OBEX_RSP_PRECONDITION_FAILED = 0x4c, OBEX_RSP_REQ_ENTITY_TOO_LARGE = 0x4d, OBEX_RSP_REQ_URL_TOO_LARGE = 0x4e, OBEX_RSP_UNSUPPORTED_MEDIA_TYPE = 0x4f, OBEX_RSP_INTERNAL_SERVER_ERROR = 0x50, OBEX_RSP_NOT_IMPLEMENTED = 0x51, OBEX_RSP_BAD_GATEWAY = 0x52, OBEX_RSP_SERVICE_UNAVAILABLE = 0x53, OBEX_RSP_GATEWAY_TIMEOUT = 0x54, OBEX_RSP_VERSION_NOT_SUPPORTED = 0x55, OBEX_RSP_DATABASE_FULL = 0x60, OBEX_RSP_DATABASE_LOCKED = 0x61, }; /** Obex response modes */ enum obex_rsp_mode { OBEX_RSP_MODE_NORMAL = 0, /**< normal response mode */ OBEX_RSP_MODE_SINGLE = 1, /**< single response mode (SRM) */ }; /* Min, Max and default transport MTU */ #define OBEX_DEFAULT_MTU 1024 #define OBEX_MINIMUM_MTU 255 #define OBEX_MAXIMUM_MTU 65535 /** Optimum MTU for various transport (optimum for throughput). * The user/application has to set them via OBEX_SetTransportMTU(). * If you are worried about safety or latency, stick with the current * default... - Jean II */ #define OBEX_IRDA_OPT_MTU (7 * 2039) /* 7 IrLAP frames */ #ifdef __cplusplus } #endif #endif /* __OBEX_CONST_H */ openobex-1.7.2-Source/lib/000755 001750 001750 00000000000 12701534273 016462 5ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/lib/ChangeLog000644 001750 001750 00000026533 11612777701 020252 0ustar00hendrikhendrik000000 000000 2005-12-18 Alex Kanavin * Support for USB transport layer and USB interface discovery 2005-12-02 Johan Hedberg * Add OBEX_SuspendRequest() and OBEX_ResumeRequest() functions for better control of streamed transfers. 2004-03-06 Christian W. Zuckschwerdt * Portability fixes, mainly replacing stdint.h with inttypes.h (needed for e.g. solaris; ISO C99 says inttypes.h includes stdint.h) 2003-10-01 Marcel Holtmann * Add COPYING.LIB for LGPL stuff * Don't auto generate openobex.spec * Bump version number to 1.0.1 2002-12-18 Marcel Holtmann * Make OBEX_TRANS_BLUETOOTH working on Big-endian platform 2002-11-15 Marcel Holtmann * Add OBEX_SetCustomData() and OBEX_GetCustomData() 2002-11-05 Marcel Holtmann * Replace OBEX_GetResponseMessage() with OBEX_ResponseToString() 2002-11-01 Marcel Holtmann * Change Bluetooth MTU to OBEX_DEFAULT_MTU * Change type of RFCOMM channel to uint8_t * Return static strings from obex_get_response_message() 2002-10-29 Dmitry Kasatkin * Add OBEX_TRANS_FD support 2002-10-28 Marcel Holtmann * Remove GLib dependencies. * Remove default prefix statement. * Fix workaround for Bluetooth support, again. * Replace OBEX_TRANS_CUST with OBEX_TRANS_CUSTOM. 2002-10-25 Marcel Holtmann * Change g_htons() into htons() 2002-10-23 Marcel Holtmann * Fix workaround for compilation without Bluetooth support. * Add support for DEBUG and DUMP. * Disable IrDA discovery if a valid IrDA address is supplied. 2002-10-16 Marcel Holtmann * Allow higher MTUs. * Handle unexpected data in continue. 2002-10-11 Marcel Holtmann * Cleanup of autoconf/automake stuff. * Support for Bluetooth transport layer. * Bump version number to 1.0.0 2001-02-27 Pontus Fuchs * Added a patch from Jean: o OBEX_SetUserCallBack - change callback after OBEX_init() o OBEX_ObjectReParseHeaders - Parse headers more than one time o Some documentation fixes. * Fixed some minor warnings 2000-12-06 Pontus Fuchs * Removed OBEX_Object(G|S)etUserData as they were not needed. * Documented the API, and added a DocBook-based doc-system (actually I just copied the Linux Kernel documentation-system). 2000-12-05 Pontus Fuchs * Pass timeout to handleinput when using a custom transport. 2000-12-04 Pontus Fuchs * Added streaming support. * Fixed endian-bug in obex_client.c and obex_server.c 2000-12-02 Pontus Fuchs * obex_data_indication was broken and didn't work correctly with custom transport. 2000-12-01 Pontus Fuchs * Minor cleanups to obex.c 2000-11-30 Pontus Fuchs * Made obex_object_send a bit more readable * Rewrote obex_client.c and obex_server.c. They are now more state- machine like which make them a lot easier to read. * Support recieving of ABORT (no sending yet). * Fixed so that IrDA works on older kernels again. 2000-11-21 Pontus Fuchs * Removed the async support. * Fixed irobex.c compilation on win32 (which Jean's patch broke). * Bumped version to 0.9.7 2000-11-20 Pontus Fuchs Applied a buch of fixes/changes made by Jean Tourrilhes * Full "accept" capability in OBEX Server (optional) : -> Keep server alive -> Detach receiver instance from server instance * Properly close all sockets (server + receiver) when Cleanup * Declare OBEX_GetFD() in obex.h * Updated irda.h to the latest * OBEX Server do tell IrDA stack to advertise OBEX hint bit * OBEX Client can do optional hint bit filtering of discovery log * OBEX Client can do optional IAS entry filtering of discovery log * Safer discovery log allocation 2000-10-16 Pontus Fuchs * obex_object.c: When a header with 0 length was received obex_object_receive tried to allocate a zero-length netbuf, which ofcourse failed causing the transfer to be aborted. 2000-08-29 Pontus Fuchs * Minor fix to obex_main.c which prevented custom transport to work. 2000-08-28 Pontus Fuchs * Minor improvements to many files. Defined some variables const as they ought to be. 2000-08-23 Pontus Fuchs * Fixed bug when receiving more than one fragment at a time. Win2K irftp seems to do this. 2000-08-21 Pontus Fuchs * Fixes to win32 makefiles. 2000-08-20 Pontus Fuchs * Created openobex.m4. 2000-08-18 Pontus Fuchs * Added IrDA-server support on win32. 2000-08-15 Pontus Fuchs * Various fixes to Makefiles etc * Did a workaround for client.c to be able to do PUT to Win2K. 2000-08-14 Pontus Fuchs * Fixed dependencies for win32. You need cygwin to generate them though. 2000-08-13 Pontus Fuchs * Made the listen/accept code to block. * Renamed the library openobex. 2000-08-11 Pontus Fuchs * Small fixes to obex.c and obex_const.h. 2000-08-09 Pontus Fuchs * Some more win32 fixes. irobex_test.c now compiles. * Added the win32 makefiles that I had forgotten. 2000-08-06 Pontus Fuchs * Lots of small win32 fixes. * irobex_palm3 and obex_tcp now compiles in win32. 2000-08-05 Pontus Fuchs * Made this thing compile on win32! 2000-08-03 Pontus Fuchs * Fixed a memleak when doing IrDA-discovery. * Fixed irda-check.m4 to really check for IrDA. * Added check to see if SIGIO is supported. Hopefully this stuff compiles on solaris now. 2000-07-21 Pontus Fuchs * When OBEX_Cleanup was called. Async IO instance was not unregistered. Fixed! * Fixed a small memleak when sending objects. 2000-07-16 Pontus Fuchs * Added a few more headers in obex_const.h 2000-07-13 Pontus Fuchs * Added functions to store userdata in an obex object and in the obex handle: OBEX_SetUserData, OBEX_GetUserData, OBEX_ObjectSetUserData and OBEX_ObjectGetUserData * Made custom transport work in sync mode. 2000-05-22 Pontus Fuchs * Fixed missing file in obex.spec.in 2000-05-18 Pontus Fuchs * Fixed libtool versioning. * Added obex.sym * Changed irobex.c to print discoved devices with DEBUG instead of g_print 2000-05-06 Pontus Fuchs * Added irda.h in src * Changed so that obex.h and obex_const.h are the only files That gets included by apps. 1999-12-06 Pontus Fuchs * Fixed a compile error on obex_object.c. 1999-12-05 Pontus Fuchs * Made some general routines to handle data before headers. (ie SETPATH works now) * Parsing of connect-hdr is a bit safer now. * Renamed OBEX_HEADER_* OBEX_HDR_*. 1999-11-29 Pontus Fuchs * Fix irobex_palm3 to quick on a link-error. * Check that we got at least 3 bytes after a read. * Made obex_receive_object check buffer sizes. 1999-11-28 Pontus Fuchs * Fixed the missing final-bit on server-operations. * Added some more errorchecking. 1999-11-26 Pontus Fuchs * Changed API again. Hopefully it will quite finished after this. * Updated all apps to work with the new API. * Made the custom-transport things cleaner. 1999-11-23 Pontus Fuchs * Fixed inobex.c to work after yesterdays changes. * Made an attempt to support multiple async instances! This needs more polishing but obex_tcp seems to work when sending to localhost. 1999-11-22 Pontus Fuchs * Fixed so that the socket is closed in OBEX_TransportDisconnect() instead of shutdown'ed. * Made async_self an array so we can have multiple async instances. 1999-11-20 Pontus Fuchs * Did some API-polishing. * Got tired of rewriting many test-apps so now obex_tcp and irobex_palm3 has common code. * Made OBEX_ObjectAddHeader() check that headers fit etc. * Made obex_parse_connect_header safer. 1999-11-17 Pontus Fuchs * Implemented a way to use custom transports. OBEX_CustomDataFeed() us used to give the OBEXlib data. A new callback is used when the OBEX-lib wants to write data. * Made code to use OBEX to an R320 over a serial line (see apps/cobex_R320.c and apps/irobex_test.c). 1999-11-16 Pontus Fuchs * More heavy changes 1999-11-08 Pontus Fuchs * Changed union OBEX_ADDHEADER_DATA to obex_headerdata_t typedef * The app is now responsible for converting to unicode before adding a unicode header. Made OBEX_CharToUnicode() for apps to use. 1999-10-28 Pontus Fuchs * Heavy changes to many things. Please look at my mail in the OBEX mailing-list for more info. 1999-10-25 Pontus Fuchs * src/obex_connect.c (obex_connect_confirm): Fixed so that the object created by obex_parse_connect_frame got properly deleted after connect_confirm callback was called. * src/obex_get.c (obex_get_indication): Removed some code which was not in my tree causing a compile error. 1999-10-22 Dag Brattli * src/obex_main.c (obex_status_indication): Fixed so that it just return if the body has not been allocated yet. This will happen if you start a get operation, and the first packet does not contain any body data. 1999-10-22 Pontus Fuchs * Small change to make irobex_palm3.c work again. 1999-10-22 Pontus Fuchs * Many changes with GET and PUT. 1999-10-21 Dag Brattli * Fixed irda-check.m4, so it doesn't stop with an error if IrDA support is not found. Now it will continue, but you will of course only get TCP support 1999-10-18 Pontus Fuchs * Fixed some small things in the GET statemachine. 1999-10-18 Dag Brattli * Removed irdalib, and just added netbuf.[ch] and parameters.[ch] to the obex/src dir. 1999-10-08 Dag Brattli * Fixed irda-check.m4 so #define HAVE_IRDA 1 will show up in config.h if you have irda support in your kernel 1999-10-08 Ole Sorslett * Added HAVE_IRDA ifdefs around all IrDA related code. Hopefully, the code should now compile OK even on *BSD systems. 1999-10-08 Pontus Fuchs * defined OBEX_OBJECT_MAXSTRLEN and removed hardcoded values * Changed obex_object_t and updated GET and PUT * Changed the status-indication to work when length is unknown. 1999-10-07 Pontus Fuchs * Fixed GET. * Fixed PUT. After a connect self->object was not empty causing putrequest to fail. * Added some checking to obex_put_request() and obex_get_request so they now fail nicely if obex_data_request() fails. openobex-1.7.2-Source/lib/obex_hdr.h000644 001750 001750 00000006416 12604167677 020450 0ustar00hendrikhendrik000000 000000 /** * @file obex_hdr.h * * OBEX header releated functions. * OpenOBEX library - Free implementation of the Object Exchange protocol. * * Copyright (c) 2012 Hendrik Sattler, All Rights Reserved. * * OpenOBEX is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the * Free Software Foundation; either version 2.1 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with OpenOBEX. If not, see . */ #include #include #include struct obex_hdr { unsigned int flags; size_t offset; struct obex_hdr_ops *ops; void *data; }; /** Copy the data to the header instance */ #define OBEX_FL_COPY (1 << 0) struct obex_hdr * obex_hdr_create(enum obex_hdr_id id, enum obex_hdr_type type, const void *data, size_t size, unsigned int flags); struct obex_hdr * obex_hdr_membuf_create(enum obex_hdr_id id, enum obex_hdr_type type, const void *data, size_t size); struct databuffer * obex_hdr_membuf_get_databuffer(struct obex_hdr *hdr); struct obex_hdr * obex_hdr_ptr_create(enum obex_hdr_id id, enum obex_hdr_type type, const void *data, size_t size); struct obex_hdr * obex_hdr_ptr_parse(const void *msgdata, size_t size); struct obex_hdr * obex_hdr_stream_create(struct obex *obex, struct obex_hdr *data); void obex_hdr_stream_finish(struct obex_hdr *hdr); struct obex_hdr_ops { void (*destroy)(void *self); enum obex_hdr_id (*get_id)(void *self); enum obex_hdr_type (*get_type)(void *self); size_t (*get_data_size)(void *self); const void * (*get_data_ptr)(void *self); bool (*set_data)(void *self, const void *data, size_t size); size_t (*append_data)(void *self, struct databuffer *buf, size_t size); bool (*is_finished)(void *self); }; struct obex_hdr * obex_hdr_new(struct obex_hdr_ops *ops, void *data); void obex_hdr_destroy(struct obex_hdr *hdr); enum obex_hdr_id obex_hdr_get_id(struct obex_hdr *hdr); enum obex_hdr_type obex_hdr_get_type(struct obex_hdr *hdr); size_t obex_hdr_get_size(struct obex_hdr *hdr); size_t obex_hdr_get_data_size(struct obex_hdr *hdr); const void * obex_hdr_get_data_ptr(struct obex_hdr *hdr); bool obex_hdr_set_data(struct obex_hdr *hdr, const void *data, size_t size); size_t obex_hdr_append(struct obex_hdr *hdr, struct databuffer *buf, size_t max_size); bool obex_hdr_is_splittable(struct obex_hdr *hdr); bool obex_hdr_is_finished(struct obex_hdr *hdr); struct obex_hdr_it { struct databuffer_list *list; int is_valid; }; void obex_hdr_it_init_from(struct obex_hdr_it *it, const struct obex_hdr_it *from); struct obex_hdr_it * obex_hdr_it_create(struct databuffer_list *list); void obex_hdr_it_destroy(struct obex_hdr_it *it); struct obex_hdr * obex_hdr_it_get(const struct obex_hdr_it *it); void obex_hdr_it_next(struct obex_hdr_it *it); int obex_hdr_it_equals(const struct obex_hdr_it *a, const struct obex_hdr_it *b); openobex-1.7.2-Source/lib/obex_hdr_membuf.c000644 001750 001750 00000005634 12604167677 021777 0ustar00hendrikhendrik000000 000000 /** * @file obex_hdr_membuf.c * * OBEX header releated functions. * OpenOBEX library - Free implementation of the Object Exchange protocol. * * Copyright (c) 2012 Hendrik Sattler, All Rights Reserved. * * OpenOBEX is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the * Free Software Foundation; either version 2.1 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with OpenOBEX. If not, see . */ #include #include #include struct obex_hdr_membuf { enum obex_hdr_id id; enum obex_hdr_type type; struct databuffer *buf; }; static void * obex_hdr_membuf_new(enum obex_hdr_id id, enum obex_hdr_type type, const void *value, size_t size) { struct obex_hdr_membuf *hdr = malloc(sizeof(*hdr)); if (!hdr) return NULL; hdr->id = id; hdr->type = type; hdr->buf = membuf_create(size); if (hdr->buf == NULL) { free(hdr); return NULL; } buf_append(hdr->buf, value, size); return hdr; } static void obex_hdr_membuf_destroy(void *self) { struct obex_hdr_membuf *hdr = self; buf_delete(hdr->buf); free(hdr); } static enum obex_hdr_id obex_hdr_membuf_get_id(void *self) { struct obex_hdr_membuf *hdr = self; return hdr->id; } static enum obex_hdr_type obex_hdr_membuf_get_type(void *self) { struct obex_hdr_membuf *hdr = self; return hdr->type; } static size_t obex_hdr_membuf_get_data_size(void *self) { struct obex_hdr_membuf *hdr = self; return buf_get_length(hdr->buf); } static const void * obex_hdr_membuf_get_data_ptr(void *self) { struct obex_hdr_membuf *hdr = self; return buf_get(hdr->buf); } static bool obex_hdr_membuf_set_data(void *self, const void *data, size_t size) { struct obex_hdr_membuf *hdr = self; buf_clear(hdr->buf, buf_get_length(hdr->buf)); if (buf_set_size(hdr->buf, size) != 0) return false; memcpy(buf_get(hdr->buf), data, size); return true; } static struct obex_hdr_ops obex_hdr_membuf_ops = { &obex_hdr_membuf_destroy, &obex_hdr_membuf_get_id, &obex_hdr_membuf_get_type, &obex_hdr_membuf_get_data_size, &obex_hdr_membuf_get_data_ptr, &obex_hdr_membuf_set_data, NULL, NULL, }; struct obex_hdr * obex_hdr_membuf_create(enum obex_hdr_id id, enum obex_hdr_type type, const void *data, size_t size) { void *buf = obex_hdr_membuf_new(id, type, data, size); if (!buf) return NULL; return obex_hdr_new(&obex_hdr_membuf_ops, buf); } struct databuffer * obex_hdr_membuf_get_databuffer(struct obex_hdr *hdr) { struct obex_hdr_membuf *memhdr = hdr->data; return memhdr->buf; } openobex-1.7.2-Source/lib/obex_hdr_ptr.c000644 001750 001750 00000006354 12604167677 021331 0ustar00hendrikhendrik000000 000000 /** * @file obex_hdr_ptr.c * * OBEX header releated functions. * OpenOBEX library - Free implementation of the Object Exchange protocol. * * Copyright (c) 2012 Hendrik Sattler, All Rights Reserved. * * OpenOBEX is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the * Free Software Foundation; either version 2.1 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with OpenOBEX. If not, see . */ #include "obex_hdr.h" #include "debug.h" #ifndef _WIN32 #include #endif #include struct obex_hdr_ptr { enum obex_hdr_id id; enum obex_hdr_type type; size_t size; const void *value; }; static void obex_hdr_ptr_destroy(void *self) { free(self); } static enum obex_hdr_id obex_hdr_ptr_get_id(void *self) { struct obex_hdr_ptr *ptr = self; return ptr->id; } static enum obex_hdr_type obex_hdr_ptr_get_type(void *self) { struct obex_hdr_ptr *ptr = self; return ptr->type; } static size_t obex_hdr_ptr_get_data_size(void *self) { struct obex_hdr_ptr *ptr = self; return ptr->size; } static const void * obex_hdr_ptr_get_data_ptr(void *self) { struct obex_hdr_ptr *ptr = self; return ptr->value; } static bool obex_hdr_ptr_set_data(void *self, const void *data, size_t size) { struct obex_hdr_ptr *ptr = self; ptr->value = data; ptr->size = size; return true; } static struct obex_hdr_ops obex_hdr_ptr_ops = { &obex_hdr_ptr_destroy, &obex_hdr_ptr_get_id, &obex_hdr_ptr_get_type, &obex_hdr_ptr_get_data_size, &obex_hdr_ptr_get_data_ptr, &obex_hdr_ptr_set_data, NULL, NULL, }; struct obex_hdr * obex_hdr_ptr_create(enum obex_hdr_id id, enum obex_hdr_type type, const void *data, size_t size) { struct obex_hdr_ptr *ptr = malloc(sizeof(*ptr)); if (!ptr) return NULL; ptr->id = id; ptr->type = type; ptr->size = size; ptr->value = data; return obex_hdr_new(&obex_hdr_ptr_ops, ptr); } struct obex_hdr * obex_hdr_ptr_parse(const void *msgdata, size_t size) { struct obex_hdr_ptr *ptr; uint16_t hsize; if (size < 1) return NULL; ptr = malloc(sizeof(*ptr)); if (!ptr) return NULL; ptr->id = ((uint8_t *)msgdata)[0] & OBEX_HDR_ID_MASK; ptr->type = ((uint8_t *)msgdata)[0] & OBEX_HDR_TYPE_MASK; switch (ptr->type) { case OBEX_HDR_TYPE_UNICODE: case OBEX_HDR_TYPE_BYTES: if (size < 3) goto err; memcpy(&hsize, (uint8_t *)msgdata + 1, 2); ptr->size = ntohs(hsize) - 3; if (size < (3 + ptr->size)) goto err; ptr->value = (uint8_t *)msgdata + 3; break; case OBEX_HDR_TYPE_UINT8: if (size < 2) goto err; ptr->size = 1; ptr->value = (uint8_t *)msgdata + 1; break; case OBEX_HDR_TYPE_UINT32: if (size < 5) goto err; ptr->size = 4; ptr->value = (uint8_t *)msgdata + 1; break; default: goto err; } return obex_hdr_new(&obex_hdr_ptr_ops, ptr); err: DEBUG(1, "Header too big.\n"); free(ptr); return NULL; } openobex-1.7.2-Source/lib/obex_msg.h000644 001750 001750 00000002751 12604167677 020457 0ustar00hendrikhendrik000000 000000 /** * @file obex_msg.h * * Bridge between obex object and raw message buffer. * OpenOBEX library - Free implementation of the Object Exchange protocol. * * Copyright (c) 2012 Hendrik Sattler, All Rights Reserved. * * OpenOBEX is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the * Free Software Foundation; either version 2.1 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with OpenOBEX. If not, see . */ #include "obex_incl.h" #include "defines.h" bool obex_msg_prepare(obex_t *self, obex_object_t *object, bool allowfinal); int obex_msg_getspace(obex_t *self, obex_object_t *object, unsigned int flags); bool obex_msg_rx_status(const obex_t *self); bool obex_msg_tx_status(const obex_t *self); int obex_msg_get_opcode(const obex_t *self); size_t obex_msg_get_len(const obex_t *self); void obex_msg_pre_receive(obex_t *self); int obex_msg_receive_filtered(obex_t *self, obex_object_t *object, uint64_t filter, bool first_run); int obex_msg_receive(obex_t *self, obex_object_t *object); int obex_msg_post_receive(obex_t *self); openobex-1.7.2-Source/lib/obex_object.h000644 001750 001750 00000006710 12604167677 021136 0ustar00hendrikhendrik000000 000000 /** \file obex_object.h OBEX object related functions. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999, 2000 Dag Brattli, All Rights Reserved. Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef OBEX_OBJECT_H #define OBEX_OBJECT_H #include "obex_incl.h" #include "defines.h" #if ! defined(_WIN32) # include #endif #include struct databuffer; struct databuffer_list; struct obex_object { struct databuffer *tx_nonhdr_data; /* Data before of headers (like CONNECT and SETPATH) */ struct databuffer_list *tx_headerq; /* List of headers to transmit*/ struct obex_hdr_it *tx_it; struct databuffer *rx_nonhdr_data; /* Data before of headers (like CONNECT and SETPATH) */ struct databuffer_list *rx_headerq; /* List of received headers */ struct obex_hdr_it *rx_it; struct obex_hdr_it *it; enum obex_cmd cmd; /* command */ enum obex_rsp rsp; /* response */ enum obex_rsp lastrsp; /* response for last packet */ uint16_t headeroffset; /* Where to start parsing headers */ uint32_t hinted_body_len; /* Hinted body-length or 0 */ bool abort; /* Request shall be aborted */ enum obex_rsp_mode rsp_mode; /* OBEX_RSP_MODE_* */ bool suspended; /* Temporarily stop transfering object */ struct obex_hdr *body; /* The body header need some extra help */ struct obex_body *body_rcv; /* Deliver body */ }; struct obex_object *obex_object_new(void); int obex_object_delete(struct obex_object *object); size_t obex_object_get_size(obex_object_t *object); int obex_object_addheader(struct obex *self, struct obex_object *object, uint8_t hi, obex_headerdata_t hv, uint32_t hv_size, unsigned int flags); int obex_object_getnextheader(struct obex_object *object, uint8_t *hi, obex_headerdata_t *hv, uint32_t *hv_size); int obex_object_reparseheaders(struct obex_object *object); void obex_object_setcmd(struct obex_object *object, enum obex_cmd cmd); enum obex_cmd obex_object_getcmd(const obex_object_t *object); int obex_object_setrsp(struct obex_object *object, enum obex_rsp rsp, enum obex_rsp lastrsp); int obex_object_get_opcode(obex_object_t *object, bool allowfinalcmd, enum obex_mode mode); bool obex_object_append_data(obex_object_t *object, struct databuffer *txmsg, size_t tx_left); int obex_object_finished(obex_object_t *object, bool allowfinal); int obex_object_receive_nonhdr_data(obex_object_t *object, const void *msgdata, size_t rx_left); int obex_object_receive_headers(struct obex_object *object, const void *msgdata, size_t tx_left, uint64_t filter); int obex_object_set_body_receiver(obex_object_t *object, struct obex_body *b); const void * obex_object_read_body(obex_object_t *object, size_t *size); int obex_object_suspend(struct obex_object *object); int obex_object_resume(struct obex_object *object); #endif openobex-1.7.2-Source/lib/obex_server.c000644 001750 001750 00000030135 12604167677 021167 0ustar00hendrikhendrik000000 000000 /** \file obex_server.c Handle server operations. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999-2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #include "obex_main.h" #include "obex_object.h" #include "obex_connect.h" #include "obex_server.h" #include "obex_msg.h" #include "databuffer.h" #include #include static __inline enum obex_cmd msg_get_cmd(const obex_t *self) { int opcode = obex_msg_get_opcode(self); if (opcode < 0) return OBEX_CMD_ABORT; else return (enum obex_cmd)(opcode & ~OBEX_FINAL); } static __inline int msg_get_final(const obex_t *self) { int opcode = obex_msg_get_opcode(self); if (opcode < 0) return 0; else return opcode & OBEX_FINAL; } static result_t obex_server_abort_tx(obex_t *self) { enum obex_cmd cmd = OBEX_CMD_ABORT; if (self->object) cmd = self->object->cmd; obex_deliver_event(self, self->abort_event, cmd, 0, true); self->state = STATE_IDLE; return RESULT_SUCCESS; } static result_t obex_server_abort_tx_prepare(obex_t *self, enum obex_rsp opcode, enum obex_event event) { DEBUG(4, "STATE: ABORT/PREPARE_TX\n"); self->abort_event = event; self->state = STATE_ABORT; self->substate = SUBSTATE_TX; if (!obex_data_request_init(self)) return RESULT_ERROR; obex_data_request_prepare(self, opcode | OBEX_FINAL); return RESULT_SUCCESS; } /** Generate response to ABORT request from client */ static result_t obex_server_abort_by_client(obex_t *self) { return obex_server_abort_tx_prepare(self, OBEX_RSP_SUCCESS, OBEX_EV_ABORT); } /** Generate response when application has set object_t::abort to true */ static result_t obex_server_abort_by_application(obex_t *self) { /* Use the error code provided by the application... */ enum obex_rsp opcode = self->object->lastrsp; /** ...but do not send continue/success. */ if (opcode == OBEX_RSP_CONTINUE || opcode == OBEX_RSP_SUCCESS) opcode = OBEX_RSP_INTERNAL_SERVER_ERROR; return obex_server_abort_tx_prepare(self, opcode, OBEX_EV_ABORT); } /** Generate response when we failed to parse the request packet */ static result_t obex_server_bad_request(obex_t *self) { return obex_server_abort_tx_prepare(self, OBEX_RSP_BAD_REQUEST, OBEX_EV_PARSEERR); } static result_t obex_server_response_tx_prepare(obex_t *self) { DEBUG(4, "STATE: RESPONSE/PREPARE_TX\n"); if (self->object->abort) return obex_server_abort_by_application(self); /* As a server, the final bit is always SET, and the "real final" packet * is distinguished by being SUCCESS instead of CONTINUE. * So, force the final bit here. */ if (!obex_msg_prepare(self, self->object, TRUE)) return RESULT_ERROR; self->substate = SUBSTATE_TX; return RESULT_SUCCESS; } static result_t obex_server_response_tx(obex_t *self) { int cmd = self->object->cmd; /* Made some progress */ obex_deliver_event(self, OBEX_EV_PROGRESS, cmd, 0, false); if (obex_object_finished(self->object, TRUE)) { self->state = STATE_IDLE; /* Response sent and object finished! */ if (cmd == OBEX_CMD_DISCONNECT) { DEBUG(2, "CMD_DISCONNECT done. Resetting MTU!\n"); self->mtu_tx = OBEX_MINIMUM_MTU; self->rsp_mode = OBEX_RSP_MODE_NORMAL; self->srm_flags = 0; } obex_deliver_event(self, OBEX_EV_REQDONE, cmd, 0, true); } else if (self->object->rsp_mode == OBEX_RSP_MODE_SINGLE && !(self->srm_flags & OBEX_SRM_FLAG_WAIT_LOCAL)) { self->substate = SUBSTATE_TX_PREPARE; return obex_server_response_tx_prepare(self); } else { self->substate = SUBSTATE_RX; } return RESULT_SUCCESS; } static result_t obex_server_response_rx(obex_t *self) { enum obex_cmd cmd; DEBUG(4, "STATE: RESPONSE/RECEIVE_RX\n"); if (!obex_msg_rx_status(self)) { if (self->object->rsp_mode == OBEX_RSP_MODE_SINGLE && !(self->srm_flags & OBEX_SRM_FLAG_WAIT_LOCAL)) { self->substate = SUBSTATE_TX_PREPARE; return obex_server_response_tx_prepare(self); } return RESULT_SUCCESS; } /* Single response mode makes it possible for the client to send * the next request (e.g. PUT) while still receiving the last * multi-packet response. So we must not consume any request * except ABORT. For Normal response mode, this other request is an * error. */ cmd = msg_get_cmd(self); if (cmd == OBEX_CMD_ABORT) { DEBUG(1, "Got OBEX_ABORT request!\n"); obex_data_receive_finished(self); return obex_server_abort_by_client(self); } else if (cmd == obex_object_getcmd(self->object)) { int ret = obex_msg_receive(self, self->object); obex_data_receive_finished(self); if (ret < 0) return obex_server_bad_request(self); self->substate = SUBSTATE_TX_PREPARE; return obex_server_response_tx_prepare(self); } else { if (self->object->rsp_mode == OBEX_RSP_MODE_SINGLE) { self->substate = SUBSTATE_TX_PREPARE; return obex_server_response_tx_prepare(self); } obex_data_receive_finished(self); return obex_server_bad_request(self); } } static result_t obex_server_request_tx(obex_t *self) { enum obex_cmd cmd = self->object->cmd; enum obex_rsp rsp = self->object->rsp; if (rsp == OBEX_RSP_CONTINUE) { obex_deliver_event(self, OBEX_EV_PROGRESS, cmd, rsp, false); self->substate = SUBSTATE_RX; } else { obex_deliver_event(self, OBEX_EV_REQDONE, cmd, rsp, true); self->state = STATE_IDLE; } return RESULT_SUCCESS; } static result_t obex_server_request_tx_prepare(obex_t *self) { DEBUG(4, "STATE: REQUEST/PREPARE_TX\n"); if (self->object->rsp_mode == OBEX_RSP_MODE_NORMAL || (self->object->rsp_mode == OBEX_RSP_MODE_SINGLE && self->srm_flags & OBEX_SRM_FLAG_WAIT_REMOTE)) { if (self->object->abort) return obex_server_abort_by_application(self); if (!obex_msg_prepare(self, self->object, FALSE)) return RESULT_ERROR; self->substate = SUBSTATE_TX; return RESULT_SUCCESS; } else { self->substate = SUBSTATE_RX; return RESULT_SUCCESS; } } static result_t obex_server_request_rx(obex_t *self, int first) { int deny = 0; uint64_t filter; enum obex_cmd cmd; int final; DEBUG(4, "STATE: REQUEST/RECEIVE_RX\n"); if (!obex_msg_rx_status(self)) return RESULT_SUCCESS; cmd = msg_get_cmd(self); final = msg_get_final(self); /* Abort? */ if (cmd == OBEX_CMD_ABORT) { DEBUG(1, "Got OBEX_ABORT request!\n"); obex_data_receive_finished(self); return obex_server_abort_by_client(self); } else if (cmd != obex_object_getcmd(self->object)) { /* The cmd-field of this packet is not the * same as int the first fragment. Bail out! */ obex_data_receive_finished(self); return obex_server_bad_request(self); } /* Get the non-header data and look at all non-body headers. * Leaving the body headers out here has advantages: * - we don't need to assign a data buffer if the user rejects * the request * - the user can inspect all first-packet headers before * deciding about stream mode * - the user application actually received the REQCHECK when * always using stream mode */ filter = (1 << OBEX_HDR_ID_BODY | 1 << OBEX_HDR_ID_BODY_END); /* Some commands needs special treatment (data outside headers) */ switch (cmd) { case OBEX_CMD_CONNECT: self->object->headeroffset = 4; break; case OBEX_CMD_SETPATH: self->object->headeroffset = 2; break; default: break; } if (obex_msg_receive_filtered(self, self->object, filter, true) < 0) { obex_data_receive_finished(self); return obex_server_bad_request(self); } /* Let the user decide whether to accept or deny a * multi-packet request by examining all headers in * the first packet */ if (first) obex_deliver_event(self, OBEX_EV_REQCHECK, cmd, 0, false); /* Everything except 0x1X and 0x2X means that the user * callback denied the request. In the denied cases * treat the last packet as a final one but don't * bother about body headers and don't signal * OBEX_EV_REQ. */ switch ((self->object->rsp & ~OBEX_FINAL) & 0xF0) { case OBEX_RSP_CONTINUE: case OBEX_RSP_SUCCESS: if (obex_msg_receive_filtered(self, self->object, ~filter, FALSE) < 0) { obex_data_receive_finished(self); return obex_server_bad_request(self); } break; default: final = 1; deny = 1; break; } obex_data_receive_finished(self); /* Connect needs some extra special treatment */ if (cmd == OBEX_CMD_CONNECT) { DEBUG(4, "Got CMD_CONNECT\n"); if (!final || obex_parse_connectframe(self, self->object) < 0) return obex_server_bad_request(self); } if (!final) { self->substate = SUBSTATE_TX_PREPARE; return obex_server_request_tx_prepare(self); } else { /* Tell the app that a whole request has * arrived. While this event is delivered the * app should append the headers that should be * in the response */ if (!deny) { DEBUG(4, "We got a request!\n"); obex_deliver_event(self, OBEX_EV_REQ, cmd, 0, false); } /* More connect-magic woodoo stuff */ if (cmd == OBEX_CMD_CONNECT) obex_insert_connectframe(self, self->object); self->state = STATE_RESPONSE; self->substate = SUBSTATE_TX_PREPARE; return obex_server_response_tx_prepare(self); } } static result_t obex_server_idle(obex_t *self) { enum obex_cmd cmd; /* Nothing has been recieved yet, so this is probably a new request */ DEBUG(4, "STATE: IDLE\n"); if (!obex_msg_rx_status(self)) return RESULT_SUCCESS; cmd = msg_get_cmd(self); if (self->object) { /* What shall we do here? I don't know!*/ DEBUG(0, "Got a new server-request while already having one!\n"); return RESULT_ERROR; } /* If ABORT command is done while we are not handling another command, * we don't need to send a request hint to the application */ if (cmd == OBEX_CMD_ABORT) { DEBUG(1, "Got OBEX_ABORT request!\n"); obex_data_receive_finished(self); return obex_server_abort_by_client(self); } self->object = obex_object_new(); if (self->object == NULL) { DEBUG(1, "Allocation of object failed!\n"); return RESULT_ERROR; } /* Remember the initial command of the request.*/ obex_object_setcmd(self->object, cmd); self->object->rsp_mode = self->rsp_mode; /* Hint app that something is about to come so that * the app can deny a PUT-like request early, or * set the header-offset */ obex_deliver_event(self, OBEX_EV_REQHINT, cmd, 0, false); /* Check the response from the REQHINT event */ switch ((self->object->rsp & ~OBEX_FINAL) & 0xF0) { case OBEX_RSP_CONTINUE: case OBEX_RSP_SUCCESS: self->state = STATE_REQUEST; self->substate = SUBSTATE_RX; return obex_server_request_rx(self, 1); default: obex_data_receive_finished(self); self->state = STATE_RESPONSE; self->substate = SUBSTATE_TX_PREPARE; return obex_server_response_tx_prepare(self); } } /* * Function obex_server () * * Handle server-operations * */ result_t obex_server(obex_t *self) { DEBUG(4, "\n"); switch (self->state) { case STATE_IDLE: return obex_server_idle(self); case STATE_REQUEST: switch (self->substate) { case SUBSTATE_RX: return obex_server_request_rx(self, 0); case SUBSTATE_TX_PREPARE: return obex_server_request_tx_prepare(self); case SUBSTATE_TX: return obex_server_request_tx(self); default: break; } break; case STATE_RESPONSE: switch (self->substate) { case SUBSTATE_RX: return obex_server_response_rx(self); case SUBSTATE_TX_PREPARE: return obex_server_response_tx_prepare(self); case SUBSTATE_TX: return obex_server_response_tx(self); default: break; } break; case STATE_ABORT: switch (self->substate) { case SUBSTATE_TX: return obex_server_abort_tx(self); default: break; } break; default: DEBUG(0, "Unknown state\n"); break; } return RESULT_ERROR; } openobex-1.7.2-Source/lib/obex_server.h000644 001750 001750 00000001637 12604167677 021201 0ustar00hendrikhendrik000000 000000 /** \file obex_server.h Handle server operations. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999-2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef OBEX_SERVER_H #define OBEX_SERVER_H struct obex; result_t obex_server(struct obex *self); #endif openobex-1.7.2-Source/lib/api.c000644 001750 001750 00000074170 12701160572 017405 0ustar00hendrikhendrik000000 000000 /** \file api.c OpenOBEX API definition. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999, 2000 Dag Brattli, All Rights Reserved. Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #ifdef _WIN32 #include #include #ifndef ESOCKTNOSUPPORT #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT #endif #else /* _WIN32 */ #include #include #endif /* _WIN32 */ #include #include #include #include #include "obex_main.h" #include "obex_client.h" #include "obex_object.h" #include "obex_body.h" #include "obex_msg.h" #include "obex_connect.h" #include "databuffer.h" #ifdef HAVE_IRDA #include "transport/irobex.h" #endif /*HAVE_IRDA*/ #ifdef HAVE_BLUETOOTH #include "transport/btobex.h" #endif /*HAVE_BLUETOOTH*/ #ifdef HAVE_USB #include "transport/usbobex.h" #endif /*HAVE_USB*/ #include "transport/inobex.h" #include "transport/customtrans.h" #include "transport/fdobex.h" #include "obex_incl.h" /** Initialize OBEX. \param transport Which transport to use. The following transports are available : - #OBEX_TRANS_IRDA : Use regular IrDA socket (need an IrDA stack) - #OBEX_TRANS_INET : Use regular TCP/IP socket - #OBEX_TRANS_CUSTOM : Use user provided transport, you must register your own transport with #OBEX_RegisterCTransport() - #OBEX_TRANS_BLUETOOTH: Use regular Bluetooth RFCOMM socket - #OBEX_TRANS_USB: Use USB transport (libusb needed) \param eventcb Function pointer to your event callback. See obex.h for prototype of this callback. \param flags Bitmask of flags. The following flags are available : - #OBEX_FL_KEEPSERVER : Keep the server alive after incomming request - #OBEX_FL_FILTERHINT : Filter target devices based on Obex hint bit - #OBEX_FL_FILTERIAS : Filter target devices based on IAS entry - #OBEX_FL_CLOEXEC : Open all sockets with SO_CLOEXEC set - #OBEX_FL_NONBLOCK : Open all sockets non-blocking \return an OBEX handle or NULL on error. */ LIB_SYMBOL obex_t * CALLAPI OBEX_Init(int transport, obex_event_t eventcb, unsigned int flags) { obex_t *self; obex_return_val_if_fail(eventcb != NULL, NULL); obex_library_init(); self = obex_create(eventcb, flags); if (!obex_transport_init(self, transport)) { obex_destroy(self); self = NULL; } return self; } /** Register a custom transport. \param self OBEX handle \param ctrans Structure with callbacks to transport operations (see obex_const.h for details) \return -1 on error Call this function directly after #OBEX_Init if you are using a custom transport. */ LIB_SYMBOL int CALLAPI OBEX_RegisterCTransport(obex_t *self, obex_ctrans_t *ctrans) { obex_return_val_if_fail(self != NULL, -1); obex_return_val_if_fail(ctrans != NULL, -1); return custom_register(self, ctrans); } /** Close down an OBEX instance. \param self OBEX handle Disconnects the transport and frees the interface (see #OBEX_FreeInterfaces). */ LIB_SYMBOL void CALLAPI OBEX_Cleanup(obex_t *self) { obex_return_if_fail(self != NULL); obex_destroy(self); } /** Set userdata of an OBEX handle. \param self OBEX handle \param data It's all up to you! */ LIB_SYMBOL void CALLAPI OBEX_SetUserData(obex_t *self, void *data) { obex_return_if_fail(self != NULL); self->userdata=data; } /** Read the userdata from an OBEX handle. \param self OBEX handle \return the userdata Returns userdata set with #OBEX_SetUserData. */ LIB_SYMBOL void * CALLAPI OBEX_GetUserData(obex_t *self) { obex_return_val_if_fail(self != NULL, 0); return self->userdata; } /** Change user callback on an OBEX handle. \param self OBEX handle \param eventcb Function pointer to your new event callback. \param data Pointer to the new user data to pass to the new callback (optional) */ LIB_SYMBOL void CALLAPI OBEX_SetUserCallBack(obex_t *self, obex_event_t eventcb, void *data) { obex_return_if_fail(self != NULL); /* The callback can't be NULL */ if (eventcb != NULL) { self->eventcb = eventcb; /* Optionaly change the user data */ if (data != NULL) self->userdata = data; } } /** Set MTU to be used for receive and transmit. \param self OBEX handle \param mtu_rx maximum receive transport packet size \param mtu_tx_max maximum transmit transport packet size negociated \return -1 or negative error code on error Changing those values can increase the performance of the underlying transport, but will increase memory consumption and latency (especially abort latency), and may trigger bugs in buggy transport. This need to be set *before* establishing the connection. */ LIB_SYMBOL int CALLAPI OBEX_SetTransportMTU(obex_t *self, uint16_t mtu_rx, uint16_t mtu_tx_max) { obex_return_val_if_fail(self != NULL, -EFAULT); if (self->object) { DEBUG(1, "We are busy.\n"); return -EBUSY; } return obex_set_mtu(self, mtu_rx, mtu_tx_max); } /** Start listening for incoming connections. \param self OBEX handle \param saddr Local address to bind to or NULL \param addrlen Length of address \return -1 on error Bind a server socket to an Obex service. Common transport have specialised version of this function. If you want to call the listen callback of the custom transport, use NULL for saddr and 0 for addrlen. */ LIB_SYMBOL int CALLAPI OBEX_ServerRegister(obex_t *self, struct sockaddr *saddr, int addrlen) { DEBUG(3, "\n"); obex_return_val_if_fail(self != NULL, -1); obex_return_val_if_fail((addrlen == 0) || (saddr != NULL), -1); if (addrlen != 0 && saddr != NULL && !obex_transport_set_local_addr(self, saddr, addrlen)) return -1; return obex_transport_listen(self)? 1: -1; } /** Accept an incoming connection. \param server OBEX handle \param eventcb Event callback for client (use NULL for same as server) \param data Userdata for client (use NULL for same as server) \return the client instance or NULL on error Create a new OBEX instance to handle the incomming connection. The old OBEX instance will continue to listen for new connections. The two OBEX instances become totally independant from each other. This function should be called after the library generates an #OBEX_EV_ACCEPTHINT event to the user, but before the user start to pull data out of the incomming connection. Using this function also requires that the OBEX handle was created with the #OBEX_FL_KEEPSERVER flag set while calling #OBEX_Init(). */ LIB_SYMBOL obex_t *CALLAPI OBEX_ServerAccept(obex_t *server, obex_event_t eventcb, void *data) { obex_t *self; DEBUG(3, "\n"); obex_return_val_if_fail(server != NULL, NULL); /* If we have started receiving something, it's too late... */ if (server->object != NULL) return NULL; /* Set callback and callback data as needed */ if (eventcb == NULL) eventcb = server->eventcb; if (data == NULL) data = server->userdata; /* Allocate new instance */ self = obex_create(eventcb, server->init_flags); if (self == NULL) return NULL; self->userdata = data; if (!obex_transport_accept(self, server)) goto out_err; self->mtu_tx = server->mtu_tx; if (obex_set_mtu(self, server->mtu_rx, server->mtu_tx_max)) goto out_err; self->mode = OBEX_MODE_SERVER; self->state = STATE_IDLE; self->rsp_mode = server->rsp_mode; return self; out_err: obex_destroy(self); return NULL; } /** Set the timeout for read/write operations if supported by the underlying transport. \param self OBEX handle \param timeout Maximum time to wait in milliseconds (-1 for infinite) */ LIB_SYMBOL void CALLAPI OBEX_SetTimeout(obex_t *self, int64_t timeout) { obex_return_if_fail(self != NULL); obex_transport_set_timeout(self, timeout); } /** Let the OBEX parser do some work. \param self OBEX handle \return -1 on error, 0 on timeout, positive on success Let the OBEX parser read and process incoming data, or prepare and send outgoing data. When a request has been sent (client) or you are waiting for an incoming request (server) you should call this function until the request has finished. */ LIB_SYMBOL int CALLAPI OBEX_Work(obex_t *self) { DEBUG(4, "\n"); obex_return_val_if_fail(self != NULL, -1); return obex_work(self); } /** Determine data direction of OBEX_Work() \param self OBEX handle Use this to achieve better integration of OBEX_Work() into mainloops. You should call this after each call of OBEX_Work(). If #OBEX_DATA_NONE is returned, it depends on your event callback when to re-enable mainloop events. */ LIB_SYMBOL enum obex_data_direction CALLAPI OBEX_GetDataDirection(obex_t *self) { DEBUG(4, "\n"); return obex_get_data_direction(self); } /** Let the OBEX parser do some work. \param self OBEX handle \param timeout Maximum time to wait in seconds (-1 for infinite) \return -1 on error, 0 on timeout, positive on success Deprecated. Let the OBEX parser read and process incoming data and send the response. The timeout parameter is only for the reading part, preparing and sending can take any amount of time. */ LIB_SYMBOL int CALLAPI OBEX_HandleInput(obex_t *self, int timeout) { int result; int64_t oldTimeout; enum obex_data_direction dir; obex_return_val_if_fail(self != NULL, -1); DEBUG(4, "\n"); oldTimeout = obex_transport_get_timeout(self); dir = obex_get_data_direction(self); obex_transport_set_timeout(self, timeout*1000); if (dir == OBEX_DATA_IN) { result = obex_work(self); if (result <= 0) /* timeout or error */ goto timeout_or_error; dir = obex_get_data_direction(self); } /* make the following loop more efficient */ obex_transport_set_timeout(self, -1); while (dir == OBEX_DATA_NONE || dir == OBEX_DATA_OUT) { result = obex_work(self); if (result < 0) /* error */ goto timeout_or_error; dir = obex_get_data_direction(self); } result = 1; timeout_or_error: obex_transport_set_timeout(self, oldTimeout); return result; } /** Feed OBEX with data when using a custom transport. \param self OBEX handle \param inputbuf Pointer to custom data \param actual Length of buffer \return -1 on error */ LIB_SYMBOL int CALLAPI OBEX_CustomDataFeed(obex_t *self, uint8_t *inputbuf, int actual) { DEBUG(3, "\n"); obex_return_val_if_fail(self != NULL, -1); if (inputbuf && actual > 0) buf_append(self->rx_msg, inputbuf, (size_t)actual); return obex_data_indication(self); } /** Try to connect to peer. \param self OBEX handle \param saddr Address to connect to \param addrlen Length of address \return -1 on error */ LIB_SYMBOL int CALLAPI OBEX_TransportConnect(obex_t *self, struct sockaddr *saddr, int addrlen) { DEBUG(4, "\n"); obex_return_val_if_fail(self != NULL, -1); obex_return_val_if_fail((addrlen == 0) || (saddr != NULL), -1); if (addrlen != 0 && saddr != NULL && !obex_transport_set_remote_addr(self, saddr, addrlen)) return -1; return obex_transport_connect_request(self)? 1: -1; } /** Disconnect transport. \param self OBEX handle \return -1 on error */ LIB_SYMBOL int CALLAPI OBEX_TransportDisconnect(obex_t *self) { DEBUG(4, "\n"); obex_return_val_if_fail(self != NULL, -1); obex_transport_disconnect(self); return 0; } /** Get transport file descriptor. \param self OBEX handle \return file descriptor of the transport, -1 on error Returns the file descriptor of the transport or -1 on error. Note that not all transports have a file descriptor, especially USB and custom transports do not. The returned filehandle can be used to do select() on, before calling OBEX_HandleInput() There is one subtelty about this function. When the OBEX connection is established, it returns the connection filedescriptor, while for an unconnected server it will return the listening filedescriptor. This mean that after receiving an incomming connection, you need to call this function again. */ LIB_SYMBOL int CALLAPI OBEX_GetFD(obex_t *self) { obex_return_val_if_fail(self != NULL, -1); return obex_transport_get_fd(self); } /** Schedule a request (as client). \param self OBEX handle \param object Object containing request \return 0 on success or a negative error code on failure (-EBUSY, -EINVAL, -EIO) */ LIB_SYMBOL int CALLAPI OBEX_Request(obex_t *self, obex_object_t *object) { result_t result; DEBUG(4, "\n"); obex_return_val_if_fail(self != NULL, -EINVAL); obex_return_val_if_fail(object != NULL, -EINVAL); if (self->object) { DEBUG(1, "We are busy.\n"); return -EBUSY; } object->rsp_mode = self->rsp_mode; self->object = object; self->mode = OBEX_MODE_CLIENT; self->state = STATE_REQUEST; self->substate = SUBSTATE_TX_PREPARE; /* Prepare the packet but do not send it */ result = obex_client(self); if (result < 0) { self->object = NULL; self->mode = OBEX_MODE_SERVER; self->state = STATE_IDLE; return -EIO; } return 0; } /** Cancel an ongoing operation. \param self OBEX handle \param nice If true an OBEX Abort will be sent if beeing client or respond with an error if beeing server. \return -1 on error */ LIB_SYMBOL int CALLAPI OBEX_CancelRequest(obex_t *self, int nice) { obex_return_val_if_fail(self != NULL, -1); return obex_cancelrequest(self, nice); } /** Suspend transfer of an object. \param self OBEX handle \param object object to suspend (NULL to suspend currently transfered object) \return -1 on error */ LIB_SYMBOL int CALLAPI OBEX_SuspendRequest(obex_t *self, obex_object_t *object) { obex_return_val_if_fail(object != NULL || self->object != NULL, -1); return obex_object_suspend(object ? object : self->object); } /** Resume transfer of an object. \param self OBEX handle \return -1 on error */ LIB_SYMBOL int CALLAPI OBEX_ResumeRequest(obex_t *self) { obex_return_val_if_fail(self->object != NULL, -1); return obex_object_resume(self->object); } /** Set the OBEX response mode. \param self OBEX context \param rsp_mode see OBEX_RSP_MODE_* If you want any mode other than default (#OBEX_RSP_MODE_NORMAL), you have to call this function. If you want it to affect the current object, you need to call it at the first #OBEX_EV_PROGRESS (as client) or at the #OBEX_EV_REQHINT or #OBEX_EV_REQCHECK events (as server). */ LIB_SYMBOL void CALLAPI OBEX_SetReponseMode(obex_t *self, enum obex_rsp_mode rsp_mode) { switch (rsp_mode) { case OBEX_RSP_MODE_NORMAL: case OBEX_RSP_MODE_SINGLE: self->rsp_mode = rsp_mode; if (self->object) self->object->rsp_mode = rsp_mode; break; default: break; } } /** Create a new OBEX Object. \param self OBEX handle \param cmd command of object \return pointer to a new OBEX Object, NULL on error */ LIB_SYMBOL obex_object_t * CALLAPI OBEX_ObjectNew(obex_t *self, uint8_t cmd) { obex_object_t *object; obex_return_val_if_fail(self != NULL, NULL); object = obex_object_new(); if (object == NULL) return NULL; obex_object_setcmd(object, cmd); /* Need some special woodoo magic on connect-frame */ if (cmd == OBEX_CMD_CONNECT) { if (obex_insert_connectframe(self, object) < 0) { obex_object_delete(object); object = NULL; } } return object; } /** Delete an OBEX object. \param self OBEX handle \param object object to delete. \return -1 on error Note that as soon as you have passed an object to the lib using OBEX_Request(), you shall not delete it yourself. */ LIB_SYMBOL int CALLAPI OBEX_ObjectDelete(obex_t *self, obex_object_t *object) { obex_return_val_if_fail(object != NULL, -1); return obex_object_delete(object); } /** Get available space in object. \param self OBEX handle \param object OBEX object to query \param flags OBEX_FL_FIT_ONE_PACKET or 0 \return -1 on error Returns the available space in a given obex object. This can be useful e.g. if the caller wants to check the size of the biggest body header that can be added to the current packet. */ LIB_SYMBOL int CALLAPI OBEX_ObjectGetSpace(obex_t *self, obex_object_t *object, unsigned int flags) { obex_return_val_if_fail(self != NULL, -1); obex_return_val_if_fail(object != NULL, -1); return obex_msg_getspace(self, object, flags); } /** Attach a header to an object. \param self OBEX handle \param object OBEX object \param hi Header identifier \param hv Header value \param hv_size Header size \param flags See obex.h for possible values \return -1 on error Add a new header to an object. If you want all headers to fit in one packet, use the flag #OBEX_FL_FIT_ONE_PACKET on all headers you add to an object. To stream a body add a body header with hv.bs = NULL and set the flag #OBEX_FL_STREAM_START. You will now get #OBEX_EV_STREAMEMPTY events as soon as the the parser wants you to feed it with more data. When you get an #OBEX_EV_STREAMEMPTY event give the parser some data by adding a body-header and set the flag #OBEX_FL_STREAM_DATA. When you have no more data to send set the flag #OBEX_FL_STREAM_DATAEND instead. After adding a header you are free to do whatever you want with the buffer if you are NOT streaming. If you are streaming you may not touch the buffer until you get another #OBEX_EV_STREAMEMPTY or until the request finishes. The headers will be sent in the order you add them. */ LIB_SYMBOL int CALLAPI OBEX_ObjectAddHeader(obex_t *self, obex_object_t *object, uint8_t hi, obex_headerdata_t hv, uint32_t hv_size, unsigned int flags) { obex_return_val_if_fail(self != NULL, -1); obex_return_val_if_fail(object != NULL, -1); return obex_object_addheader(self, object, hi, hv, hv_size, flags); } /** Get next available header from an object. \param self OBEX handle (ignored) \param object OBEX object \param hi Pointer to header identifier \param hv Pointer to hv \param hv_size Pointer to hv_size \return 0 when no more headers are available, -1 on error Returns 0 when no more headers are available. All headers are read-only. You will get the headers in the received order. */ LIB_SYMBOL int CALLAPI OBEX_ObjectGetNextHeader(obex_t *self, obex_object_t *object, uint8_t *hi, obex_headerdata_t *hv, uint32_t *hv_size) { obex_return_val_if_fail(object != NULL, -1); return obex_object_getnextheader(object, hi, hv, hv_size); } /** Allow the user to parse again the rx headers. \param self OBEX handle (ignored) \param object OBEX object \return 1 on success, 0 if previous parsing not completed, -1 on error Next call to #OBEX_ObjectGetNextHeader() will return the first received header. */ LIB_SYMBOL int CALLAPI OBEX_ObjectReParseHeaders(obex_t *self, obex_object_t *object) { obex_return_val_if_fail(object != NULL, -1); return obex_object_reparseheaders(object); } /** Read data from body stream. \param self OBEX handle \param object OBEX object (ignored) \param buf A pointer to a pointer which this function will set to a buffer which shall be read (and ONLY read) after this function returns. \return number of bytes in buffer, or 0 for end-of-stream, -1 on error To recieve the body as a stream call this function with buf = NULL as soon as you get an #OBEX_EV_REQHINT event. You will now recieve #OBEX_EV_STREAMAVAIL events when data is available for you. Call this function to get the data. Note! When receiving a stream data is not buffered so if you don't call this function when you get an #OBEX_EV_STREAMAVAIL event data will be lost. */ LIB_SYMBOL int CALLAPI OBEX_ObjectReadStream(obex_t *self, obex_object_t *object, const uint8_t **buf) { size_t size = 0; obex_return_val_if_fail(self != NULL, -1); object = self->object; obex_return_val_if_fail(object != NULL, -1); /* Enable streaming */ if (buf == NULL) { struct obex_body *b = obex_body_stream_create(self); int result = obex_object_set_body_receiver(object, b); if (!result) return -1; DEBUG(4, "Streaming is enabled!\n"); return 0; } if (buf) *buf = obex_object_read_body(object, &size); return (int)size; } /** Sets the response to a received request. \param object OBEX object \param rsp Respose code in non-last packets \param lastrsp Response code in last packet \return -1 on error */ LIB_SYMBOL int CALLAPI OBEX_ObjectSetRsp(obex_object_t *object, uint8_t rsp, uint8_t lastrsp) { obex_return_val_if_fail(object != NULL, -1); return obex_object_setrsp(object, rsp, lastrsp); } /** Get any data which was before headers. \param object OBEX object \param buffer Pointer to a pointer which will point to a read-only buffer \return size of the buffer or -1 for error */ LIB_SYMBOL int CALLAPI OBEX_ObjectGetNonHdrData(obex_object_t *object, uint8_t **buffer) { obex_return_val_if_fail(object != NULL, -1); if (!object->rx_nonhdr_data) return 0; *buffer = buf_get(object->rx_nonhdr_data); return buf_get_length(object->rx_nonhdr_data); } /** Set data to send before headers. \param object OBEX object \param buffer Data to send \param len Length to data \return 1 on success, -1 on error Some commands (notably SetPath) send data before headers. Use this function to set this data. */ LIB_SYMBOL int CALLAPI OBEX_ObjectSetNonHdrData(obex_object_t *object, const uint8_t *buffer, unsigned int len) { /* TODO: Check that we actually can send len bytes without * violating MTU */ obex_return_val_if_fail(object != NULL, -1); obex_return_val_if_fail(buffer != NULL, -1); if (object->tx_nonhdr_data) return -1; object->tx_nonhdr_data = membuf_create(len); if (object->tx_nonhdr_data == NULL) return -1; buf_append(object->tx_nonhdr_data, buffer, len); return 1; } /** Set headeroffset. \param object OBEX object \param offset Desired offset \return 1 on success, -1 on error Call this function when you get a OBEX_EV_REQHINT and you know that the command has data before the headers comes. You do NOT need to use this function on Connect and SetPath, they are handled automatically. */ LIB_SYMBOL int CALLAPI OBEX_ObjectSetHdrOffset(obex_object_t *object, unsigned int offset) { obex_return_val_if_fail(object != NULL, -1); object->headeroffset = offset; return 1; } /** Get the OBEX commmand of an object. \param self OBEX context \param object OBEX object (or NULL to access the current object) \return -1 on error Call this function to get the OBEX command of an object. */ LIB_SYMBOL int CALLAPI OBEX_ObjectGetCommand(obex_t *self, obex_object_t *object) { obex_return_val_if_fail(object != NULL || self->object != NULL, -1); if (object) return object->cmd; return self->object->cmd; } /** Return a human understandable string from a response-code. \param rsp Response code. \return static response code string The returned string must not be freed. If the response code is unknown, the string "Unknown response" will be returned. */ LIB_SYMBOL char * CALLAPI OBEX_ResponseToString(int rsp) { DEBUG(4, "\n"); return obex_response_to_string(rsp); } /** Set customdata of an OBEX handle. \param self OBEX handle \param data Custom Transport data \return 0 on success, -1 on error Note : this call is *reserved* to the Custom Transport and should not be use by the user/client. It allow to update the Custom Transport data originally set via OBEX_RegisterCTransport(). The Custom Transport data (or instance handle) is used to store data relative to the specific instance (i.e. connection), such as file descriptors, offsets and others, so that the Custom Transport can manage multiple connections transparently (i.e. without a lookup table). - Jean II */ LIB_SYMBOL int CALLAPI OBEX_SetCustomData(obex_t *self, void *data) { obex_return_val_if_fail(self == NULL, -1); custom_set_data(self, data); return 0; } /** Read the customdata from an OBEX handle. \param self OBEX handle \return custom transport data, NULL on error */ LIB_SYMBOL void * CALLAPI OBEX_GetCustomData(obex_t *self) { obex_return_val_if_fail(self == NULL, NULL); return custom_get_data(self); } /** Start listening for incoming TCP connections. \param self OBEX handle \param addr Address to bind to (*:650 if NULL) \param addrlen Length of address structure \return -1 on error An easier server function to use for TCP/IP (TcpOBEX) only. It supports IPv4 (AF_INET) and IPv6 (AF_INET6). Note: INADDR_ANY will get mapped to IN6ADDR_ANY and using port 0 will select the default OBEX port. */ LIB_SYMBOL int CALLAPI TcpOBEX_ServerRegister(obex_t *self, struct sockaddr *addr, int addrlen) { DEBUG(3, "\n"); errno = EINVAL; obex_return_val_if_fail(self != NULL, -1); inobex_prepare_listen(self, addr, addrlen); return obex_transport_listen(self)? 1: -1; } /** Connect TCP transport. \param self OBEX handle \param addr Address to connect to ([::1]:650 if NULL) \param addrlen Length of address structure \return -1 on error An easier connect function to use for TCP/IP (TcpOBEX) only. It supports IPv4 (AF_INET) and IPv6 (AF_INET6). */ LIB_SYMBOL int CALLAPI TcpOBEX_TransportConnect(obex_t *self, struct sockaddr *addr, int addrlen) { DEBUG(4, "\n"); errno = EINVAL; obex_return_val_if_fail(self != NULL, -1); if (self->object) { DEBUG(1, "We are busy.\n"); errno = EBUSY; return -1; } inobex_prepare_connect(self, addr, addrlen); return obex_transport_connect_request(self)? 1: -1; } /** Start listening for incoming connections. \param self OBEX handle \param service Service to bind to. \return -1 or negative error code on error An easier server function to use for IrDA (IrOBEX) only. */ LIB_SYMBOL int CALLAPI IrOBEX_ServerRegister(obex_t *self, const char *service) { DEBUG(3, "\n"); obex_return_val_if_fail(self != NULL, -1); obex_return_val_if_fail(service != NULL, -1); #ifdef HAVE_IRDA irobex_prepare_listen(self, service); return obex_transport_listen(self)? 1: -1; #else return -ESOCKTNOSUPPORT; #endif /* HAVE_IRDA */ } /** Connect Irda transport. \param self OBEX handle \param service IrIAS service name to connect to \return -1 or negative error code on error An easier connect function to use for IrDA (IrOBEX) only. */ LIB_SYMBOL int CALLAPI IrOBEX_TransportConnect(obex_t *self, const char *service) { obex_interface_t *intf; int err; DEBUG(4, "\n"); err = OBEX_EnumerateInterfaces(self); if (err <= 0) return -1; intf = OBEX_GetInterfaceByIndex(self, 0); intf->irda.service = service; return OBEX_InterfaceConnect(self, intf); } /** Start listening for incoming connections. \param self OBEX handle \param src source address to listen on \param channel source channel to listen on \return -1 or negative error code on error An easier server function to use for Bluetooth (Bluetooth OBEX) only. */ LIB_SYMBOL int CALLAPI BtOBEX_ServerRegister(obex_t *self, const bt_addr_t *src, uint8_t channel) { DEBUG(3, "\n"); obex_return_val_if_fail(self != NULL, -1); #ifdef HAVE_BLUETOOTH if (src == NULL) src = BDADDR_ANY; btobex_prepare_listen(self, src, channel); return obex_transport_listen(self)? 1: -1; #else return -ESOCKTNOSUPPORT; #endif /* HAVE_BLUETOOTH */ } /** Connect Bluetooth transport. \param self OBEX handle \param src source address to connect from \param dst destination address to connect to \param channel destination channel to connect to \return -1 or negative error code on error An easier connect function to use for Bluetooth (Bluetooth OBEX) only. */ LIB_SYMBOL int CALLAPI BtOBEX_TransportConnect(obex_t *self, const bt_addr_t *src, const bt_addr_t *dst, uint8_t channel) { DEBUG(4, "\n"); obex_return_val_if_fail(self != NULL, -1); if (self->object) { DEBUG(1, "We are busy.\n"); return -EBUSY; } obex_return_val_if_fail(dst != NULL, -1); #ifdef HAVE_BLUETOOTH if (src == NULL) src = BDADDR_ANY; btobex_prepare_connect(self, src, dst, channel); return obex_transport_connect_request(self)? 1: -1; #else return -ESOCKTNOSUPPORT; #endif /* HAVE_BLUETOOTH */ } /* FdOBEX_TransportSetup - setup descriptors for OBEX_TRANS_FD transport. \param self OBEX handle \param rfd descriptor to read \param wfd descriptor to write \param mtu (ignored) \return -1 or negative error code on error */ LIB_SYMBOL int CALLAPI FdOBEX_TransportSetup(obex_t *self, int rfd, int wfd, int mtu) { DEBUG(4, "\n"); obex_return_val_if_fail(self != NULL, -1); if (self->object) { DEBUG(1, "We are busy.\n"); return -EBUSY; } fdobex_set_fd(self, rfd, wfd); return obex_transport_connect_request(self)? 1: -1; } /** Connect USB interface. \param self OBEX handle \param intf USB interface to connect to \return -1 or negative error code on error An easier connect function to connect to a discovered interface (currently USB OBEX only). */ LIB_SYMBOL int CALLAPI OBEX_InterfaceConnect(obex_t *self, obex_interface_t *intf) { DEBUG(4, "\n"); obex_return_val_if_fail(self != NULL, -1); if (self->object) { DEBUG(1, "We are busy.\n"); return -EBUSY; } obex_return_val_if_fail(intf != NULL, -1); if (self->trans->ops->client.select_interface) { if (!self->trans->ops->client.select_interface(self, intf)) return -1; return obex_transport_connect_request(self)? 1: -1; } else return -ESOCKTNOSUPPORT; } /** Find OBEX interfaces on the system. \param self OBEX handle \return the number of OBEX interfaces. */ LIB_SYMBOL int CALLAPI OBEX_EnumerateInterfaces(obex_t *self) { DEBUG(4, "\n"); obex_return_val_if_fail(self != NULL, -1); OBEX_FreeInterfaces(self); obex_transport_enumerate(self); return self->interfaces_number; } /** Get OBEX interface information. \param self OBEX handle \param i interface number \return OBEX interface information. */ LIB_SYMBOL obex_interface_t * CALLAPI OBEX_GetInterfaceByIndex(obex_t *self, int i) { DEBUG(4, "\n"); obex_return_val_if_fail(self != NULL, NULL); if (i >= self->interfaces_number || i < 0) return NULL; return &self->interfaces[i]; } /** Free memory allocated to OBEX interface structures. \param self OBEX handle Frees memory allocated to OBEX interface structures after it has been allocated by OBEX_EnumerateInterfaces. */ LIB_SYMBOL void CALLAPI OBEX_FreeInterfaces(obex_t *self) { obex_return_if_fail(self != NULL); obex_transport_free_interfaces(self); } openobex-1.7.2-Source/lib/obex_connect.h000644 001750 001750 00000002022 12604167677 021311 0ustar00hendrikhendrik000000 000000 /** \file obex_connect.h Parse and create connect-command. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenOBEX. If not, see . */ #ifndef OBEX_CONNECT_H #define OBEX_CONNECT_H struct obex; struct obex_object; int obex_insert_connectframe(struct obex *self, struct obex_object *object); int obex_parse_connectframe(struct obex *self, struct obex_object *object); #endif openobex-1.7.2-Source/lib/obex_hdr_stream.c000644 001750 001750 00000010422 12604167677 022006 0ustar00hendrikhendrik000000 000000 /** * @file obex_hdr_stream.c * * OBEX header releated functions. * OpenOBEX library - Free implementation of the Object Exchange protocol. * * Copyright (c) 2012 Hendrik Sattler, All Rights Reserved. * * OpenOBEX is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the * Free Software Foundation; either version 2.1 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with OpenOBEX. If not, see . */ #include #include #include struct obex_hdr_stream { struct obex *obex; /** Pointer to streaming data */ struct obex_hdr *data; /** Current offset in buf */ size_t s_offset; /** End of stream */ bool s_stop; }; static void obex_hdr_stream_destroy(void *self) { struct obex_hdr_stream *hdr = self; obex_hdr_destroy(hdr->data); free(hdr); } static enum obex_hdr_id obex_hdr_stream_get_id(void *self) { struct obex_hdr_stream *hdr = self; return obex_hdr_get_id(hdr->data); } static enum obex_hdr_type obex_hdr_stream_get_type(void *self) { struct obex_hdr_stream *hdr = self; return obex_hdr_get_type(hdr->data); } static void obex_hdr_stream_refresh(struct obex_hdr_stream *hdr) { if (!hdr->s_stop) { struct obex *obex = hdr->obex; struct obex_object *object = obex->object; enum obex_cmd cmd = obex_object_getcmd(object); /* Ask app for more data if no more */ obex_hdr_set_data(hdr->data, NULL, 0); hdr->s_offset = 0; obex_deliver_event(obex, OBEX_EV_STREAMEMPTY, cmd, 0, FALSE); DEBUG(4, "s_size=%lu, s_stop=%d\n", (unsigned long)obex_hdr_get_data_size(hdr->data), hdr->s_stop); } } static size_t obex_hdr_stream_get_data_size(void *self) { struct obex_hdr_stream *hdr = self; size_t data_size = obex_hdr_get_data_size(hdr->data) - hdr->s_offset; if (data_size == 0) { obex_hdr_stream_refresh(hdr); data_size = obex_hdr_get_data_size(hdr->data) - hdr->s_offset; } return data_size; } static const void * obex_hdr_stream_get_data_ptr(void *self) { struct obex_hdr_stream *hdr = self; const void *ptr = obex_hdr_get_data_ptr(hdr->data); if (ptr == NULL) return NULL; else return (uint8_t *)ptr + hdr->s_offset; } static bool obex_hdr_stream_set_data(void *self, const void *data, size_t size) { struct obex_hdr_stream *hdr = self; return obex_hdr_set_data(hdr->data, data, size); } static size_t obex_hdr_stream_append_data(void *self, struct databuffer *buf, size_t size) { struct obex_hdr_stream *hdr = self; size_t ret = 0; const void *ptr; size_t data_size = obex_hdr_stream_get_data_size(hdr); /* this function _must_ only be called _after_ get_data_size() */ ptr = obex_hdr_stream_get_data_ptr(hdr); if (data_size == 0 || ptr == NULL) return 0; if (size < data_size) { DEBUG(4, "More data than tx_left. Buffer will not be empty\n"); buf_append(buf, ptr, size); hdr->s_offset += size; ret += size; } else { DEBUG(4, "Less data than tx_left. Buffer will be empty\n"); ptr = obex_hdr_stream_get_data_ptr(self); buf_append(buf, ptr, data_size); hdr->s_offset += data_size; ret += data_size; } return ret; } static bool obex_hdr_stream_is_finished(void *self) { struct obex_hdr_stream *hdr = self; return hdr->s_stop && (obex_hdr_stream_get_data_size(hdr) == 0); } static struct obex_hdr_ops obex_hdr_stream_ops = { &obex_hdr_stream_destroy, &obex_hdr_stream_get_id, &obex_hdr_stream_get_type, &obex_hdr_stream_get_data_size, &obex_hdr_stream_get_data_ptr, &obex_hdr_stream_set_data, &obex_hdr_stream_append_data, &obex_hdr_stream_is_finished, }; struct obex_hdr * obex_hdr_stream_create(struct obex *obex, struct obex_hdr *data) { struct obex_hdr_stream *hdr = calloc(1, sizeof(*hdr)); if (!hdr) return NULL; hdr->obex = obex; hdr->data = data; return obex_hdr_new(&obex_hdr_stream_ops, hdr); } void obex_hdr_stream_finish(struct obex_hdr *hdr) { struct obex_hdr_stream *s = hdr->data; s->s_stop = true; } openobex-1.7.2-Source/lib/openobex.rc.in000644 001750 001750 00000002154 12701161273 021232 0ustar00hendrikhendrik000000 000000 #include VS_VERSION_INFO VERSIONINFO FILEVERSION @openobex_VERSION_MAJOR@,@openobex_VERSION_MINOR@,@openobex_VERSION_PATCH@,0 PRODUCTVERSION @openobex_VERSION_MAJOR@,@openobex_VERSION_MINOR@,@openobex_VERSION_PATCH@,0 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK #ifndef NDEBUG FILEFLAGS 0 #else FILEFLAGS VER_DEBUG #endif FILEOS VOS_NT_WINDOWS32 #ifdef OPENOBEX_EXPORTS FILETYPE VFT_DLL #else FILETYPE VFT_STATIC_LIB #endif FILESUBTYPE VFT2_UNKNOWN BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "04090000" BEGIN VALUE "FileDescription", "Object Exchange Protocol Implementation" VALUE "FileVersion", "@openobex_VERSION@" VALUE "InternalName", "openobex" VALUE "LegalCopyright", "Licensed under GPLv2 or any later version" VALUE "OriginalFilename", "openobex.dll" VALUE "ProductName", "OpenObex" VALUE "ProductVersion", "@openobex_VERSION@" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1200 END END openobex-1.7.2-Source/lib/obex_object.c000644 001750 001750 00000035707 12604167677 021141 0ustar00hendrikhendrik000000 000000 /** \file obex_object.c OBEX object related functions. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved. Copyright (c) 1999, 2000 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #include "obex_main.h" #include "obex_object.h" #include "obex_hdr.h" #include "obex_body.h" #include "obex_msg.h" #include "obex_connect.h" #include "databuffer.h" #include #include #include /* * Function obex_object_new () * * Create a new OBEX object * */ obex_object_t *obex_object_new(void) { obex_object_t *object = calloc(1, sizeof(*object)); if (object != NULL) obex_object_setrsp(object, OBEX_RSP_NOT_IMPLEMENTED, OBEX_RSP_NOT_IMPLEMENTED); return object; } /* * Function free_headerq(q) * * Free all headers in a header queue. * */ static void free_headerq(slist_t *q, const struct obex_hdr *no_delete) { DEBUG(4, "\n"); while (!slist_is_empty(q)) { struct obex_hdr *h = slist_get(q); q = slist_remove(q, h); if (h != no_delete) obex_hdr_destroy(h); } } /* * Function obex_object_delete (object) * * Delete OBEX object * */ int obex_object_delete(obex_object_t *object) { DEBUG(4, "\n"); obex_return_val_if_fail(object != NULL, -1); /* Free the headerqueues */ obex_hdr_it_destroy(object->tx_it); free_headerq(object->tx_headerq, object->body); /* Free tx non-header data */ if (object->tx_nonhdr_data) { buf_delete(object->tx_nonhdr_data); object->tx_nonhdr_data = NULL; } /* Free the headerqueues */ obex_hdr_it_destroy(object->it); obex_hdr_it_destroy(object->rx_it); free_headerq(object->rx_headerq, object->body); /* Free rx non-header data */ if (object->rx_nonhdr_data) { buf_delete(object->rx_nonhdr_data); object->rx_nonhdr_data = NULL; } if (object->body != NULL) { obex_hdr_destroy(object->body); object->body = NULL; } free(object); return 0; } /* * Function obex_object_setcmd () * * Set command of object * */ void obex_object_setcmd(obex_object_t *object, enum obex_cmd cmd) { DEBUG(4,"%02x\n", cmd); object->cmd = cmd & ~OBEX_FINAL; } /* * Function obex_object_setrsp () * * Set the response for an object * */ int obex_object_setrsp(obex_object_t *object, enum obex_rsp rsp, enum obex_rsp lastrsp) { DEBUG(4,"\n"); object->rsp = rsp; object->lastrsp = lastrsp; return 1; } size_t obex_object_get_size(obex_object_t *object) { size_t objlen = 0; if (object->tx_nonhdr_data) objlen += buf_get_length(object->tx_nonhdr_data); if (object->tx_it) { struct obex_hdr_it it; struct obex_hdr *hdr; obex_hdr_it_init_from(&it, object->tx_it); hdr = obex_hdr_it_get(&it); while (hdr != NULL) { objlen += obex_hdr_get_size(hdr); obex_hdr_it_next(&it); hdr = obex_hdr_it_get(&it); } } return objlen; } /** Add a header to an objext TX queue * @deprecated */ int obex_object_addheader(obex_t *self, obex_object_t *object, uint8_t hi, obex_headerdata_t hv, uint32_t hv_size, unsigned int flags) { int ret; struct obex_hdr *hdr; const void *value; uint32_t bq4; size_t size; enum obex_hdr_id id = hi & OBEX_HDR_ID_MASK; enum obex_hdr_type type = hi & OBEX_HDR_TYPE_MASK; unsigned int flags2 = OBEX_FL_COPY; DEBUG(4, "\n"); if (object == NULL) object = self->object; if (object == NULL) return -1; if (id == OBEX_HDR_ID_BODY_END) { id = OBEX_HDR_ID_BODY; if (object->body) flags &= OBEX_FL_STREAM_DATAEND; } if (id == OBEX_HDR_ID_BODY) { if (flags & OBEX_FL_STREAM_DATAEND) { /* End of stream marker */ if (object->body == NULL) { /* A body with a single chunk. */ hdr = obex_hdr_ptr_create(OBEX_HDR_ID_BODY_END, OBEX_HDR_TYPE_BYTES, hv.bs, hv_size); hdr = obex_hdr_stream_create(self, hdr); obex_hdr_stream_finish(hdr); } else { /* Set the remaining data on the BODY header... */ obex_hdr_set_data(object->body, hv.bs, hv_size); obex_hdr_stream_finish(object->body); object->body = NULL; /* ...and add the BODY_END header to the end */ hdr = obex_hdr_ptr_create(OBEX_HDR_ID_BODY_END, OBEX_HDR_TYPE_BYTES, NULL, 0); } ret = 1; goto out; } else if (flags & OBEX_FL_STREAM_CONTINUE) { /* Continue stream after all other headers */ if (object->body == NULL) return -1; obex_hdr_stream_finish(object->body); hdr = obex_hdr_ptr_create(id, OBEX_HDR_TYPE_BYTES, hv.bs, hv_size); hdr = obex_hdr_stream_create(self, hdr); object->body = hdr; ret = 1; goto out; } else if (flags & OBEX_FL_STREAM_DATA) { /* Stream data */ if (object->body == NULL) return -1; obex_hdr_set_data(object->body, hv.bs, hv_size); return 1; } else if (flags & OBEX_FL_STREAM_START) { /* Is this a stream? */ DEBUG(3, "Adding stream\n"); if (object->body) return -1; hdr = obex_hdr_ptr_create(id, OBEX_HDR_TYPE_BYTES, hv.bs, hv_size); hdr = obex_hdr_stream_create(self, hdr); object->body = hdr; ret = 1; goto out; } } switch (type) { case OBEX_HDR_TYPE_UINT32: DEBUG(2, "4BQ header %d\n", hv.bq4); bq4 = htonl(hv.bq4); value = &bq4; size = 4; break; case OBEX_HDR_TYPE_UINT8: DEBUG(2, "1BQ header %d\n", hv.bq1); value = &hv.bq1; size = 1; break; case OBEX_HDR_TYPE_BYTES: DEBUG(2, "BS header size %d\n", hv_size); value = hv.bs; size = hv_size; break; case OBEX_HDR_TYPE_UNICODE: DEBUG(2, "Unicode header size %d\n", hv_size); value = hv.bs; size = hv_size; break; default: return -1; } if (hi == OBEX_HDR_EMPTY) { DEBUG(2, "Empty header\n"); id = OBEX_HDR_ID_INVALID; type = OBEX_HDR_TYPE_INVALID; value = NULL; size = 0; flags2 = 0; } flags2 |= (flags & OBEX_FL_SUSPEND); hdr = obex_hdr_create(id, type, value, size, flags2); if (!hdr) return -1; ret = (int)obex_hdr_get_size(hdr); /* Check if you can send this header without violating MTU or * OBEX_FIT_ONE_PACKET */ if (!obex_hdr_is_splittable(hdr) && (flags & OBEX_FL_FIT_ONE_PACKET)) { int maxlen = obex_msg_getspace(self, object, flags); if (maxlen < ret) { DEBUG(0, "Header to big\n"); obex_hdr_destroy(hdr); return -1; } } out: object->tx_headerq = slist_append(object->tx_headerq, hdr); if (object->tx_it == NULL) object->tx_it = obex_hdr_it_create(object->tx_headerq); return ret; } enum obex_cmd obex_object_getcmd(const obex_object_t *object) { return object->cmd; } int obex_object_get_opcode(obex_object_t *object, bool allowfinal, enum obex_mode mode) { int opcode = -1; /* Decide which command to use, and if to use final-bit */ DEBUG(4, "allowfinalcmd: %d mode:%d\n", allowfinal, mode); switch (mode) { case OBEX_MODE_SERVER: if (obex_object_finished(object, allowfinal)) opcode = object->lastrsp; else opcode = object->rsp; opcode |= OBEX_FINAL; break; case OBEX_MODE_CLIENT: opcode = object->cmd; /* Have more headers (or body) to send? */ if (obex_object_finished(object, allowfinal)) opcode |= OBEX_FINAL; break; default: break; } return opcode; } bool obex_object_append_data(obex_object_t *object, buf_t *txmsg, size_t tx_left) { /* Don't do anything if object is suspended */ if (object->suspended) return false; /* Add nonheader-data first if any (SETPATH, CONNECT)*/ if (object->tx_nonhdr_data) { DEBUG(4, "Adding %lu bytes of non-headerdata\n", (unsigned long)buf_get_length(object->tx_nonhdr_data)); buf_append(txmsg, buf_get(object->tx_nonhdr_data), buf_get_length(object->tx_nonhdr_data)); buf_delete(object->tx_nonhdr_data); object->tx_nonhdr_data = NULL; } DEBUG(4, "4\n"); /* Take headers from the tx queue and try to stuff as * many as possible into the tx-msg */ if (object->tx_it) { bool has_body_header = false; struct obex_hdr *h = obex_hdr_it_get(object->tx_it); while (h != NULL && !object->suspended && tx_left > 0) { enum obex_hdr_id id = obex_hdr_get_id(h); if (id == OBEX_HDR_ID_BODY || id == OBEX_HDR_ID_BODY_END) { if (has_body_header) break; has_body_header = true; } if (id != OBEX_HDR_ID_INVALID) { size_t ret = obex_hdr_append(h, txmsg, tx_left); if (ret == 0) break; tx_left -= ret; } if (obex_hdr_is_finished(h)) { if (h->flags & OBEX_FL_SUSPEND) object->suspended = true; obex_hdr_it_next(object->tx_it); h = obex_hdr_it_get(object->tx_it); } } } return true; } int obex_object_finished(obex_object_t *object, bool allowfinal) { return (!object->suspended && (!object->tx_it || !obex_hdr_it_get(object->tx_it)) && allowfinal); } /* * Function obex_object_getnextheader() * * Return the next header in the rx-queue * */ int obex_object_getnextheader(obex_object_t *object, uint8_t *hi, obex_headerdata_t *hv, uint32_t *hv_size) { const uint8_t *bq1; const uint32_t *bq4; struct obex_hdr *h; DEBUG(4, "\n"); /* No more headers */ if (slist_is_empty(object->rx_headerq)) return 0; if (!object->it) object->it = obex_hdr_it_create(object->rx_headerq); if (!object->it) return -1; h = obex_hdr_it_get(object->it); if (h == NULL) return 0; obex_hdr_it_next(object->it); *hi = obex_hdr_get_id(h) | obex_hdr_get_type(h); *hv_size= (uint32_t)obex_hdr_get_data_size(h); switch (obex_hdr_get_type(h)) { case OBEX_HDR_TYPE_BYTES: case OBEX_HDR_TYPE_UNICODE: hv->bs = obex_hdr_get_data_ptr(h); break; case OBEX_HDR_TYPE_UINT32: bq4 = obex_hdr_get_data_ptr(h); hv->bq4 = ntohl(*bq4); break; case OBEX_HDR_TYPE_UINT8: bq1 = obex_hdr_get_data_ptr(h); hv->bq1 = bq1[0]; break; default: return -1; } return 1; } /* * Function obex_object_reparseheader() * * Allow the user to re-parse the headers in the rx-queue * */ int obex_object_reparseheaders(obex_object_t *object) { DEBUG(4, "\n"); /* Check that there is no more active headers */ if (object->it) { obex_hdr_it_destroy(object->it); object->it = NULL; } /* Success */ return 1; } /* * Function obex_object_receive() * * Process non-header data from an incoming message. */ int obex_object_receive_nonhdr_data(obex_object_t *object, const void *msgdata, size_t rx_left) { DEBUG(4, "\n"); if (object->headeroffset == 0) return 0; if (object->headeroffset > rx_left) return -1; /* Copy any non-header data (like in CONNECT and SETPATH) */ object->rx_nonhdr_data = membuf_create(object->headeroffset); if (!object->rx_nonhdr_data) return -1; buf_append(object->rx_nonhdr_data, msgdata, object->headeroffset); DEBUG(4, "Command has %lu bytes non-headerdata\n", (unsigned long)buf_get_length(object->rx_nonhdr_data)); return 0; } static int obex_object_receive_body(obex_object_t *object, struct obex_hdr *hdr) { enum obex_hdr_id id = obex_hdr_get_id(hdr); DEBUG(4, "\n"); if (id == OBEX_HDR_ID_BODY || id == OBEX_HDR_ID_BODY_END) { if (!object->body_rcv) object->body_rcv = obex_body_buffered_create(object); if (!object->body_rcv) return -1; if (obex_body_rcv(object->body_rcv, hdr) < 0) return -1; if (id == OBEX_HDR_ID_BODY) { DEBUG(4, "Normal body fragment...\n"); /* We have already handled this data! */ } return 1; } else if (obex_hdr_get_id(hdr) == OBEX_HDR_ID_LENGTH && !object->body) { /* The length MAY be useful when receiving body. */ uint32_t value; memcpy(&value, obex_hdr_get_data_ptr(hdr), sizeof(value)); object->hinted_body_len = ntohl(value); DEBUG(4, "Hinted body len is %d\n", object->hinted_body_len); } return 0; } static int obex_object_rcv_one_header(obex_object_t *object, struct obex_hdr *hdr) { enum obex_hdr_id id = obex_hdr_get_id(hdr); enum obex_hdr_type type = obex_hdr_get_type(hdr); const void *data = obex_hdr_get_data_ptr(hdr); size_t len = obex_hdr_get_data_size(hdr); DEBUG(4, "\n"); hdr = obex_hdr_membuf_create(id, type, data, len); if (hdr == NULL) return -1; /* Add element to rx-list */ object->rx_headerq = slist_append(object->rx_headerq, hdr); if (object->rx_it == NULL) object->rx_it = obex_hdr_it_create(object->rx_headerq); return 0; } /* * Function obex_object_receive_headers() * * Add any incoming headers to headerqueue but does not remove them from * the message buffer. * Returns the total number of bytes of the added headers or -1; */ int obex_object_receive_headers(struct obex_object *object, const void *msgdata, size_t tx_left, uint64_t filter) { size_t offset = 0; int consumed = 0; const uint64_t body_filter = (1 << OBEX_HDR_ID_BODY | 1 << OBEX_HDR_ID_BODY_END); DEBUG(4, "\n"); while (offset < tx_left) { struct obex_hdr *hdr = obex_hdr_ptr_parse((uint8_t *)msgdata + offset, tx_left - offset); size_t hlen; int err = 0; uint64_t header_bit; if (hdr == NULL) break; hlen = obex_hdr_get_size(hdr); DEBUG(4, "Header: type=%02x, id=%02x, size=%ld\n", obex_hdr_get_type(hdr), obex_hdr_get_id(hdr), (unsigned long)hlen); /* Push the body header data either to the application * or to an internal receive buffer. * This also uses the length header in the latter case * but the filter is not checked for it as it's only an * optimisation (currently only works if BODY header is * part of first message). */ if (hdr && (filter & body_filter) == 0) { int used = obex_object_receive_body(object, hdr); if (used != 0) { obex_hdr_destroy(hdr); hdr = NULL; } if (used < 0) err = -1; if (used > 0) consumed += hlen; } /* This adds all headers to an internal list of headers that * the application can walk easily. Body headers are only added * if not in streaming mode and only after end-of-body was * received. */ if (hdr) { enum obex_hdr_id id = obex_hdr_get_id(hdr); header_bit = (uint64_t) 1 << id; if (!(filter & header_bit)) { err = obex_object_rcv_one_header(object, hdr); consumed += hlen; } obex_hdr_destroy(hdr); } if (err) return err; offset += hlen; } return consumed; } int obex_object_set_body_receiver(obex_object_t *object, struct obex_body *b) { if (!object->body_rcv) object->body_rcv = b; return (object->body_rcv == b); } const void * obex_object_read_body(obex_object_t *object, size_t *size) { return obex_body_read(object->body_rcv, size); } int obex_object_suspend(obex_object_t *object) { if (object->suspended) return -1; object->suspended = true; return 0; } int obex_object_resume(obex_object_t *object) { if (!object->suspended) return -1; object->suspended = false; return 0; } openobex-1.7.2-Source/lib/cloexec.h000644 001750 001750 00000003542 11734132217 020256 0ustar00hendrikhendrik000000 000000 /** \file cloexec.h close-on-exec wrapper functions. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2010 Hendrik Sattler, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef _WIN32 #include #include #include static __inline void fcntl_cloexec(socket_t fd) { if (fd != INVALID_SOCKET) (void)fcntl(fd, F_SETFD, FD_CLOEXEC); } #else static __inline void fcntl_cloexec(socket_t fd) { fd = fd; } #endif static __inline socket_t socket_cloexec(int domain, int type, int proto) { #ifdef SOCK_CLOEXEC return socket(domain, type | SOCK_CLOEXEC, proto); #else socket_t fd = socket(domain, type, proto); fcntl_cloexec(fd); return fd; #endif } /* This supports an accept4() equivalent on NetBSD 6 and later */ #if defined(SOCK_CLOEXEC) && defined(__NetBSD__) static __inline int accept4(int s, struct sockaddr * addr, socklen_t *addrlen, int flags) { return paccept(s, addr, addrlen, NULL, flags); } #endif static __inline socket_t accept_cloexec(socket_t sockfd, struct sockaddr *addr, socklen_t *addrlen) { #ifdef SOCK_CLOEXEC return accept4(sockfd, addr, addrlen, SOCK_CLOEXEC); #else socket_t fd = accept(sockfd, addr, addrlen); fcntl_cloexec(fd); return fd; #endif } openobex-1.7.2-Source/lib/win32compat.c000644 001750 001750 00000002460 11764323252 020777 0ustar00hendrikhendrik000000 000000 /** \file win32compat.c Functions used only by the win32 platform. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #include #include #include "obex_main.h" // The MSVC preprocessor can't handle variable argument macros, // so we are forced to do it as a function void log_debug(char *format, ...) { va_list ap; va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); } void DEBUG(int n, const char *format, ...) { if (n <= obex_debug) { va_list ap; va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); } } openobex-1.7.2-Source/lib/openobex-build-settings.cmake.in000644 001750 001750 00000000060 11767023227 024642 0ustar00hendrikhendrik000000 000000 set(OpenObex_SOURCE_DIR "@PROJECT_SOURCE_DIR@") openobex-1.7.2-Source/lib/debug.h000644 001750 001750 00000002034 11730664157 017726 0ustar00hendrikhendrik000000 000000 #ifndef OPENOBEX_DEBUG_H #define OPENOBEX_DEBUG_H #if defined(_MSC_VER) && _MSC_VER < 1400 void log_debug(char *format, ...); #define log_debug_prefix "" #elif defined(OBEX_SYSLOG) && !defined(_WIN32) #include #define log_debug(format, ...) syslog(LOG_DEBUG, format, ## __VA_ARGS__) #define log_debug_prefix "OpenOBEX: " #else #include #define log_debug(format, ...) fprintf(stderr, format, ## __VA_ARGS__) #define log_debug_prefix "" #endif /* use integer: 0 for production * 1 for verification * >2 for debug */ extern int obex_debug; #if defined(_MSC_VER) && _MSC_VER < 1400 void DEBUG(int n, const char *format, ...); #else # define DEBUG(n, format, ...) \ if (obex_debug >= (n)) \ log_debug("%s%s(): " format, log_debug_prefix, __FUNCTION__, ## __VA_ARGS__) #endif /* use bitmask: 0x1 for sendbuff * 0x2 for receivebuff */ extern int obex_dump; #define DUMPBUFFER(n, label, msg) \ if ((obex_dump & 0x3) & (n)) buf_dump(msg, label); #endif openobex-1.7.2-Source/lib/transport/000755 001750 001750 00000000000 12701534273 020516 5ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/lib/transport/usbutils.h000644 001750 001750 00000001776 12701160572 022551 0ustar00hendrikhendrik000000 000000 /** \file usbutils.h USB OBEX, USB transport for OBEX, support functions. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2009 Alex Kanavin, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef USBUTILS_H #define USBUTILS_H #include void find_obex_service_descriptor(const char *buffer, int buflen, obex_usb_intf_service_t **service); #endif openobex-1.7.2-Source/lib/transport/irda_wrap.h000644 001750 001750 00000000743 11734666076 022657 0ustar00hendrikhendrik000000 000000 #ifndef IRDA_WRAP_H #define IRDA_WRAP_H #if defined(HAVE_IRDA_WINDOWS) #ifndef _WIN32_WINNT #define _WIN32_WINNT 1 #endif #include #define irda_device_info _WINDOWS_IRDA_DEVICE_INFO #define irda_device_list _WINDOWS_DEVICELIST #define irda_ias_set _WINDOWS_IAS_QUERY #define sockaddr_irda _SOCKADDR_IRDA #define sir_family irdaAddressFamily #define sir_name irdaServiceName #elif defined(HAVE_IRDA_LINUX) #include #endif #endif /* IRDA_WRAP_H */ openobex-1.7.2-Source/lib/transport/fdobex.c000644 001750 001750 00000010673 12701160572 022135 0ustar00hendrikhendrik000000 000000 /** \file fdobex.c FD OBEX, file descriptor transport for OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved. Copyright (c) 1999, 2000 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #include #include "obex_main.h" #include "fdobex.h" #include "databuffer.h" #include #include #if defined(_WIN32) #include #define fd_t unsigned int #else #define fd_t int #endif struct fdobex_data { fd_t readfd; /* read descriptor */ fd_t writefd; /* write descriptor */ }; static void * fdobex_create(void) { return calloc(1, sizeof(struct fdobex_data)); } static bool fdobex_init(obex_t *self) { struct fdobex_data *data = self->trans->data; if (data == NULL) return false; data->readfd = (fd_t)-1; data->writefd = (fd_t)-1; return true; } void fdobex_set_fd(obex_t *self, int in, int out) { struct fdobex_data *data = self->trans->data; data->readfd = (fd_t)in; data->writefd = (fd_t)out; } static void fdobex_cleanup (obex_t *self) { struct fdobex_data *data = self->trans->data; free(data); } static bool fdobex_connect_request(obex_t *self) { struct fdobex_data *data = self->trans->data; /* no real connect on the file */ return (data->readfd != (fd_t)-1 && data->writefd != (fd_t)-1); } static bool fdobex_disconnect(obex_t *self) { /* no real disconnect on a file */ return fdobex_init(self); } static ssize_t fdobex_write(obex_t *self, buf_t *msg) { struct obex_transport *trans = self->trans; struct fdobex_data *data = self->trans->data; fd_t fd = data->writefd; size_t size = buf_get_length(msg); int status; fd_set fdset; struct timeval time = {(long)(trans->timeout / 1000), (long)(trans->timeout % 1000)}; if (size == 0) return 0; DEBUG(1, "sending %lu bytes\n", (unsigned long)size); FD_ZERO(&fdset); FD_SET(fd, &fdset); if (trans->timeout >= 0) status = select(fd+1, NULL, &fdset, NULL, &time); else status = select(fd+1, NULL, &fdset, NULL, NULL); if (status == 0) return 0; #if defined(_WIN32) status = _write(fd, buf_get(msg), size); #else status = write(fd, buf_get(msg), size); /* The following are not really transport errors. */ if (status == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) status = 0; #endif return status; } static result_t fdobex_handle_input(obex_t *self) { struct obex_transport *trans = self->trans; struct fdobex_data *data = self->trans->data; fd_t fd = data->readfd; struct timeval time = {(long)(trans->timeout / 1000), (long)(trans->timeout % 1000)}; fd_set fdset; int status; DEBUG(4, "\n"); FD_ZERO(&fdset); FD_SET(fd, &fdset); if (trans->timeout >= 0) status = select(fd+1, NULL, &fdset, NULL, &time); else status = select(fd+1, NULL, &fdset, NULL, NULL); if (status == -1) return RESULT_ERROR; else if (status == 0) return RESULT_TIMEOUT; else return RESULT_SUCCESS; } static ssize_t fdobex_read(obex_t *self, void *buf, int buflen) { struct fdobex_data *data = self->trans->data; fd_t fd = data->readfd; int status; #ifdef _WIN32 status = _read(fd, buf, buflen); #else status = read(fd, buf, buflen); /* The following are not really transport errors */ if (status == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) status = 0; #endif return status; } static int fdobex_get_fd(obex_t *self) { struct fdobex_data *data = self->trans->data; return data->readfd; } static struct obex_transport_ops fdobex_transport_ops = { &fdobex_create, &fdobex_init, &fdobex_cleanup, &fdobex_handle_input, &fdobex_write, &fdobex_read, &fdobex_disconnect, &fdobex_get_fd, NULL, NULL, { NULL, NULL, }, { &fdobex_connect_request, NULL, NULL, NULL, }, }; struct obex_transport * fdobex_transport_create(void) { return obex_transport_create(&fdobex_transport_ops); } openobex-1.7.2-Source/lib/transport/inobex.h000644 001750 001750 00000002056 12701160572 022153 0ustar00hendrikhendrik000000 000000 /** \file inobex.h InOBEX, Inet transport for OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef INOBEX_H #define INOBEX_H struct obex_transport * inobex_transport_create(void); void inobex_prepare_connect(obex_t *self, struct sockaddr *saddr, int addrlen); void inobex_prepare_listen(obex_t *self, struct sockaddr *saddr, int addrlen); #endif openobex-1.7.2-Source/lib/transport/usbobex.c000644 001750 001750 00000034523 12701160572 022335 0ustar00hendrikhendrik000000 000000 /** \file usbobex.c USB OBEX, USB transport for OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2005 Alex Kanavin, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #include /* errno and EADDRNOTAVAIL */ #if defined HAVE_USB && !defined HAVE_USB1 #ifdef _WIN32 #include #include #ifndef ETIMEDOUT #define ETIMEDOUT WSAETIMEDOUT #endif #else #include #include #endif #include #include #include /* perror */ #include #include #include "obex_main.h" #include "usbobex.h" #include "usbutils.h" #include "databuffer.h" static void * usbobex_create (void) { return calloc(1, sizeof(struct usbobex_data)); } static void usbobex_cleanup (obex_t *self) { struct usbobex_data *data = self->trans->data; free(data); } /* * Function usbobex_select_interface (self, interface) * * Prepare for USB OBEX connect * */ static bool usbobex_select_interface(obex_t *self, obex_interface_t *intf) { struct usbobex_data *data = self->trans->data; obex_return_val_if_fail(intf->usb.intf != NULL, false); data->self = *intf->usb.intf; return true; } /* * Helper function to usbobex_find_interfaces */ static void find_eps(struct obex_usb_intf_transport_t *intf, struct usb_interface_descriptor data_intf, int *found_active, int *found_idle) { if (data_intf.bNumEndpoints == 2) { struct usb_endpoint_descriptor *ep0, *ep1; ep0 = data_intf.endpoint; ep1 = data_intf.endpoint + 1; if ((ep0->bEndpointAddress & USB_ENDPOINT_IN) && ((ep0->bmAttributes & USB_ENDPOINT_TYPE_MASK) == USB_ENDPOINT_TYPE_BULK) && !(ep1->bEndpointAddress & USB_ENDPOINT_IN) && ((ep1->bmAttributes & USB_ENDPOINT_TYPE_MASK) == USB_ENDPOINT_TYPE_BULK)) { *found_active = 1; intf->data_active_setting = data_intf.bAlternateSetting; intf->data_interface_active_description = data_intf.iInterface; intf->data_endpoint_read = ep0->bEndpointAddress; intf->data_endpoint_write = ep1->bEndpointAddress; } if (!(ep0->bEndpointAddress & USB_ENDPOINT_IN) && ((ep0->bmAttributes & USB_ENDPOINT_TYPE_MASK) == USB_ENDPOINT_TYPE_BULK) && (ep1->bEndpointAddress & USB_ENDPOINT_IN) && ((ep1->bmAttributes & USB_ENDPOINT_TYPE_MASK) == USB_ENDPOINT_TYPE_BULK)) { *found_active = 1; intf->data_active_setting = data_intf.bAlternateSetting; intf->data_interface_active_description = data_intf.iInterface; intf->data_endpoint_read = ep1->bEndpointAddress; intf->data_endpoint_write = ep0->bEndpointAddress; } } if (data_intf.bNumEndpoints == 0) { *found_idle = 1; intf->data_idle_setting = data_intf.bAlternateSetting; intf->data_interface_idle_description = data_intf.iInterface; } } /* * Helper function to usbobex_find_interfaces */ static int find_obex_data_interface(unsigned char *buffer, int buflen, struct usb_config_descriptor config, struct obex_usb_intf_transport_t *intf) { struct cdc_union_desc *union_header = NULL; int i, a; int found_active = 0; int found_idle = 0; if (!buffer) { DEBUG(2,"Weird descriptor references"); return -EINVAL; } while (buflen > 0) { if (buffer [1] != USB_DT_CS_INTERFACE) { DEBUG(2,"skipping garbage"); goto next_desc; } switch (buffer [2]) { case CDC_UNION_TYPE: /* we've found it */ if (union_header) { DEBUG(2,"More than one union descriptor, skiping ..."); goto next_desc; } union_header = (struct cdc_union_desc *)buffer; break; case CDC_OBEX_TYPE: /* maybe check version */ case CDC_OBEX_SERVICE_ID_TYPE: /* This one is handled later */ case CDC_HEADER_TYPE: break; /* for now we ignore it */ default: DEBUG(2, "Ignoring extra header, type %d, length %d", buffer[2], buffer[0]); break; } next_desc: buflen -= buffer[0]; buffer += buffer[0]; } if (!union_header) { DEBUG(2,"No union descriptor, giving up\n"); return -ENODEV; } /* Found the slave interface, now find active/idle settings and endpoints */ intf->data_interface = union_header->bSlaveInterface0; /* Loop through all of the interfaces */ for (i = 0; i < config.bNumInterfaces; i++) { /* Loop through all of the alternate settings */ for (a = 0; a < config.interface[i].num_altsetting; a++) { /* Check if this interface is OBEX data interface*/ /* and find endpoints */ if (config.interface[i].altsetting[a].bInterfaceNumber == intf->data_interface) find_eps(intf, config.interface[i].altsetting[a], &found_active, &found_idle); } } if (!found_idle) { DEBUG(2,"No idle setting\n"); return -ENODEV; } if (!found_active) { DEBUG(2,"No active setting\n"); return -ENODEV; } return 0; } /* * Helper function to usbobex_find_interfaces */ static int get_intf_string(struct usb_dev_handle *usb_handle, char **string, int id) { if (id) { *string = malloc(USB_MAX_STRING_SIZE); if (*string == NULL) return -errno; *string[0] = '\0'; return usb_get_string_simple(usb_handle, id, *string, USB_MAX_STRING_SIZE); } return 0; } /* * Helper function to usbobex_find_interfaces */ static struct obex_usb_intf_transport_t *check_intf(struct usb_device *dev, int c, int i, int a) { struct usb_interface_descriptor *alt; alt = &dev->config[c].interface[i].altsetting[a]; if ((alt->bInterfaceClass == USB_CDC_CLASS) && (alt->bInterfaceSubClass == USB_CDC_OBEX_SUBCLASS)) { int err; unsigned char *buffer = alt->extra; int buflen = alt->extralen; struct obex_usb_intf_transport_t *next; next = calloc(1, sizeof(*next)); if (next == NULL) return NULL; next->device = dev; next->configuration = dev->config[c].bConfigurationValue; next->configuration_description = dev->config[c].iConfiguration; next->control_interface = alt->bInterfaceNumber; next->control_interface_description = alt->iInterface; next->control_setting = alt->bAlternateSetting; next->extra_descriptors = malloc(buflen); if (next->extra_descriptors) memcpy(next->extra_descriptors, buffer, buflen); next->extra_descriptors_len = buflen; err = find_obex_data_interface(buffer, buflen, dev->config[c], next); if (err) { free(next); return NULL; } return next; } return NULL; } /* * Function usbobex_find_interfaces () * * Find available USBOBEX interfaces on the system */ static int usbobex_find_interfaces(obex_t *self, obex_interface_t **interfaces) { struct usb_bus *busses; struct usb_bus *bus; struct usb_device *dev; int c, i, a; int num = 0; struct obex_usb_intf_transport_t *first = NULL; struct obex_usb_intf_transport_t *current = NULL; obex_interface_t *intf_array = NULL; usb_init(); usb_find_busses(); usb_find_devices(); busses = usb_get_busses(); for (bus = busses; bus; bus = bus->next) { for (dev = bus->devices; dev; dev = dev->next) { /* Loop through all of the configurations */ for (c = 0; c < dev->descriptor.bNumConfigurations; c++) { /* Loop through all of the interfaces */ for (i = 0; i < dev->config[c].bNumInterfaces; i++) { /* Loop through all of the alternate settings */ for (a = 0; a < dev->config[c].interface[i].num_altsetting; a++) { /* Check if this interface is OBEX */ /* and find data interface */ struct obex_usb_intf_transport_t *next; next = check_intf(dev, c, i, a); if (!next) continue; ++num; if (current) current->next = next; current = next; if (first == NULL) first = current; } } } } } intf_array = calloc(num, sizeof(*intf_array)); if (intf_array == NULL) { while (current) { struct obex_usb_intf_transport_t *tmp = current->next; free(current); current = tmp; } return 0; } num = 0; current = first; while (current) { struct usb_dev_handle *usb_handle; intf_array[num].usb.intf = current; usb_handle = usb_open(current->device); get_intf_string(usb_handle, &intf_array[num].usb.manufacturer, current->device->descriptor.iManufacturer); get_intf_string(usb_handle, &intf_array[num].usb.product, current->device->descriptor.iProduct); get_intf_string(usb_handle, &intf_array[num].usb.serial, current->device->descriptor.iSerialNumber); get_intf_string(usb_handle, &intf_array[num].usb.configuration, current->configuration_description); get_intf_string(usb_handle, &intf_array[num].usb.control_interface, current->control_interface_description); get_intf_string(usb_handle, &intf_array[num].usb.data_interface_idle, current->data_interface_idle_description); get_intf_string(usb_handle, &intf_array[num].usb.data_interface_active, current->data_interface_active_description); intf_array[num].usb.idVendor = current->device->descriptor.idVendor; intf_array[num].usb.idProduct = current->device->descriptor.idProduct; intf_array[num].usb.bus_number = atoi(current->device->bus->dirname); intf_array[num].usb.device_address = atoi(current->device->filename); intf_array[num].usb.interface_number = current->control_interface; find_obex_service_descriptor(current->extra_descriptors, current->extra_descriptors_len, &intf_array[num].usb.service); usb_close(usb_handle); current = current->next; ++num; } *interfaces = intf_array; return num; } /* * Function usbobex_free_interface () * * Free a discovered USBOBEX interface on the system */ static void usbobex_free_interface(obex_interface_t *intf) { if (intf) { free(intf->usb.manufacturer); free(intf->usb.product); free(intf->usb.serial); free(intf->usb.configuration); free(intf->usb.control_interface); free(intf->usb.data_interface_idle); free(intf->usb.data_interface_active); free(intf->usb.service); free(intf->usb.intf->extra_descriptors); free(intf->usb.intf); } } /* * Function usbobex_connect_request (self) * * Open the USB connection * */ static bool usbobex_connect_request(obex_t *self) { struct usbobex_data *data = self->trans->data; int ret; DEBUG(4, "\n"); data->self.dev = usb_open(data->self.device); ret = usb_set_configuration(data->self.dev, data->self.configuration); if (ret < 0) { DEBUG(4, "Can't set configuration %d", ret); } ret = usb_claim_interface(data->self.dev, data->self.control_interface); if (ret < 0) { DEBUG(4, "Can't claim control interface %d", ret); goto err1; } ret = usb_set_altinterface(data->self.dev, data->self.control_setting); if (ret < 0) { DEBUG(4, "Can't set control setting %d", ret); goto err2; } ret = usb_claim_interface(data->self.dev, data->self.data_interface); if (ret < 0) { DEBUG(4, "Can't claim data interface %d", ret); goto err2; } ret = usb_set_altinterface(data->self.dev, data->self.data_active_setting); if (ret < 0) { DEBUG(4, "Can't set data active setting %d", ret); goto err3; } return true; err3: usb_release_interface(data->self.dev, data->self.data_interface); err2: usb_release_interface(data->self.dev, data->self.control_interface); err1: usb_close(data->self.dev); return false; } /* * Function usbobex_disconnect (self) * * Shutdown the USB link * */ static bool usbobex_disconnect(obex_t *self) { struct usbobex_data *data = self->trans->data; int ret; DEBUG(4, "\n"); usb_clear_halt(data->self.dev, data->self.data_endpoint_read); usb_clear_halt(data->self.dev, data->self.data_endpoint_write); ret = usb_set_altinterface(data->self.dev, data->self.data_idle_setting); if (ret < 0) { DEBUG(4, "Can't set data idle setting %d", ret); } ret = usb_release_interface(data->self.dev, data->self.data_interface); if (ret < 0) { DEBUG(4, "Can't release data interface %d", ret); } ret = usb_release_interface(data->self.dev, data->self.control_interface); if (ret < 0) { DEBUG(4, "Can't release control interface %d", ret); } ret = usb_close(data->self.dev); if (ret < 0) { DEBUG(4, "Can't close interface %d", ret); return false; } return true; } static int usbobex_get_timeout(int64_t timeout) { if (timeout < 0 || timeout > INT_MAX) { /* libusb-0.x doesn't know about waiting infinitely * so we try with the largest value possible */ return INT_MAX; } return (int)timeout; } static ssize_t usbobex_write(obex_t *self, struct databuffer *msg) { struct obex_transport *trans = self->trans; struct usbobex_data *data = self->trans->data; int status; DEBUG(4, "Endpoint %d\n", data->self.data_endpoint_write); status = usb_bulk_write(data->self.dev, data->self.data_endpoint_write, buf_get(msg), buf_get_length(msg), usbobex_get_timeout(trans->timeout)); if (status < 0) { if (status == -ETIMEDOUT) return 0; errno = -status; return -1; } return status; } static ssize_t usbobex_read(obex_t *self, void *buf, int buflen) { struct obex_transport *trans = self->trans; struct usbobex_data *data = self->trans->data; int status; /* USB can only read 0xFFFF bytes at once (equals mtu_rx) */ DEBUG(4, "Endpoint %d\n", data->self.data_endpoint_read); status = usb_bulk_read(data->self.dev, data->self.data_endpoint_read, buf, self->mtu_rx, usbobex_get_timeout(trans->timeout)); if (status < 0) { if (status == -ETIMEDOUT) return 0; errno = -status; return -1; } return status; } static result_t usbobex_handle_input(obex_t *self) { ssize_t err = obex_transport_read(self, 0); if (err > 0) return RESULT_SUCCESS; else if (err == 0) return RESULT_TIMEOUT; else return RESULT_ERROR; } static struct obex_transport_ops usbobex_transport_ops = { &usbobex_create, NULL, &usbobex_cleanup, usbobex_handle_input, &usbobex_write, &usbobex_read, &usbobex_disconnect, NULL, NULL, NULL, { NULL, NULL, }, { &usbobex_connect_request, &usbobex_find_interfaces, &usbobex_free_interface, &usbobex_select_interface, }, }; struct obex_transport * usbobex_transport_create(void) { return obex_transport_create(&usbobex_transport_ops); } #endif /* HAVE_USB */ openobex-1.7.2-Source/lib/transport/btobex.h000644 001750 001750 00000002230 12701160572 022144 0ustar00hendrikhendrik000000 000000 /** \file btobex.h Bluetooth OBEX, Bluetooth transport for OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2002 Marcel Holtmann, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef BTOBEX_H #define BTOBEX_H #include "bluez_compat.h" #include "obex_transport.h" struct obex_transport * btobex_transport_create(void); void btobex_prepare_connect(obex_t *self, const bdaddr_t *src, const bdaddr_t *dst, uint8_t channel); void btobex_prepare_listen(obex_t *self, const bdaddr_t *src, uint8_t channel); #endif openobex-1.7.2-Source/lib/transport/fdobex.h000644 001750 001750 00000002023 12701160572 022130 0ustar00hendrikhendrik000000 000000 /** \file fdobex.h FD OBEX, file descriptor transport for OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved. Copyright (c) 1999, 2000 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef FDOBEX_H #define FDOBEX_H struct obex_transport * fdobex_transport_create(void); void fdobex_set_fd(obex_t *self, int in, int out); #endif openobex-1.7.2-Source/lib/transport/irobex.c000644 001750 001750 00000031523 12701160572 022153 0ustar00hendrikhendrik000000 000000 /** \file irobex.c IrOBEX, IrDA transport for OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999 Dag Brattli, All Rights Reserved. Copyright (c) 2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #ifdef _WIN32 #include #include "irda_wrap.h" #else /* _WIN32 */ /* Linux case */ #include #include #include /* perror */ #include /* errno and EADDRNOTAVAIL */ #include #include #include #include "irda_wrap.h" #ifndef AF_IRDA #define AF_IRDA 23 #endif /* AF_IRDA */ #endif /* _WIN32 */ #include "obex_main.h" #include "irobex.h" #include "obex_transport_sock.h" struct irobex_data { struct obex_sock *sock; }; static void * irobex_create(void) { return calloc(1, sizeof(struct irobex_data)); } static bool irobex_init (obex_t *self) { struct irobex_data *data = self->trans->data; socklen_t len = sizeof(struct sockaddr_irda); if (data == NULL) return false; data->sock = obex_transport_sock_create(AF_IRDA, 0, len, self->init_flags); if (data->sock == NULL) { free(data); return false; } return true; } static void irobex_cleanup (obex_t *self) { struct irobex_data *data = self->trans->data; if (data->sock) obex_transport_sock_destroy(data->sock); free(data); } /* * Function irobex_no_addr (addr) * * Check if the address is not valid for connection * */ static bool irobex_no_addr(struct sockaddr_irda *addr) { #ifndef _WIN32 return ((addr->sir_addr == 0x0) || (addr->sir_addr == 0xFFFFFFFF)); #else return (((addr->irdaDeviceID[0] == 0x00) && (addr->irdaDeviceID[1] == 0x00) && (addr->irdaDeviceID[2] == 0x00) && (addr->irdaDeviceID[3] == 0x00)) || ((addr->irdaDeviceID[0] == 0xFF) && (addr->irdaDeviceID[1] == 0xFF) && (addr->irdaDeviceID[2] == 0xFF) && (addr->irdaDeviceID[3] == 0xFF))); #endif /* _WIN32 */ } static bool irobex_query_ias(obex_t *self, uint32_t addr, const char* class_name) { int err; struct irda_ias_set ias_query; socklen_t len = sizeof(ias_query); socket_t fd; memset(&ias_query, 0, sizeof(ias_query)); /* Ask if the requested service exist on this device */ #ifndef _WIN32 ias_query.daddr = addr; strncpy(ias_query.irda_class_name, class_name, IAS_MAX_CLASSNAME-1); strncpy(ias_query.irda_attrib_name, "IrDA:TinyTP:LsapSel", IAS_MAX_ATTRIBNAME-1); #else ias_query.irdaDeviceID[0] = (addr >> 24) & 0xFF; ias_query.irdaDeviceID[1] = (addr >> 16) & 0xFF; ias_query.irdaDeviceID[2] = (addr >> 8) & 0xFF; ias_query.irdaDeviceID[3] = addr & 0xFF; strncpy(ias_query.irdaClassName, class_name, IAS_MAX_CLASSNAME-1); strncpy(ias_query.irdaAttribName, "IrDA:TinyTP:LsapSel", IAS_MAX_ATTRIBNAME-1); #endif fd = create_stream_socket(AF_IRDA, 0, OBEX_FL_CLOEXEC); if (fd == INVALID_SOCKET) return false; err = getsockopt(fd, SOL_IRLMP, IRLMP_IAS_QUERY, (void*)&ias_query, &len); close_socket(fd); #if defined(_WIN32) if (err == SOCKET_ERROR) { if (WSAGetLastError() == WSAECONNREFUSED) { DEBUG(1, ", doesn't have %s\n", class_name); } else { DEBUG(1, " \n"); } return false; } #else if (err == -1) { if (errno == EADDRNOTAVAIL) { DEBUG(1, ", doesn't have %s\n", class_name); } else { DEBUG(1, " \n"); } return false; } #endif DEBUG(1, ", has service %s\n", class_name); return true; } static bool irobex_set_local_addr(obex_t *self, struct sockaddr *addr, size_t len) { struct irobex_data *data = self->trans->data; return obex_transport_sock_set_local(data->sock, addr, len); } static bool irobex_set_remote_addr(obex_t *self, struct sockaddr *addr, size_t len) { struct irobex_data *data = self->trans->data; return obex_transport_sock_set_remote(data->sock, addr, len); } static bool irobex_select_interface(obex_t *self, obex_interface_t *intf) { struct sockaddr_irda addr; /* local address */ memset(&addr, 0, sizeof(addr)); addr.sir_family = AF_IRDA; addr.sir_lsap_sel = LSAP_ANY; #ifndef _WIN32 addr.sir_addr = intf->irda.local; #else memset(addr.irdaDeviceID, 0, sizeof(addr.irdaDeviceID)); #endif if (!irobex_set_local_addr(self, (struct sockaddr *)&addr, sizeof(addr))) return false; /* remote address */ memset(&addr, 0, sizeof(addr)); addr.sir_family = AF_IRDA; strncpy(addr.sir_name, intf->irda.service, sizeof(addr.sir_name)-1); #ifndef _WIN32 addr.sir_lsap_sel = LSAP_ANY; addr.sir_addr = intf->irda.remote; #else addr.irdaDeviceID[0] = (intf->irda.remote >> 24) & 0xFF; addr.irdaDeviceID[1] = (intf->irda.remote >> 16) & 0xFF; addr.irdaDeviceID[2] = (intf->irda.remote >> 8) & 0xFF; addr.irdaDeviceID[3] = intf->irda.remote & 0xFF; #endif if (!irobex_set_remote_addr(self, (struct sockaddr *)&addr, sizeof(addr))) return false; return true; } /* * Function irobex_prepare_connect (self, service) * * Prepare for IR-connect * */ void irobex_prepare_connect(obex_t *self, const char *service) { int i = 0; obex_transport_enumerate(self); if (self->interfaces_number == 0) { DEBUG(1, "No devices in range\n"); return; } if (service == NULL) service = "OBEX"; /* Do we want to filter devices based on IAS ? */ if (self->init_flags & OBEX_FL_FILTERIAS) { for (; i < self->interfaces_number; ++i) { obex_irda_intf_t *intf = &self->interfaces[i].irda; if (irobex_query_ias(self, intf->remote, service)) break; } if (i >= self->interfaces_number) return; } self->interfaces[i].irda.service = service; irobex_select_interface(self, &self->interfaces[i]); self->interfaces[i].irda.service = NULL; } /* * Function irobex_prepare_listen (self, service) * * Prepare for IR-listen * */ void irobex_prepare_listen(obex_t *self, const char *service) { struct sockaddr_irda addr; /* Bind local service */ addr.sir_family = AF_IRDA; #ifndef _WIN32 addr.sir_lsap_sel = LSAP_ANY; #endif /* _WIN32 */ if (service == NULL) service = "OBEX"; strncpy(addr.sir_name, service, sizeof(addr.sir_name)); irobex_set_local_addr(self, (struct sockaddr *)&addr, sizeof(addr)); } static bool set_listen_sock_opts(socket_t fd) { #ifndef _WIN32 /* Hint be we advertise */ unsigned char hints[4] = { HINT_EXTENSION, HINT_OBEX, 0, 0, }; /* Tell the stack about it. * This command is not supported by older kernels, * so ignore any errors! */ (void)setsockopt(fd, SOL_IRLMP, IRLMP_HINTS_SET, hints, sizeof(hints)); #else /* _WIN32 */ /* The registry must be changed to set the hint bit. */ #endif /* _WIN32 */ return true; } /* * Function irobex_listen (self) * * Listen for incoming connections. * */ static bool irobex_listen(obex_t *self) { struct irobex_data *data = self->trans->data; DEBUG(4, "\n"); data->sock->set_sock_opts = &set_listen_sock_opts; return obex_transport_sock_listen(data->sock); } /* * Function irobex_accept (self) * * Accept an incoming connection. * * Note : don't close the server socket here, so apps may want to continue * using it... */ static bool irobex_accept(obex_t *self, const obex_t *server) { struct irobex_data *server_data = server->trans->data; struct irobex_data *data = self->trans->data; if (data == NULL) return false; data->sock = obex_transport_sock_accept(server_data->sock); if (data->sock == NULL) return false; return true; } /* * Function irobex_find_interfaces() * * Try to discover some remote device(s) that we can connect to * * Note : we optionally can do a first filtering on the Obex hint bit, * and then we can verify that the device does have the requested service... * Note : in this function, the memory allocation for the discovery log * is done "the right way", so that it's safe and we don't leak memory... * Jean II */ static int irobex_find_interfaces(obex_t *self, obex_interface_t **interfaces) { struct irda_device_list *list; struct irda_device_info *dev; unsigned char buf[sizeof(*list) + ((MAX_DEVICES-1) * sizeof(*dev))]; socklen_t len = sizeof(buf); int count = 0; socket_t fd = create_stream_socket(AF_IRDA, 0, OBEX_FL_CLOEXEC); int i; uint32_t k = 0; if (fd == INVALID_SOCKET) goto out; #ifndef _WIN32 /* Hint bit filtering, if possible */ if (self->init_flags & OBEX_FL_FILTERHINT) { unsigned char hints[4] = { HINT_EXTENSION, HINT_OBEX, 0, 0, }; int err; /* Set the filter used for performing discovery */ err = setsockopt(fd, SOL_IRLMP, IRLMP_HINT_MASK_SET, hints, sizeof(hints)); if (err < 0) { perror("setsockopt"); goto out; } } #endif /* Perform a discovery and get device list */ if (getsockopt(fd, SOL_IRLMP, IRLMP_ENUMDEVICES, (char *) buf, &len)) goto done; list = (struct irda_device_list *) buf; #ifndef _WIN32 count = (int) list->len; dev = list->dev; #else count = (int) list->numDevice; dev = list->Device; #endif if (count <= 0) goto done; *interfaces = calloc(count, sizeof(**interfaces)); DEBUG(1, "Discovered %u devices:\n", count); for (i = 0; i < count; ++i) { obex_irda_intf_t *intf = &((*interfaces)+k)->irda; #ifndef _WIN32 intf->local = dev[i].saddr; intf->remote = dev[i].daddr; intf->charset = dev[i].charset; /* allocate enough space to make sure the string is * zero-terminated */ intf->info = calloc(sizeof(dev[i].info)+2, 1); if (intf->info) memcpy(intf->info, dev[i].info, sizeof(dev[i].info)); intf->hints[0] = dev[i].hints[0]; intf->hints[1] = dev[i].hints[1]; #else if ((self->init_flags & OBEX_FL_FILTERHINT) && ((dev[i].irdaDeviceHints1 & LM_HB_Extension) == 0)) continue; if ((dev[i].irdaDeviceHints2 & 0x20) == 0) continue; intf->remote = dev[i].irdaDeviceID[3] | dev[i].irdaDeviceID[2] << 8 | dev[i].irdaDeviceID[1] << 16 | dev[i].irdaDeviceID[0] << 24; intf->charset = dev[i].irdaCharSet; /* allocate enough space to make sure the * string is zero-terminated */ intf->info = calloc(sizeof(dev[i].irdaDeviceName)+2, 1); if (intf->info) memcpy(intf->info, dev[i].irdaDeviceName, sizeof(dev[i].irdaDeviceName)); intf->hints[0] = dev[i].irdaDeviceHints1; intf->hints[1] = dev[i].irdaDeviceHints2; #endif ++k; DEBUG(1, " [%d] daddr: 0x%08x\n", i+1, intf->remote); } count = k; done: if (count == 0) DEBUG(1, "didn't find any OBEX devices!\n"); out: close_socket(fd); return count; } static void irobex_free_interface(obex_interface_t *intf) { if (intf) { if (intf->irda.info) { free(intf->irda.info); intf->irda.info = NULL; } } } /* * Function irobex_irda_connect_request (self) * * Open the TTP connection * */ static bool irobex_connect_request(obex_t *self) { struct irobex_data *data = self->trans->data; DEBUG(4, "\n"); /* Check if the application did supply a valid address. */ if (irobex_no_addr((struct sockaddr_irda *)&data->sock->remote)) return false; return obex_transport_sock_connect(data->sock); } /* * Function irobex_disconnect (self) * * Shutdown the IrTTP link * */ static bool irobex_disconnect(obex_t *self) { struct irobex_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_disconnect(data->sock); } static result_t irobex_handle_input(obex_t *self) { struct irobex_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_wait(data->sock, self->trans->timeout); } static ssize_t irobex_write(obex_t *self, struct databuffer *msg) { struct obex_transport *trans = self->trans; struct irobex_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_send(data->sock, msg, trans->timeout); } static ssize_t irobex_read(obex_t *self, void *buf, int buflen) { struct irobex_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_recv(data->sock, buf, buflen); } static int irobex_get_fd(obex_t *self) { struct irobex_data *data = self->trans->data; return (int)obex_transport_sock_get_fd(data->sock); } static struct obex_transport_ops irobex_transport_ops = { &irobex_create, &irobex_init, &irobex_cleanup, &irobex_handle_input, &irobex_write, &irobex_read, &irobex_disconnect, &irobex_get_fd, &irobex_set_local_addr, &irobex_set_remote_addr, { &irobex_listen, &irobex_accept, }, { &irobex_connect_request, &irobex_find_interfaces, &irobex_free_interface, &irobex_select_interface, }, }; struct obex_transport * irobex_transport_create(void) { return obex_transport_create(&irobex_transport_ops); } openobex-1.7.2-Source/lib/transport/usbobex.h000644 001750 001750 00000007206 12701160572 022340 0ustar00hendrikhendrik000000 000000 /** \file usbobex.h USB OBEX, USB transport for OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2005 Alex Kanavin, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef USBOBEX_H #define USBOBEX_H #include #ifdef HAVE_USB1 #include #else #include #endif /* Information about a USB OBEX interface present on the system */ struct obex_usb_intf_transport_t { struct obex_usb_intf_transport_t *next; /* Next interface in the list */ int configuration; /* Device configuration */ int configuration_description; /* Configuration string descriptor number */ int control_interface; /* OBEX master interface */ int control_setting; /* OBEX master interface setting */ int control_interface_description; /* OBEX master interface string descriptor number * If non-zero, use usb_get_string_simple() from * libusb to retrieve human-readable description */ char *extra_descriptors; /* Extra master interface descriptors */ int extra_descriptors_len; /* Length of extra descriptors */ int data_interface; /* OBEX data/slave interface */ int data_idle_setting; /* OBEX data/slave idle setting */ int data_interface_idle_description; /* OBEX data/slave interface string descriptor number * in idle setting */ int data_active_setting; /* OBEX data/slave active setting */ int data_interface_active_description; /* OBEX data/slave interface string descriptor number * in active setting */ int data_endpoint_read; /* OBEX data/slave interface read endpoint */ int data_endpoint_write; /* OBEX data/slave interface write endpoint */ #ifdef HAVE_USB1 struct libusb_device *device; /* libusb 1.x device */ struct libusb_device_handle *dev; /* libusb 1.x device handle */ #else struct usb_device *device; /* libusb 0.x device */ usb_dev_handle *dev; /* libusb 0.x device handle */ #endif }; /* "Union Functional Descriptor" from CDC spec 5.2.3.X * used to find data/slave OBEX interface */ #pragma pack(1) struct cdc_union_desc { uint8_t bLength; uint8_t bDescriptorType; uint8_t bDescriptorSubType; uint8_t bMasterInterface0; uint8_t bSlaveInterface0; }; #pragma pack() /* CDC class and subclass types */ #define USB_CDC_CLASS 0x02 #define USB_CDC_OBEX_SUBCLASS 0x0b /* class and subclass specific descriptor types */ #define CDC_HEADER_TYPE 0x00 #define CDC_CALL_MANAGEMENT_TYPE 0x01 #define CDC_AC_MANAGEMENT_TYPE 0x02 #define CDC_UNION_TYPE 0x06 #define CDC_COUNTRY_TYPE 0x07 #define CDC_OBEX_TYPE 0x15 #define CDC_OBEX_SERVICE_ID_TYPE 0x19 /* Interface descriptor */ #define USB_DT_CS_INTERFACE 0x24 #define CDC_DATA_INTERFACE_TYPE 0x0a #define WMC_DEFAULT_OBEX_SERVER_UUID \ { 0x02, 0xae, 0xb3, 0x20, \ 0xf6, 0x49, 0x11, 0xda, \ 0x97, 0x4d, 0x08, 0x00, \ 0x20, 0x0c, 0x9a, 0x66 } #define USB_MAX_STRING_SIZE 256 struct obex_transport * usbobex_transport_create(void); struct usbobex_data { #ifdef HAVE_USB1 struct libusb_context *ctx; int fd; #endif struct obex_usb_intf_transport_t self; }; #endif openobex-1.7.2-Source/lib/transport/bluez_compat.h000644 001750 001750 00000004564 12604167677 023400 0ustar00hendrikhendrik000000 000000 /** \file bluez_compat.h Provides the Bluez API on other platforms. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2007-2011 Hendrik Sattler, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #ifndef BLUEZ_COMPAT_H #define BLUEZ_COMPAT_H #if defined(HAVE_BLUETOOTH_WINDOWS) /* you need the headers files from the Platform SDK */ #include #include #define bdaddr_t BTH_ADDR #define sockaddr_rc _SOCKADDR_BTH #define rc_family addressFamily #define rc_bdaddr btAddr #define rc_channel port #define PF_BLUETOOTH PF_BTH #define AF_BLUETOOTH AF_BTH #define BTPROTO_RFCOMM BTHPROTO_RFCOMM /* TODO: should be const */ extern bdaddr_t bluez_compat_bdaddr_any; #define BDADDR_ANY &bluez_compat_bdaddr_any #define bacpy(dst,src) memcpy((dst),(src),sizeof(bdaddr_t)) #define bacmp(a,b) memcmp((a),(b),sizeof(bdaddr_t)) #elif defined(HAVE_BLUETOOTH_LINUX) #include #include #elif defined(HAVE_BLUETOOTH_FREEBSD) #include #define sockaddr_rc sockaddr_rfcomm #define rc_family rfcomm_family #define rc_bdaddr rfcomm_bdaddr #define rc_channel rfcomm_channel #define BDADDR_ANY NG_HCI_BDADDR_ANY #define BTPROTO_RFCOMM BLUETOOTH_PROTO_RFCOMM #elif defined(HAVE_BLUETOOTH_NETBSD) #include #include #define sockaddr_rc sockaddr_bt #define rc_family bt_family #define rc_bdaddr bt_bdaddr #define rc_channel bt_channel #define bacpy(dst,src) memcpy((dst),(src),sizeof(bdaddr_t)) #define bacmp(a,b) memcmp((a),(b),sizeof(bdaddr_t)) #define str2ba(str, ba) (bt_aton((str), (ba)) == 1 ? 0 : -1) #else #define bdaddr_t unsigned long #endif /* HAVE_BLUETOOTH_* */ #endif /* BLUEZ_COMPAT_H */ openobex-1.7.2-Source/lib/transport/customtrans.h000644 001750 001750 00000002173 12604167677 023270 0ustar00hendrikhendrik000000 000000 /** \file customtrans.h Custom OBEX, custom transport for OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved. Copyright (c) 1999, 2000 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef CUSTOMTRANS_H #define CUSTOMTRANS_H struct obex_transport * custom_transport_create(void); int custom_register(obex_t *self, const obex_ctrans_t *in); void custom_set_data(obex_t *self, void *data); void* custom_get_data(obex_t *self); #endif openobex-1.7.2-Source/lib/transport/irobex.h000644 001750 001750 00000002112 12701160572 022150 0ustar00hendrikhendrik000000 000000 /** \file irobex.h IrOBEX, IrDA transport for OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef IROBEX_H #define IROBEX_H #define MAX_DEVICES 10 /* Max devices to discover */ struct obex_transport * irobex_transport_create(void); void irobex_prepare_connect(obex_t *self, const char *service); void irobex_prepare_listen(obex_t *self, const char *service); #endif openobex-1.7.2-Source/lib/transport/usbutils.c000644 001750 001750 00000004447 12701160572 022542 0ustar00hendrikhendrik000000 000000 /** \file usbutils.c USB OBEX, USB transport for OBEX, support functions. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2009 Alex Kanavin, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #ifdef HAVE_USB #include #include #include /* perror */ #include #include "obex_main.h" #include "usbobex.h" #include "usbutils.h" /* * Helper function to usbobex_find_interfaces */ void find_obex_service_descriptor(const char *buffer, int buflen, obex_usb_intf_service_t **service) { if (!buffer) { DEBUG(2, "Weird descriptor references"); return ; } while (buflen > 0) { if (buffer[1] != USB_DT_CS_INTERFACE) { DEBUG(2, "skipping garbage"); goto next_desc; } switch (buffer[2]) { case CDC_OBEX_SERVICE_ID_TYPE: /* we've found it */ if (buflen < 22) {/* Check descriptor size */ DEBUG(2, "Invalid service id descriptor"); } else if (*service == NULL) { *service = malloc(sizeof(**service)); if (*service != NULL) { const uint8_t default_uuid[16] = WMC_DEFAULT_OBEX_SERVER_UUID; (*service)->role = buffer[3]; memcpy((*service)->uuid, buffer+4, 16); (*service)->version = (buffer[20]<<8)|(buffer[21]); if (memcmp((*service)->uuid, default_uuid, 16) == 0 ) (*service)->is_default_uuid = 1; else (*service)->is_default_uuid = 0; } } break; case CDC_OBEX_TYPE: /* maybe check version */ case CDC_UNION_TYPE: case CDC_HEADER_TYPE: break; default: DEBUG(2, "Ignoring extra header, type %d, length %d", buffer[2], buffer[0]); break; } next_desc: buflen -= buffer[0]; buffer += buffer[0]; } } #endif openobex-1.7.2-Source/lib/transport/btobex.c000644 001750 001750 00000013716 12701160572 022152 0ustar00hendrikhendrik000000 000000 /** \file btobex.c Bluetooth OBEX, Bluetooth transport for OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2002 Marcel Holtmann, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #ifdef HAVE_BLUETOOTH #ifdef _WIN32 #include #else /* _WIN32 */ /* Linux/FreeBSD/NetBSD case */ #include #include #endif /* _WIN32 */ #include "obex_main.h" #include "btobex.h" #ifdef _WIN32 bdaddr_t bluez_compat_bdaddr_any = { BTH_ADDR_NULL }; #endif #include "obex_transport_sock.h" #include "cloexec.h" #include "nonblock.h" #include struct btobex_rfcomm_data { struct obex_sock *sock; }; static void * btobex_create(void) { return calloc(1, sizeof(struct btobex_rfcomm_data)); } static bool btobex_init(obex_t *self) { struct btobex_rfcomm_data *data = self->trans->data; socklen_t len = sizeof(struct sockaddr_rc); if (data == NULL) return false; data->sock = obex_transport_sock_create(AF_BLUETOOTH, BTPROTO_RFCOMM, len, self->init_flags); if (data->sock == NULL) { free(data); return false; } return true; } static void btobex_cleanup (obex_t *self) { struct btobex_rfcomm_data *data = self->trans->data; if (data->sock) obex_transport_sock_destroy(data->sock); free(data); } static bool btobex_set_local_addr(obex_t *self, struct sockaddr *addr, size_t len) { struct btobex_rfcomm_data *data = self->trans->data; return obex_transport_sock_set_local(data->sock, addr, len); } static bool btobex_set_remote_addr(obex_t *self, struct sockaddr *addr, size_t len) { struct btobex_rfcomm_data *data = self->trans->data; return obex_transport_sock_set_remote(data->sock, addr, len); } static void btobex_addr2sock(const bdaddr_t *addr, uint8_t channel, struct sockaddr_rc *sock) { memset(sock, 0, sizeof(*sock)); sock->rc_family = AF_BLUETOOTH; bacpy(&sock->rc_bdaddr, addr); sock->rc_channel = (uint8_t)(channel & 0xFF); } /* * Function btobex_prepare_connect (self, service) * * Prepare for Bluetooth RFCOMM connect * */ void btobex_prepare_connect(obex_t *self, const bdaddr_t *src, const bdaddr_t *dst, uint8_t channel) { struct btobex_rfcomm_data *data = self->trans->data; struct sockaddr_rc sock; btobex_prepare_listen(self, src, 0); btobex_addr2sock(dst, channel, &sock); obex_transport_sock_set_remote(data->sock, (struct sockaddr *) &sock, sizeof(sock)); } /* * Function btobex_prepare_listen (self, service) * * Prepare for Bluetooth RFCOMM listen * */ void btobex_prepare_listen(obex_t *self, const bdaddr_t *src, uint8_t channel) { struct btobex_rfcomm_data *data = self->trans->data; struct sockaddr_rc sock; btobex_addr2sock(src, channel, &sock); obex_transport_sock_set_local(data->sock, (struct sockaddr *) &sock, sizeof(sock)); } /* * Function btobex_listen (self) * * Listen for incoming connections. * */ static bool btobex_listen(obex_t *self) { struct btobex_rfcomm_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_listen(data->sock); } /* * Function btobex_accept (self) * * Accept an incoming connection. * * Note : don't close the server socket here, so apps may want to continue * using it... */ static bool btobex_accept(obex_t *self, const obex_t *server) { struct btobex_rfcomm_data *server_data = server->trans->data; struct btobex_rfcomm_data *data = self->trans->data; if (data == NULL) return false; data->sock = obex_transport_sock_accept(server_data->sock); if (data->sock == NULL) return false; return true; } /* * Function btobex_connect_request (self) * * Open the RFCOMM connection * */ static bool btobex_connect_request(obex_t *self) { struct btobex_rfcomm_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_connect(data->sock); } /* * Function btobex_disconnect (self) * * Shutdown the RFCOMM link * */ static bool btobex_disconnect(obex_t *self) { struct btobex_rfcomm_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_disconnect(data->sock); } static result_t btobex_handle_input(obex_t *self) { struct btobex_rfcomm_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_wait(data->sock, self->trans->timeout); } static ssize_t btobex_write(obex_t *self, struct databuffer *msg) { struct obex_transport *trans = self->trans; struct btobex_rfcomm_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_send(data->sock, msg, trans->timeout); } static ssize_t btobex_read(obex_t *self, void *buf, int buflen) { struct btobex_rfcomm_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_recv(data->sock, buf, buflen); } static int btobex_get_fd(obex_t *self) { struct btobex_rfcomm_data *data = self->trans->data; return (int)obex_transport_sock_get_fd(data->sock); } static struct obex_transport_ops btobex_transport_ops = { &btobex_create, &btobex_init, &btobex_cleanup, &btobex_handle_input, &btobex_write, &btobex_read, &btobex_disconnect, &btobex_get_fd, &btobex_set_local_addr, &btobex_set_remote_addr, { &btobex_listen, &btobex_accept, }, { &btobex_connect_request, NULL, NULL, NULL, }, }; struct obex_transport * btobex_transport_create(void) { return obex_transport_create(&btobex_transport_ops); } #endif /* HAVE_BLUETOOTH */ openobex-1.7.2-Source/lib/transport/customtrans.c000644 001750 001750 00000010302 12701160572 023235 0ustar00hendrikhendrik000000 000000 /** \file customtrans.c Custom OBEX, custom transport for OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved. Copyright (c) 1999, 2000 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #include "obex_main.h" #include "databuffer.h" #include "customtrans.h" #include #include static void * custom_create (void) { return calloc(1, sizeof(obex_ctrans_t)); } static void custom_cleanup (obex_t *self) { struct obex_transport_ops *ops = self->trans->ops; obex_ctrans_t *data = self->trans->data; free(ops); free(data); } void custom_set_data(obex_t *self, void *data) { struct obex_transport *trans = self->trans; obex_ctrans_t *ctrans = trans->data; ctrans->customdata = data; } void* custom_get_data(obex_t *self) { struct obex_transport *trans = self->trans; obex_ctrans_t *ctrans = trans->data; return ctrans->customdata; } static bool custom_connect_request(obex_t *self) { struct obex_transport *trans = self->trans; obex_ctrans_t *ctrans = trans->data; return (ctrans->connect(self, ctrans->customdata) >= 0); } static bool custom_disconnect(obex_t *self) { struct obex_transport *trans = self->trans; obex_ctrans_t *ctrans = trans->data; return (ctrans->disconnect(self, ctrans->customdata) >= 0); } static bool custom_listen(obex_t *self) { struct obex_transport *trans = self->trans; obex_ctrans_t *ctrans = trans->data; return (ctrans->listen(self, ctrans->customdata) >= 0); } static bool custom_accept(obex_t *self, const obex_t *from) { const obex_ctrans_t *old = from->trans->data; obex_ctrans_t *ctrans = self->trans->data; *ctrans = *old; return true; } static result_t custom_handle_input(obex_t *self) { struct obex_transport *trans = self->trans; obex_ctrans_t *ctrans = trans->data; int res = ctrans->handleinput(self, ctrans->customdata, (int)((trans->timeout+999)/1000)); if (res < 0) return RESULT_ERROR; else if (res == 0) return RESULT_TIMEOUT; else return RESULT_SUCCESS; } static ssize_t custom_write(obex_t *self, buf_t *msg) { struct obex_transport *trans = self->trans; obex_ctrans_t *ctrans = trans->data; return ctrans->write(self, ctrans->customdata, buf_get(msg), buf_get_length(msg)); } static ssize_t custom_read(obex_t *self, void *buf, int size) { struct obex_transport *trans = self->trans; obex_ctrans_t *ctrans = trans->data; if (ctrans->read) { return ctrans->read(self, ctrans->customdata, buf, size); } else { /* This is not an error as it may happen that * OBEX_CustomDataFeed() was not given enough data * for one OBEX packet. This would result in calling * this function. */ return 0; } } int custom_register(obex_t *self, const obex_ctrans_t *in) { struct obex_transport *trans = self->trans; obex_ctrans_t *ctrans = trans->data; struct obex_transport_ops *ops = self->trans->ops; if (!in->handleinput || !in->write) return -1; *ctrans = *in; ops->handle_input = &custom_handle_input; ops->write = &custom_write; ops->read = &custom_read; ops->server.accept = &custom_accept; if (ctrans->listen) ops->server.listen = &custom_listen; if (ctrans->connect) ops->client.connect = &custom_connect_request; if (ctrans->disconnect) ops->disconnect = &custom_disconnect; return 0; } struct obex_transport * custom_transport_create(void) { struct obex_transport_ops *ops = calloc(1, sizeof(*ops)); struct obex_transport *trans; if (!ops) return NULL; ops->create = &custom_create; ops->cleanup = &custom_cleanup; trans = obex_transport_create(ops); if (!trans) free(ops); return trans; } openobex-1.7.2-Source/lib/transport/inobex.c000644 001750 001750 00000021042 12701160572 022142 0ustar00hendrikhendrik000000 000000 /** \file inobex.c InOBEX, Inet transport for OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #ifdef _WIN32 #include #include #else #include #include #include #include #include #endif /*_WIN32*/ #include "obex_main.h" #include "inobex.h" #include #include #include #include #include "obex_transport_sock.h" #include "cloexec.h" #include "nonblock.h" struct inobex_data { struct obex_sock *sock; }; #if 0 static void print_sock_addr(const char *prefix, const struct sockaddr *addr) { #ifndef _WIN32 char atxt[INET6_ADDRSTRLEN]; const struct sockaddr_in6 *addr6 = (const struct sockaddr_in6 *)addr; if (!inet_ntop(AF_INET6, &addr6->sin6_addr, atxt, sizeof(atxt))) return; DEBUG(2, "%s [%s]:%u\n", prefix, atxt, ntohs(addr6->sin6_port)); #endif } #endif static bool set_sock_opts(socket_t fd) { #ifdef IPV6_V6ONLY /* Needed for some system that set this IPv6 socket option to * 1 by default (Windows Vista, maybe some BSDs). * Do not check the return code as it may not matter. * You will certainly notice later if it failed. */ int v6only = 0; (void)setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (void *) &v6only, sizeof(v6only)); #endif return true; } static void map_ip4to6(struct sockaddr_in *in, struct sockaddr_in6 *out) { out->sin6_family = AF_INET6; out->sin6_port = in->sin_port; out->sin6_flowinfo = 0; out->sin6_scope_id = 0; /* default, matches IN6ADDR_ANY */ memset(out->sin6_addr.s6_addr, 0, sizeof(out->sin6_addr.s6_addr)); switch (in->sin_addr.s_addr) { case INADDR_ANY: /* does not work, so use IN6ADDR_ANY * which includes INADDR_ANY */ break; default: /* map the IPv4 address to [::FFFF:] * see RFC2373 and RFC2553 for details */ out->sin6_addr.s6_addr[10] = 0xFF; out->sin6_addr.s6_addr[11] = 0xFF; out->sin6_addr.s6_addr[12] = (unsigned char)((in->sin_addr.s_addr >> 0) & 0xFF); out->sin6_addr.s6_addr[13] = (unsigned char)((in->sin_addr.s_addr >> 8) & 0xFF); out->sin6_addr.s6_addr[14] = (unsigned char)((in->sin_addr.s_addr >> 16) & 0xFF); out->sin6_addr.s6_addr[15] = (unsigned char)((in->sin_addr.s_addr >> 24) & 0xFF); break; } } static void * inobex_create(void) { return calloc(1, sizeof(struct inobex_data)); } static bool inobex_init (obex_t *self) { struct inobex_data *data = self->trans->data; socklen_t len = sizeof(struct sockaddr_in6); if (data == NULL) return false; data->sock = obex_transport_sock_create(AF_INET6, 0, len, self->init_flags); if (data->sock == NULL) { free(data); return false; } data->sock->set_sock_opts = &set_sock_opts; return true; } static void inobex_cleanup (obex_t *self) { struct inobex_data *data = self->trans->data; if (data->sock) obex_transport_sock_destroy(data->sock); free(data); } static bool inobex_set_remote_addr(obex_t *self, struct sockaddr *addr, size_t len) { size_t expected_len; if (addr->sa_family == AF_INET) expected_len = sizeof(struct sockaddr_in); else if (addr->sa_family == AF_INET6) expected_len = sizeof(struct sockaddr_in6); else return false; if (expected_len != len) return false; inobex_prepare_connect(self, addr, len); return true; } static bool inobex_set_local_addr(obex_t *self, struct sockaddr *addr, size_t len) { size_t expected_len; if (addr->sa_family == AF_INET) expected_len = sizeof(struct sockaddr_in); else if (addr->sa_family == AF_INET6) expected_len = sizeof(struct sockaddr_in6); else return false; if (expected_len != len) return false; inobex_prepare_listen(self, addr, len); return true; } #define OBEX_DEFAULT_PORT 650 static void check_default_port(struct sockaddr_in6 *saddr) { if (saddr->sin6_port == 0) saddr->sin6_port = htons(OBEX_DEFAULT_PORT); } /* * Function inobex_prepare_connect (self, service) * * Prepare for INET-connect * */ void inobex_prepare_connect(obex_t *self, struct sockaddr *saddr, int addrlen) { struct inobex_data *data = self->trans->data; struct sockaddr_in6 addr; addr.sin6_family = AF_INET6; addr.sin6_port = 0; addr.sin6_flowinfo = 0; memcpy(&addr.sin6_addr, &in6addr_loopback, sizeof(addr.sin6_addr)); addr.sin6_scope_id = 0; if (saddr == NULL) saddr = (struct sockaddr*)(&addr); else switch (saddr->sa_family){ case AF_INET6: break; case AF_INET: map_ip4to6((struct sockaddr_in*)saddr,&addr); /* no break */ default: saddr = (struct sockaddr*)(&addr); break; } check_default_port((struct sockaddr_in6 *)saddr); obex_transport_sock_set_remote(data->sock, saddr, sizeof(addr)); } /* * Function inobex_prepare_listen (self) * * Prepare for INET-listen * */ void inobex_prepare_listen(obex_t *self, struct sockaddr *saddr, int addrlen) { struct inobex_data *data = self->trans->data; struct sockaddr_in6 addr; addr.sin6_family = AF_INET6; addr.sin6_port = 0; addr.sin6_flowinfo = 0; memcpy(&addr.sin6_addr, &in6addr_any, sizeof(addr.sin6_addr)); addr.sin6_scope_id = 0; /* Bind local service */ if (saddr == NULL) saddr = (struct sockaddr *) &addr; else switch (saddr->sa_family) { case AF_INET6: break; case AF_INET: map_ip4to6((struct sockaddr_in *) saddr, &addr); /* no break */ default: saddr = (struct sockaddr *) &addr; break; } check_default_port((struct sockaddr_in6 *)saddr); obex_transport_sock_set_local(data->sock, saddr, sizeof(addr)); } /* * Function inobex_listen (self) * * Wait for incomming connections * */ static bool inobex_listen(obex_t *self) { struct inobex_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_listen(data->sock); } /* * Function inobex_accept (self) * * Accept incoming connection. * * Note : don't close the server socket here, so apps may want to continue * using it... */ static bool inobex_accept(obex_t *self, const obex_t *server) { struct inobex_data *server_data = server->trans->data; struct inobex_data *data = self->trans->data; if (data == NULL) return false; data->sock = obex_transport_sock_accept(server_data->sock); if (data->sock == NULL) return false; return true; } /* * Function inobex_connect_request (self) */ static bool inobex_connect_request(obex_t *self) { struct inobex_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_connect(data->sock); } /* * Function inobex_transport_disconnect (self) * * Shutdown the TCP/IP link * */ static bool inobex_disconnect(obex_t *self) { struct inobex_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_disconnect(data->sock); } static result_t inobex_handle_input(obex_t *self) { struct inobex_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_wait(data->sock, self->trans->timeout); } static ssize_t inobex_write(obex_t *self, struct databuffer *msg) { struct obex_transport *trans = self->trans; struct inobex_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_send(data->sock, msg, trans->timeout); } static ssize_t inobex_read(obex_t *self, void *buf, int buflen) { struct inobex_data *data = self->trans->data; DEBUG(4, "\n"); return obex_transport_sock_recv(data->sock, buf, buflen); } static int inobex_get_fd(obex_t *self) { struct inobex_data *data = self->trans->data; return (int)obex_transport_sock_get_fd(data->sock); } static struct obex_transport_ops inobex_transport_ops = { &inobex_create, &inobex_init, &inobex_cleanup, &inobex_handle_input, &inobex_write, &inobex_read, &inobex_disconnect, &inobex_get_fd, &inobex_set_local_addr, &inobex_set_remote_addr, { &inobex_listen, &inobex_accept, }, { &inobex_connect_request, NULL, NULL, NULL, }, }; struct obex_transport * inobex_transport_create(void) { return obex_transport_create(&inobex_transport_ops); } openobex-1.7.2-Source/lib/transport/usb1obex.c000644 001750 001750 00000037032 12701160572 022414 0ustar00hendrikhendrik000000 000000 /** \file usbobex.c USB OBEX, USB transport for OBEX, libusb 1.x support. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2009 Alex Kanavin, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #ifdef HAVE_USB1 #include #include #include /* perror */ #include /* errno and EADDRNOTAVAIL */ #include #include /* POLLIN */ #include #include #include "obex_main.h" #include "usbobex.h" #include "usbutils.h" #include "databuffer.h" static void usbobex_set_fd(int fd, short events, void *user_data) { struct usbobex_data *data = user_data; data->fd = fd; } static void usbobex_clear_fd(int fd, void *user_data) { struct usbobex_data *data = user_data; if (fd == data->fd) data->fd = -1; } static int usbobex_get_fd(obex_t *self) { struct usbobex_data *data = self->trans->data; return data->fd; } static void * usbobex_create (void) { return calloc(1, sizeof(struct usbobex_data)); } static bool usbobex_init (obex_t *self) { struct usbobex_data *data = self->trans->data; if (data == NULL) return false; if (data->ctx == NULL) { int err = libusb_init(&data->ctx); if (err) return false; } data->fd = -1; libusb_set_pollfd_notifiers(data->ctx, &usbobex_set_fd, &usbobex_clear_fd, data); return true; } static void usbobex_cleanup (obex_t *self) { struct usbobex_data *data = self->trans->data; if (data->ctx) { libusb_exit(data->ctx); data->ctx = NULL; } free(data); } /* * Function usbobex_select_interface (self, interface) * * Prepare for USB OBEX connect * */ static bool usbobex_select_interface(obex_t *self, obex_interface_t *intf) { struct usbobex_data *data = self->trans->data; obex_return_val_if_fail(intf->usb.intf != NULL, false); data->self = *intf->usb.intf; return true; } /* * Helper function to usbobex_find_interfaces */ static void find_eps(struct obex_usb_intf_transport_t *intf, struct libusb_interface_descriptor data_intf, int *found_active, int *found_idle) { struct libusb_endpoint_descriptor ep0, ep1; if (data_intf.bNumEndpoints == 2) { ep0 = data_intf.endpoint[0]; ep1 = data_intf.endpoint[1]; if ((ep0.bEndpointAddress & LIBUSB_ENDPOINT_IN) && ((ep0.bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) == LIBUSB_TRANSFER_TYPE_BULK) && !(ep1.bEndpointAddress & LIBUSB_ENDPOINT_IN) && ((ep1.bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) == LIBUSB_TRANSFER_TYPE_BULK)) { *found_active = 1; intf->data_active_setting = data_intf.bAlternateSetting; intf->data_interface_active_description = data_intf.iInterface; intf->data_endpoint_read = ep0.bEndpointAddress; intf->data_endpoint_write = ep1.bEndpointAddress; } if (!(ep0.bEndpointAddress & LIBUSB_ENDPOINT_IN) && ((ep0.bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) == LIBUSB_TRANSFER_TYPE_BULK) && (ep1.bEndpointAddress & LIBUSB_ENDPOINT_IN) && ((ep1.bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) == LIBUSB_TRANSFER_TYPE_BULK)) { *found_active = 1; intf->data_active_setting = data_intf.bAlternateSetting; intf->data_interface_active_description = data_intf.iInterface; intf->data_endpoint_read = ep1.bEndpointAddress; intf->data_endpoint_write = ep0.bEndpointAddress; } } if (data_intf.bNumEndpoints == 0) { *found_idle = 1; intf->data_idle_setting = data_intf.bAlternateSetting; intf->data_interface_idle_description = data_intf.iInterface; } } /* * Helper function to usbobex_find_interfaces */ static int find_obex_data_interface(const unsigned char *buffer, int buflen, struct libusb_config_descriptor *config, struct obex_usb_intf_transport_t *intf) { struct cdc_union_desc *union_header = NULL; int i, a; int found_active = 0; int found_idle = 0; if (!buffer) { DEBUG(2,"Weird descriptor references"); return -EINVAL; } while (buflen > 0) { if (buffer [1] != USB_DT_CS_INTERFACE) { DEBUG(2,"skipping garbage"); goto next_desc; } switch (buffer [2]) { case CDC_UNION_TYPE: /* we've found it */ if (union_header) { DEBUG(2,"More than one union descriptor, skiping ..."); goto next_desc; } union_header = (struct cdc_union_desc *)buffer; break; case CDC_OBEX_TYPE: /* maybe check version */ case CDC_OBEX_SERVICE_ID_TYPE: /* This one is handled later */ case CDC_HEADER_TYPE: break; /* for now we ignore it */ default: DEBUG(2, "Ignoring extra header, type %d, length %d", buffer[2], buffer[0]); break; } next_desc: buflen -= buffer[0]; buffer += buffer[0]; } if (!union_header) { DEBUG(2,"No union descriptor, giving up\n"); return -ENODEV; } /* Found the slave interface, now find active/idle settings and endpoints */ intf->data_interface = union_header->bSlaveInterface0; /* Loop through all of the interfaces */ for (i = 0; i < config->bNumInterfaces; i++) { /* Loop through all of the alternate settings */ for (a = 0; a < config->interface[i].num_altsetting; a++) { /* Check if this interface is OBEX data interface*/ /* and find endpoints */ if (config->interface[i].altsetting[a].bInterfaceNumber == intf->data_interface) find_eps(intf, config->interface[i].altsetting[a], &found_active, &found_idle); } } if (!found_idle) { DEBUG(2,"No idle setting\n"); return -ENODEV; } if (!found_active) { DEBUG(2,"No active setting\n"); return -ENODEV; } return 0; } /* * Helper function to usbobex_find_interfaces */ static int get_intf_string(struct libusb_device_handle *usb_handle, char **string, int id) { if (id) { *string = malloc(USB_MAX_STRING_SIZE); if (*string == NULL) return -errno; *string[0] = '\0'; return libusb_get_string_descriptor_ascii(usb_handle, id, (unsigned char*)*string, USB_MAX_STRING_SIZE); } return 0; } /* * Helper function to usbobex_find_interfaces */ static struct obex_usb_intf_transport_t *check_intf(struct libusb_device *dev, struct libusb_config_descriptor *conf_desc, int i, int a) { const struct libusb_interface_descriptor *alt; alt = &conf_desc->interface[i].altsetting[a]; if (alt->bInterfaceClass == USB_CDC_CLASS && alt->bInterfaceSubClass == USB_CDC_OBEX_SUBCLASS) { int err; const unsigned char *buffer = alt->extra; int buflen = alt->extra_length; struct obex_usb_intf_transport_t *next; next = calloc(1, sizeof(*next)); if (next == NULL) return NULL; next->device = dev; libusb_ref_device(dev); next->configuration = conf_desc->bConfigurationValue; next->configuration_description = conf_desc->iConfiguration; next->control_interface = alt->bInterfaceNumber; next->control_interface_description = alt->iInterface; next->control_setting = alt->bAlternateSetting; next->extra_descriptors = malloc(buflen); if (next->extra_descriptors) memcpy(next->extra_descriptors, buffer, buflen); next->extra_descriptors_len = buflen; err = find_obex_data_interface(buffer, buflen, conf_desc, next); if (err) { free(next); return NULL; } return next; } return NULL; } /* * Function usbobex_find_interfaces () * * Find available USBOBEX interfaces on the system */ static int usbobex_find_interfaces(obex_t *self, obex_interface_t **interfaces) { struct usbobex_data *data = self->trans->data; struct libusb_context *libusb_ctx = data->ctx; struct obex_usb_intf_transport_t *first = NULL; struct obex_usb_intf_transport_t *current = NULL; int i, a; int num = 0; obex_interface_t *intf_array = NULL; if (libusb_ctx) { libusb_device **list; size_t cnt_dev = libusb_get_device_list(libusb_ctx, &list); size_t d = 0; for (d = 0; d < cnt_dev; d++) { struct libusb_config_descriptor *conf_desc; if (libusb_get_active_config_descriptor(list[d], &conf_desc) == 0) { for (i = 0; i < conf_desc->bNumInterfaces; i++) { for (a = 0; a < conf_desc->interface[i].num_altsetting; a++) { /* and find data interface */ struct obex_usb_intf_transport_t *next; next = check_intf(list[d], conf_desc, i, a); if (!next) continue; ++num; if (current) current->next = next; current = next; if (first == NULL) first = current; } } libusb_free_config_descriptor(conf_desc); } } libusb_free_device_list(list, 1); } intf_array = calloc(num, sizeof(*intf_array)); if (intf_array == NULL) { while (current) { struct obex_usb_intf_transport_t *tmp = current->next; free(current); current = tmp; } return 0; } num = 0; current = first; while (current) { struct libusb_device_handle *usb_handle; intf_array[num].usb.intf = current; if (libusb_open(current->device, &usb_handle) == 0) { struct libusb_device_descriptor dev_desc; if (libusb_get_device_descriptor(current->device, &dev_desc) == 0) { get_intf_string(usb_handle, &intf_array[num].usb.manufacturer, dev_desc.iManufacturer); get_intf_string(usb_handle, &intf_array[num].usb.product, dev_desc.iProduct); get_intf_string(usb_handle, &intf_array[num].usb.serial, dev_desc.iSerialNumber); get_intf_string(usb_handle, &intf_array[num].usb.configuration, current->configuration_description); get_intf_string(usb_handle, &intf_array[num].usb.control_interface, current->control_interface_description); get_intf_string(usb_handle, &intf_array[num].usb.data_interface_idle, current->data_interface_idle_description); get_intf_string(usb_handle, &intf_array[num].usb.data_interface_active, current->data_interface_active_description); intf_array[num].usb.idVendor = dev_desc.idVendor; intf_array[num].usb.idProduct = dev_desc.idProduct; intf_array[num].usb.bus_number = libusb_get_bus_number(current->device); intf_array[num].usb.device_address = libusb_get_device_address(current->device); intf_array[num].usb.interface_number = current->control_interface; } find_obex_service_descriptor(current->extra_descriptors, current->extra_descriptors_len, &intf_array[num].usb.service); libusb_close(usb_handle); } current = current->next; ++num; } *interfaces = intf_array; return num; } /* * Function usbobex_free_interface () * * Free a discovered USBOBEX interface on the system */ static void usbobex_free_interface(obex_interface_t *intf) { if (intf) { free(intf->usb.manufacturer); free(intf->usb.product); free(intf->usb.serial); free(intf->usb.configuration); free(intf->usb.control_interface); free(intf->usb.data_interface_idle); free(intf->usb.data_interface_active); free(intf->usb.service); free(intf->usb.intf->extra_descriptors); libusb_unref_device(intf->usb.intf->device); free(intf->usb.intf); } } /* * Function usbobex_connect_request (self) * * Open the USB connection * */ static bool usbobex_connect_request(obex_t *self) { struct usbobex_data *data = self->trans->data; int ret; DEBUG(4, "\n"); ret = libusb_open(data->self.device, &data->self.dev); if (ret != 0) return false; ret = libusb_claim_interface(data->self.dev, data->self.control_interface); if (ret < 0) { DEBUG(4, "Can't claim control interface %d", ret); goto err1; } ret = libusb_set_interface_alt_setting(data->self.dev, data->self.control_interface, data->self.control_setting); if (ret < 0) { DEBUG(4, "Can't set control setting %d", ret); goto err2; } ret = libusb_claim_interface(data->self.dev, data->self.data_interface); if (ret < 0) { DEBUG(4, "Can't claim data interface %d", ret); goto err2; } ret = libusb_set_interface_alt_setting(data->self.dev, data->self.data_interface, data->self.data_active_setting); if (ret < 0) { DEBUG(4, "Can't set data active setting %d", ret); goto err3; } return true; err3: libusb_release_interface(data->self.dev, data->self.data_interface); err2: libusb_release_interface(data->self.dev, data->self.control_interface); err1: libusb_close(data->self.dev); return false; } /* * Function usbobex_disconnect (self) * * Shutdown the USB link * */ static bool usbobex_disconnect(obex_t *self) { struct usbobex_data *data = self->trans->data; int ret; DEBUG(4, "\n"); libusb_clear_halt(data->self.dev, data->self.data_endpoint_read); libusb_clear_halt(data->self.dev, data->self.data_endpoint_write); ret = libusb_set_interface_alt_setting(data->self.dev, data->self.data_interface, data->self.data_idle_setting); if (ret < 0) { DEBUG(4, "Can't set data idle setting %d", ret); } ret = libusb_release_interface(data->self.dev, data->self.data_interface); if (ret < 0) { DEBUG(4, "Can't release data interface %d", ret); } ret = libusb_release_interface(data->self.dev, data->self.control_interface); if (ret < 0) { DEBUG(4, "Can't release control interface %d", ret); } libusb_close(data->self.dev); return true; } static unsigned int usbobex_get_timeout(int64_t timeout) { /* uses closest to zero, 0 itself means infinite */ if (timeout == 0) { return 1; } else if (timeout > 0) { if ((uint64_t)timeout > UINT_MAX) return UINT_MAX; else return (unsigned int)timeout; } return 0; } static ssize_t usbobex_write(obex_t *self, struct databuffer *msg) { struct obex_transport *trans = self->trans; struct usbobex_data *data = self->trans->data; int actual = 0; int usberror; DEBUG(4, "Endpoint %d\n", data->self.data_endpoint_write); usberror = libusb_bulk_transfer(data->self.dev, data->self.data_endpoint_write, buf_get(msg), buf_get_length(msg), &actual, usbobex_get_timeout(trans->timeout)); switch (usberror) { case 0: buf_clear(msg, actual); return actual; case LIBUSB_ERROR_TIMEOUT: buf_clear(msg, actual); return 0; default: return -1; } } static ssize_t usbobex_read(obex_t *self, void *buf, int buflen) { struct obex_transport *trans = self->trans; struct usbobex_data *data = self->trans->data; int usberror; int actual = 0; /* USB can only read 0xFFFF bytes at once (equals mtu_rx) */ DEBUG(4, "Endpoint %d\n", data->self.data_endpoint_read); usberror = libusb_bulk_transfer(data->self.dev, data->self.data_endpoint_read, buf, self->mtu_rx, &actual, usbobex_get_timeout(trans->timeout)); switch (usberror) { case 0: if (actual > buflen) buflen = actual; break; case LIBUSB_ERROR_TIMEOUT: actual = 0; break; default: actual = -1; break; } return actual; } static result_t usbobex_handle_input(obex_t *self) { ssize_t err = obex_transport_read(self, 0); if (err > 0) return RESULT_SUCCESS; else if (err == 0) return RESULT_TIMEOUT; else return RESULT_ERROR; } static struct obex_transport_ops usbobex_transport_ops = { &usbobex_create, &usbobex_init, &usbobex_cleanup, &usbobex_handle_input, &usbobex_write, &usbobex_read, &usbobex_disconnect, &usbobex_get_fd, NULL, NULL, { NULL, NULL, }, { &usbobex_connect_request, &usbobex_find_interfaces, &usbobex_free_interface, &usbobex_select_interface, }, }; struct obex_transport * usbobex_transport_create(void) { return obex_transport_create(&usbobex_transport_ops); } #endif /* HAVE_USB1 */ openobex-1.7.2-Source/lib/membuf.h000644 001750 001750 00000001745 12604167677 020131 0ustar00hendrikhendrik000000 000000 /** \file membuf.h Memory buffer handling routines. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2012 Hendrik Sattler, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef MEMBUF_H #define MEMBUF_H #include /* from databuffer.h */ struct databuffer; struct databuffer *membuf_create(size_t default_size); #endif /* MEMBUF_H */ openobex-1.7.2-Source/lib/obex_body.c000644 001750 001750 00000010634 12604167677 020620 0ustar00hendrikhendrik000000 000000 /** * @file obex_body.c * * OBEX body reception releated functions. * OpenOBEX library - Free implementation of the Object Exchange protocol. * * Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved. * Copyright (c) 1999, 2000 Dag Brattli, All Rights Reserved. * Copyright (c) 2012 Hendrik Sattler, All Rights Reserved. * * OpenOBEX is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the * Free Software Foundation; either version 2.1 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with OpenOBEX. If not, see . */ #include #include #include #include int obex_body_rcv(struct obex_body *self, struct obex_hdr *hdr) { if (self && self->ops && self->ops->rcv) return self->ops->rcv(self->data, hdr); else return -1; } const void * obex_body_read(struct obex_body *self, size_t *size) { if (self && self->ops && self->ops->read) return self->ops->read(self->data, size); else return NULL; } static int obex_body_stream_rcv(void *self, struct obex_hdr *hdr) { obex_t *obex = self; obex_object_t *object = obex->object; uint8_t cmd = obex_object_getcmd(object); enum obex_hdr_id id = obex_hdr_get_id(hdr); enum obex_hdr_type type = obex_hdr_get_type(hdr); size_t len = obex_hdr_get_data_size(hdr); DEBUG(4, "\n"); /* Spare the app this empty nonlast body-hdr */ if (obex_hdr_get_id(hdr) == OBEX_HDR_ID_BODY && obex_hdr_get_data_size(hdr) == 0) return 1; /* Notify app that data has arrived */ object->body = hdr; obex_deliver_event(obex, OBEX_EV_STREAMAVAIL, cmd, 0, FALSE); object->body = NULL; /* If send send EOS to app */ if (id == OBEX_HDR_ID_BODY_END && len != 0) { object->body = obex_hdr_ptr_create(id, type, NULL, 0); obex_deliver_event(obex, OBEX_EV_STREAMAVAIL, cmd, 0, FALSE); obex_hdr_destroy(object->body); object->body = NULL; } return 1; } static const void * obex_body_stream_read(void *self, size_t *size) { obex_t *obex = self; obex_object_t *object = obex->object; const void *buf = obex_hdr_get_data_ptr(object->body); if (buf && size) *size = obex_hdr_get_data_size(object->body); return buf; } struct obex_body_ops obex_body_stream_ops = { &obex_body_stream_rcv, &obex_body_stream_read, }; struct obex_body * obex_body_stream_create(obex_t *obex) { struct obex_body *self = calloc(1, sizeof(*self)); if (self) { self->ops = &obex_body_stream_ops; self->data = obex; } return self; } static int obex_body_buffered_rcv(void *self, struct obex_hdr *hdr) { obex_object_t *object = self; const void *data = obex_hdr_get_data_ptr(hdr); size_t len = obex_hdr_get_data_size(hdr); DEBUG(4, "This is a body-header.\n"); if (!object->body) { int alloclen = obex_hdr_get_data_size(hdr); if (object->hinted_body_len) alloclen = object->hinted_body_len; DEBUG(4, "Allocating new body-buffer. Len=%d\n", alloclen); object->body = obex_hdr_membuf_create(OBEX_HDR_ID_BODY, OBEX_HDR_TYPE_BYTES, data, len); if (!object->body) return -1; } else { struct databuffer *buf; buf = obex_hdr_membuf_get_databuffer(object->body); if (buf_append(buf, data, len) < 0) return -1; } if (obex_hdr_get_id(hdr) == OBEX_HDR_ID_BODY_END) { hdr = object->body; object->body = NULL; /* Add element to rx-list */ object->rx_headerq = slist_append(object->rx_headerq, hdr); if (object->rx_it == NULL) object->rx_it = obex_hdr_it_create(object->rx_headerq); } return 1; } static const void * obex_body_buffered_read(void *self, size_t *size) { obex_object_t *object = self; const void *buf = obex_hdr_get_data_ptr(object->body); if (buf && size) *size = obex_hdr_get_data_size(object->body); return buf; } struct obex_body_ops obex_body_buffered_ops = { &obex_body_buffered_rcv, &obex_body_buffered_read, }; struct obex_body * obex_body_buffered_create(obex_object_t *object) { struct obex_body *self = calloc(1, sizeof(*self)); if (self) { self->ops = &obex_body_buffered_ops; self->data = object; } return self; } openobex-1.7.2-Source/lib/obex_body.h000644 001750 001750 00000002716 12604167677 020627 0ustar00hendrikhendrik000000 000000 /** * @file obex_body.h * * OBEX body reception releated functions. * OpenOBEX library - Free implementation of the Object Exchange protocol. * * Copyright (c) 2012 Hendrik Sattler, All Rights Reserved. * * OpenOBEX is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the * Free Software Foundation; either version 2.1 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with OpenOBEX. If not, see . */ #ifndef OBEX_BODY_H #define OBEX_BODY_H #include #include "defines.h" struct obex; struct obex_hdr; struct obex_object; struct obex_body_ops { int (*rcv)(void *data, struct obex_hdr *hdr); const void * (*read)(void *data, size_t *size); }; struct obex_body { struct obex_body_ops *ops; void *data; }; int obex_body_rcv(struct obex_body *self, struct obex_hdr *hdr); const void * obex_body_read(struct obex_body *self, size_t *size); struct obex_body * obex_body_stream_create(struct obex *obex); struct obex_body * obex_body_buffered_create(struct obex_object *object); #endif /* OBEX_BODY_H */ openobex-1.7.2-Source/lib/obex_client.c000644 001750 001750 00000017766 12604167677 021156 0ustar00hendrikhendrik000000 000000 /** \file obex_client.c Handle client operations. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999-2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #include "obex_main.h" #include "obex_object.h" #include "obex_connect.h" #include "obex_client.h" #include "obex_msg.h" #include "databuffer.h" #include #include static __inline enum obex_rsp msg_get_rsp(obex_t *self) { int opcode = obex_msg_get_opcode(self); if (opcode < 0) return OBEX_RSP_BAD_REQUEST; else return opcode & ~OBEX_FINAL; } static __inline uint16_t msg_get_len(const buf_t *msg) { if (msg) { obex_common_hdr_t *hdr = buf_get(msg); return ntohs(hdr->len); } else return 0; } static result_t obex_client_abort_tx(obex_t *self) { self->substate = SUBSTATE_RX; return RESULT_SUCCESS; } static result_t obex_client_abort_tx_prepare(obex_t *self) { DEBUG(4, "STATE: ABORT/TX_PREPARE\n"); if (!obex_data_request_init(self)) return RESULT_ERROR; obex_data_request_prepare(self, OBEX_CMD_ABORT); self->substate = SUBSTATE_TX; return RESULT_SUCCESS; } static result_t obex_client_abort_rx(obex_t *self) { int ret = RESULT_SUCCESS; enum obex_rsp rsp; int event = OBEX_EV_LINKERR; DEBUG(4, "STATE: ABORT/RX\n"); if (!obex_msg_rx_status(self)) return RESULT_SUCCESS; rsp = msg_get_rsp(self); if (rsp == OBEX_RSP_SUCCESS) event = OBEX_EV_ABORT; obex_deliver_event(self, event, self->object->cmd, rsp, true); if (event == OBEX_EV_LINKERR) ret = RESULT_ERROR; self->mode = OBEX_MODE_SERVER; self->state = STATE_IDLE; return ret; } static result_t obex_client_response_tx(obex_t *self) { enum obex_cmd cmd = self->object->cmd; enum obex_rsp rsp = OBEX_RSP_CONTINUE; obex_deliver_event(self, OBEX_EV_PROGRESS, cmd, rsp, false); self->substate = SUBSTATE_RX; return RESULT_SUCCESS; } static result_t obex_client_response_tx_prepare(obex_t *self) { DEBUG(4, "STATE: RESPONSE/TX_PREPARE\n"); /* Sending ABORT is allowed even during SRM */ if (self->object->abort) { self->state = STATE_ABORT; return obex_client_abort_tx_prepare(self); } if (self->object->rsp_mode == OBEX_RSP_MODE_NORMAL || (self->object->rsp_mode == OBEX_RSP_MODE_SINGLE && self->srm_flags & OBEX_SRM_FLAG_WAIT_REMOTE)) { if (!obex_msg_prepare(self, self->object, TRUE)) return RESULT_ERROR; self->substate = SUBSTATE_TX; } else { self->substate = SUBSTATE_RX; } return RESULT_SUCCESS; } static result_t obex_client_response_rx(obex_t *self) { enum obex_rsp rsp; DEBUG(4, "STATE: RESPONSE/RX\n"); if (!obex_msg_rx_status(self)) return RESULT_SUCCESS; rsp = msg_get_rsp(self); switch (self->object->cmd) { case OBEX_CMD_CONNECT: DEBUG(2, "We expect a connect-rsp\n"); self->object->headeroffset=4; break; case OBEX_CMD_DISCONNECT: /* Response of a CMD_DISCONNECT needs some special treatment.*/ DEBUG(2, "CMD_DISCONNECT done. Resetting MTU!\n"); self->mtu_tx = OBEX_MINIMUM_MTU; self->rsp_mode = OBEX_RSP_MODE_NORMAL; self->srm_flags = 0; break; default: break; } if (!self->object->abort) { /* Receive any headers */ result_t ret = obex_msg_receive(self, self->object); if (ret == RESULT_ERROR) { obex_deliver_event(self, OBEX_EV_PARSEERR, self->object->cmd, 0, true); self->mode = OBEX_MODE_SERVER; self->state = STATE_IDLE; obex_data_receive_finished(self); return RESULT_ERROR; } } obex_data_receive_finished(self); /* Response of a CMD_CONNECT needs some special treatment.*/ if (self->object->cmd == OBEX_CMD_CONNECT) { DEBUG(2, "We expect a connect-rsp\n"); if (rsp != OBEX_RSP_SUCCESS || obex_parse_connectframe(self, self->object) < 0) { obex_deliver_event(self, OBEX_EV_PARSEERR, self->object->cmd, 0, true); self->mode = OBEX_MODE_SERVER; self->state = STATE_IDLE; return RESULT_ERROR; } } /* Are we done yet? */ if (rsp == OBEX_RSP_CONTINUE) { enum obex_cmd cmd = self->object->cmd; DEBUG(3, "Continue...\n"); obex_deliver_event(self, OBEX_EV_CONTINUE, cmd, rsp, false); /* Return if the user cancelled the request without sending ABORT. * If ABORT is being sent, we continue as usual and let the normal * tx_prepare() handle it. */ if (self->object == NULL) return RESULT_SUCCESS; self->substate = SUBSTATE_TX_PREPARE; return obex_client_response_tx_prepare(self); } else { enum obex_cmd cmd = self->object->cmd; /* Notify app that client-operation is done! */ DEBUG(3, "Done! Rsp=%02x!\n", rsp); obex_deliver_event(self, OBEX_EV_REQDONE, cmd, rsp, true); self->mode = OBEX_MODE_SERVER; self->state = STATE_IDLE; return RESULT_SUCCESS; } } static result_t obex_client_request_tx(obex_t *self) { obex_deliver_event(self, OBEX_EV_PROGRESS, self->object->cmd, 0, false); if (obex_object_finished(self->object, TRUE)) self->state = STATE_RESPONSE; self->substate = SUBSTATE_RX; return RESULT_SUCCESS; } static result_t obex_client_request_tx_prepare(obex_t *self) { DEBUG(4, "STATE: REQUEST/TX_PREPARE\n"); if (self->object->abort) { self->state = STATE_ABORT; return obex_client_abort_tx_prepare(self); } if (!obex_msg_prepare(self, self->object, TRUE)) return RESULT_ERROR; self->substate = SUBSTATE_TX; return RESULT_SUCCESS; } static result_t obex_client_request_rx(obex_t *self) { enum obex_rsp rsp; DEBUG(4, "STATE: REQUEST/RX\n"); if (!obex_msg_rx_status(self)) return RESULT_SUCCESS; rsp = msg_get_rsp(self); /* Any errors from peer? Win2k will send RSP_SUCCESS after * every fragment sent so we have to accept that too.*/ switch (rsp) { case OBEX_RSP_SUCCESS: case OBEX_RSP_CONTINUE: break; default: DEBUG(0, "STATE_SEND. request not accepted.\n"); obex_deliver_event(self, OBEX_EV_REQDONE, self->object->cmd, rsp, true); /* This is not an Obex error, it is just that the peer * doesn't accept the request */ obex_data_receive_finished(self); return RESULT_SUCCESS; } if (!self->object->abort) { int ret = obex_msg_receive(self, self->object); if (ret < 0) { obex_deliver_event(self, OBEX_EV_PARSEERR, self->object->cmd, 0, true); self->mode = OBEX_MODE_SERVER; self->state = STATE_IDLE; obex_data_receive_finished(self); return RESULT_ERROR; } } obex_data_receive_finished(self); self->substate = SUBSTATE_TX_PREPARE; return obex_client_request_tx_prepare(self); } /* * Function obex_client () * * Handle client operations * */ result_t obex_client(obex_t *self) { DEBUG(4, "\n"); switch (self->state) { case STATE_REQUEST: switch (self->substate) { case SUBSTATE_RX: return obex_client_request_rx(self); case SUBSTATE_TX_PREPARE: return obex_client_request_tx_prepare(self); case SUBSTATE_TX: return obex_client_request_tx(self); default: break; } break; case STATE_RESPONSE: switch (self->substate) { case SUBSTATE_RX: return obex_client_response_rx(self); case SUBSTATE_TX_PREPARE: return obex_client_response_tx_prepare(self); case SUBSTATE_TX: return obex_client_response_tx(self); default: break; } break; case STATE_ABORT: switch (self->substate) { case SUBSTATE_RX: return obex_client_abort_rx(self); case SUBSTATE_TX_PREPARE: return obex_client_abort_tx_prepare(self); case SUBSTATE_TX: return obex_client_abort_tx(self); default: break; } break; default: DEBUG(0, "Unknown state\n"); break; } return RESULT_ERROR; } openobex-1.7.2-Source/lib/obex_client.h000644 001750 001750 00000001632 12604167677 021144 0ustar00hendrikhendrik000000 000000 /** \file obex_client.h Handle client operations. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999-2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef OBEX_CLIENT_H #define OBEX_CLIENT_H struct obex; int obex_client(struct obex *self); #endif openobex-1.7.2-Source/lib/obex_connect.c000644 001750 001750 00000004440 12604167677 021312 0ustar00hendrikhendrik000000 000000 /** \file obex_connect.c Parse and create connect-command. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2000 Pontus Fuchs, All Rights Reserved. Copyright (c) 1999 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #include "obex_main.h" #include "obex_object.h" #include "databuffer.h" #include "obex_connect.h" #include #include /* Connect header */ #pragma pack(1) struct obex_connect_hdr { uint8_t version; uint8_t flags; uint16_t mtu; }; #pragma pack() /** Add the data needed to send/reply to a CONNECT request */ int obex_insert_connectframe(obex_t *self, obex_object_t *object) { struct databuffer *buf = object->tx_nonhdr_data; struct obex_connect_hdr *hdr; DEBUG(4, "\n"); if (!buf) { buf = object->tx_nonhdr_data = membuf_create(sizeof(*hdr)); if (!buf) return -1; } else buf_clear(buf, buf_get_length(buf)); buf_append(buf, NULL, sizeof(*hdr)); hdr = buf_get(buf); hdr->version = OBEX_VERSION; hdr->flags = 0x00; /* Flags */ hdr->mtu = htons(self->mtu_rx); /* Max packet size */ return 0; } /** Parse the non-header data of a CONNECT request/response */ int obex_parse_connectframe(obex_t *self, obex_object_t *object) { struct databuffer *buf = object->rx_nonhdr_data; struct obex_connect_hdr *conn_hdr = buf_get(buf); uint16_t mtu = ntohs(conn_hdr->mtu); DEBUG(1, "version=%02x\n", conn_hdr->version); /* Limit to some reasonable value (usually OBEX_DEFAULT_MTU) */ if (mtu < self->mtu_tx_max) self->mtu_tx = mtu; else self->mtu_tx = self->mtu_tx_max; DEBUG(1, "requested MTU=%u, used MTU=%u\n", mtu, self->mtu_tx); return 1; } openobex-1.7.2-Source/lib/obex_hdr.c000644 001750 001750 00000014777 12604167677 020454 0ustar00hendrikhendrik000000 000000 /** * @file obex_hdr.c * * OBEX header releated functions. * OpenOBEX library - Free implementation of the Object Exchange protocol. * * Copyright (c) 2012 Hendrik Sattler, All Rights Reserved. * * OpenOBEX is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the * Free Software Foundation; either version 2.1 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with OpenOBEX. If not, see . */ #include "obex_hdr.h" #include "defines.h" #include struct obex_hdr * obex_hdr_create(enum obex_hdr_id id, enum obex_hdr_type type, const void *value, size_t size, unsigned int flags) { struct obex_hdr *hdr; const unsigned int save_flags = OBEX_FL_SUSPEND; if (flags & OBEX_FL_COPY) hdr = obex_hdr_membuf_create(id, type, value, size); else hdr = obex_hdr_ptr_create(id, type, value, size); if (!hdr) return NULL; hdr->flags |= (flags & save_flags); return hdr; } struct obex_hdr * obex_hdr_new(struct obex_hdr_ops *ops, void *data) { struct obex_hdr *hdr = calloc(1, sizeof(*hdr)); if (!hdr) { if (ops && ops->destroy) ops->destroy(data); return NULL; } hdr->ops = ops; hdr->data = data; return hdr; } void obex_hdr_destroy(struct obex_hdr *hdr) { if (hdr->ops && hdr->ops->destroy) hdr->ops->destroy(hdr->data); hdr->ops = NULL; hdr->data = NULL; free(hdr); } enum obex_hdr_id obex_hdr_get_id(struct obex_hdr *hdr) { if (hdr->ops && hdr->ops->get_id) return hdr->ops->get_id(hdr->data); else return OBEX_HDR_ID_INVALID; } enum obex_hdr_type obex_hdr_get_type(struct obex_hdr *hdr) { if (hdr->ops && hdr->ops->get_type) return hdr->ops->get_type(hdr->data); else return OBEX_HDR_TYPE_INVALID; } static size_t obex_hdr_get_hdr_size(struct obex_hdr *hdr) { switch (obex_hdr_get_type(hdr)) { case OBEX_HDR_TYPE_UINT8: case OBEX_HDR_TYPE_UINT32: return 1; case OBEX_HDR_TYPE_BYTES: case OBEX_HDR_TYPE_UNICODE: return 3; default: return 0; } } size_t obex_hdr_get_data_size(struct obex_hdr *hdr) { if (hdr->ops && hdr->ops->get_data_size) if (hdr->ops && hdr->ops->append_data) return hdr->ops->get_data_size(hdr->data); else return hdr->ops->get_data_size(hdr->data) - hdr->offset; else return (size_t)0; } size_t obex_hdr_get_size(struct obex_hdr *hdr) { size_t hdr_size = obex_hdr_get_hdr_size(hdr); size_t data_size = obex_hdr_get_data_size(hdr); return hdr_size + data_size; } const void * obex_hdr_get_data_ptr(struct obex_hdr *hdr) { if (hdr->ops && hdr->ops->get_data_ptr) if (hdr->ops && hdr->ops->append_data) return hdr->ops->get_data_ptr(hdr->data); else return (uint8_t *)hdr->ops->get_data_ptr(hdr->data) + hdr->offset; else return NULL; } bool obex_hdr_set_data(struct obex_hdr *hdr, const void *data, size_t size) { if (hdr->ops && hdr->ops->set_data) return hdr->ops->set_data(hdr->data, data, size); else return false; } bool obex_hdr_is_splittable(struct obex_hdr *hdr) { return (obex_hdr_get_id(hdr) == OBEX_HDR_ID_BODY && obex_hdr_get_type(hdr) == OBEX_HDR_TYPE_BYTES); } static size_t obex_hdr_append_data(struct obex_hdr *hdr, struct databuffer *buf, size_t size) { if (hdr->ops && hdr->ops->append_data) return hdr->ops->append_data(hdr->data, buf, size); buf_append(buf, obex_hdr_get_data_ptr(hdr), size); hdr->offset += size; return size; } #define MIN_DATA_SIZE 1 /** Append the header to a buffer * @param hdr the header instance * @param buf the buffer to append to * @param size maximum number of bytes to append to the buffer * @return the actual number of appended bytes */ size_t obex_hdr_append(struct obex_hdr *hdr, struct databuffer *buf, size_t max_size) { size_t actual = 0; uint8_t *h; size_t buflen = buf_get_length(buf); size_t hdr_size = obex_hdr_get_hdr_size(hdr); size_t data_size = obex_hdr_get_data_size(hdr); if (((hdr_size + data_size) > max_size && !obex_hdr_is_splittable(hdr)) || hdr_size + MIN_DATA_SIZE > max_size) return 0; buf_append(buf, NULL, hdr_size); h = (uint8_t *)buf_get(buf) + buflen; actual += hdr_size; while (max_size > actual && data_size != 0) { size_t ret; if (data_size > (max_size - actual)) { if (obex_hdr_is_splittable(hdr)) data_size = max_size - actual; else return 0; } if (obex_hdr_get_type(hdr) == OBEX_HDR_TYPE_UINT8 && data_size != 1) { if (data_size < 1) { uint8_t dummy = 0; buf_append(buf, &dummy, 1); ret = 1; } else ret = obex_hdr_append_data(hdr, buf, 1); } else if (obex_hdr_get_type(hdr) == OBEX_HDR_TYPE_UINT32 && data_size != 4) { if (data_size < 4) { uint32_t dummy = 0; buf_append(buf, &dummy, 4); ret = 1; } else ret = obex_hdr_append_data(hdr, buf, 4); } else ret = obex_hdr_append_data(hdr, buf, data_size); actual += ret; if (ret == 0 ) break; data_size = obex_hdr_get_data_size(hdr); } ; h[0] = obex_hdr_get_id(hdr) | obex_hdr_get_type(hdr); if (hdr_size > 1) { h[1] = (actual >> 8) & 0xFF; h[2] = actual & 0xFF; } return actual; } bool obex_hdr_is_finished(struct obex_hdr *hdr) { if (hdr->ops && hdr->ops->is_finished) return hdr->ops->is_finished(hdr->data); else return (obex_hdr_get_data_size(hdr) == 0); } void obex_hdr_it_init_from(struct obex_hdr_it *it, const struct obex_hdr_it *from) { if (from) { it->list = from->list; it->is_valid = from->is_valid; } else { it->list = NULL; it->is_valid = FALSE; } } struct obex_hdr_it * obex_hdr_it_create(struct databuffer_list *list) { struct obex_hdr_it *it = malloc(sizeof(*it)); if (it) { it->list = list; it->is_valid = TRUE; } return it; } void obex_hdr_it_destroy(struct obex_hdr_it *it) { if (it == NULL) return; it->list = NULL; free(it); } struct obex_hdr * obex_hdr_it_get(const struct obex_hdr_it *it) { if (it->is_valid) return slist_get(it->list); else return NULL; } void obex_hdr_it_next(struct obex_hdr_it *it) { if (it == NULL) return; it->is_valid = slist_has_more(it->list); if (it->is_valid) it->list = it->list->next; } int obex_hdr_it_equals(const struct obex_hdr_it *a, const struct obex_hdr_it *b) { return a && b && (memcmp(a, b, sizeof(*a)) == 0); } openobex-1.7.2-Source/lib/obex_incl.h000644 001750 001750 00000001250 12701160572 020570 0ustar00hendrikhendrik000000 000000 #ifndef OBEX_INCL_H #define OBEX_INCL_H #include "transport/bluez_compat.h" #if defined(_WIN32) # include /* make sure to use version 2 of Windows socket API */ # include # define CALLAPI WINAPI #endif #include "openobex_export.h" #ifndef LIB_SYMBOL #define LIB_SYMBOL OPENOBEX_EXPORT #endif #ifndef CALLAPI #define CALLAPI #endif /* This overides the define in openobex/obex.h */ #define OPENOBEX_SYMBOL(retval) LIB_SYMBOL retval CALLAPI /* Visual Studio C++ Compiler 7.1 does not know about Bluetooth */ #if ( defined(_MSC_VER) && _MSC_VER < 1400 ) || !defined(HAVE_BLUETOOTH) #define bt_addr_t void #endif #include #endif openobex-1.7.2-Source/lib/obex_main.c000644 001750 001750 00000027041 12701160572 020570 0ustar00hendrikhendrik000000 000000 /** \file obex_main.c Implementation of the Object Exchange Protocol OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2000 Pontus Fuchs, All Rights Reserved. Copyright (c) 1998, 1999 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #ifdef _WIN32 #include #else /* _WIN32 */ #include #include #include #include #include #include #include #endif /* _WIN32 */ #include #include "obex_main.h" #include "obex_transport.h" #include "obex_object.h" #include "obex_server.h" #include "obex_client.h" #include "obex_hdr.h" #include "obex_msg.h" #include "databuffer.h" #include int obex_debug; int obex_dump; void obex_library_init(void) { char *env; #if OBEX_DEBUG obex_debug = OBEX_DEBUG; #else obex_debug = -1; #endif env = getenv("OBEX_DEBUG"); if (env) obex_debug = atoi(env); #if OBEX_DUMP obex_dump = OBEX_DUMP; #else obex_dump = 0; #endif env = getenv("OBEX_DUMP"); if (env) obex_dump = atoi(env); } obex_t * obex_create(obex_event_t eventcb, unsigned int flags) { obex_t *self; self = calloc(1, sizeof(*self)); if (self == NULL) return NULL; self->eventcb = eventcb; self->init_flags = flags; self->mode = OBEX_MODE_SERVER; self->state = STATE_IDLE; self->rsp_mode = OBEX_RSP_MODE_NORMAL; /* Safe values. * Both self->mtu_rx and self->mtu_tx_max can be increased by app * self->mtu_tx will be whatever the other end sends us - Jean II */ self->mtu_tx = OBEX_MINIMUM_MTU; if (obex_set_mtu(self, OBEX_DEFAULT_MTU, OBEX_DEFAULT_MTU)) { obex_destroy(self); self = NULL; } return self; } void obex_destroy(obex_t *self) { if (self->trans) obex_transport_cleanup(self); if (self->tx_msg) buf_delete(self->tx_msg); if (self->rx_msg) buf_delete(self->rx_msg); free(self); } int obex_set_mtu(obex_t *self, uint16_t mtu_rx, uint16_t mtu_tx_max) { if (mtu_rx < OBEX_MINIMUM_MTU /*|| mtu_rx > OBEX_MAXIMUM_MTU*/) return -E2BIG; if (mtu_tx_max < OBEX_MINIMUM_MTU /*|| mtu_tx_max > OBEX_MAXIMUM_MTU*/) return -E2BIG; /* Change MTUs */ self->mtu_rx = mtu_rx; self->mtu_tx_max = mtu_tx_max; /* (Re)Allocate transport buffers */ if (self->rx_msg) buf_set_size(self->rx_msg, self->mtu_rx); else self->rx_msg = membuf_create(self->mtu_rx); if (self->rx_msg == NULL) return -ENOMEM; if (self->tx_msg) buf_set_size(self->tx_msg, self->mtu_tx_max); else self->tx_msg = membuf_create(self->mtu_tx_max); if (self->tx_msg == NULL) return -ENOMEM; return 0; } /* * Function obex_response_to_string(rsp) * * Return a string of an OBEX-response * */ char *obex_response_to_string(int rsp) { switch (rsp) { case OBEX_RSP_CONTINUE: return "Continue"; case OBEX_RSP_SWITCH_PRO: return "Switching protocols"; case OBEX_RSP_SUCCESS: return "OK, Success"; case OBEX_RSP_CREATED: return "Created"; case OBEX_RSP_ACCEPTED: return "Accepted"; case OBEX_RSP_NO_CONTENT: return "No Content"; case OBEX_RSP_BAD_REQUEST: return "Bad Request"; case OBEX_RSP_UNAUTHORIZED: return "Unauthorized"; case OBEX_RSP_PAYMENT_REQUIRED: return "Payment required"; case OBEX_RSP_FORBIDDEN: return "Forbidden"; case OBEX_RSP_NOT_FOUND: return "Not found"; case OBEX_RSP_METHOD_NOT_ALLOWED: return "Method not allowed"; case OBEX_RSP_CONFLICT: return "Conflict"; case OBEX_RSP_INTERNAL_SERVER_ERROR: return "Internal server error"; case OBEX_RSP_NOT_IMPLEMENTED: return "Not implemented!"; case OBEX_RSP_DATABASE_FULL: return "Database full"; case OBEX_RSP_DATABASE_LOCKED: return "Database locked"; default: return "Unknown response"; } } /* * Function obex_deliver_event () * * Deliver an event to app. * */ void obex_deliver_event(obex_t *self, enum obex_event event, enum obex_cmd cmd, enum obex_rsp rsp, bool delete_object) { obex_object_t *object = self->object; if (delete_object) self->object = NULL; self->eventcb(self, object, self->mode, event, cmd, rsp); if (delete_object) obex_object_delete(object); } bool obex_data_request_init(obex_t *self) { buf_t *msg = self->tx_msg; int err; buf_clear(msg, buf_get_length(msg)); err = buf_set_size(msg, self->mtu_tx); if (err) return false; buf_append(msg, NULL, sizeof(struct obex_common_hdr)); return true; } /** Prepare response or command code along with optional headers/data to send. * * The caller is supposed to reserve the size of struct obex_common_hdr at the * begin of the message buffer, e.g. using obex_data_request_init() * * @param self the obex instance * @param msg the message buffer * @opcode the message opcode */ void obex_data_request_prepare(obex_t *self, int opcode) { buf_t *msg = self->tx_msg; obex_common_hdr_t *hdr = buf_get(msg); /* alignment is assured here */ hdr->opcode = opcode; hdr->len = htons((uint16_t)buf_get_length(msg)); DUMPBUFFER(1, "Tx", msg); } /** Transmit some data from the TX message buffer. */ static bool obex_data_request_transmit(obex_t *self) { buf_t *msg = self->tx_msg; if (buf_get_length(msg)) { ssize_t status = obex_transport_write(self, msg); if (status > 0) buf_clear(msg, status); else if (status < 0) { DEBUG(4, "Send error\n"); return false; } } return true; } static result_t obex_mode(obex_t *self) { switch (self->mode) { case OBEX_MODE_SERVER: return obex_server(self); case OBEX_MODE_CLIENT: return obex_client(self); default: return RESULT_ERROR; } } enum obex_data_direction obex_get_data_direction(obex_t *self) { if (self->state == STATE_IDLE) return OBEX_DATA_IN; else if (self->substate == SUBSTATE_RX) return OBEX_DATA_IN; else if (self->substate == SUBSTATE_TX) return OBEX_DATA_OUT; else return OBEX_DATA_NONE; } result_t obex_handle_input(obex_t *self) { result_t ret = obex_transport_handle_input(self); if (ret != RESULT_SUCCESS) return ret; if (obex_transport_is_server(self)) { DEBUG(4, "Data available on server socket\n"); if (self->init_flags & OBEX_FL_KEEPSERVER) /* Tell the app to perform the OBEX_Accept() */ obex_deliver_event(self, OBEX_EV_ACCEPTHINT, 0, 0, FALSE); else obex_transport_accept(self, self); return RESULT_SUCCESS; } else { DEBUG(4, "Data available on client socket\n"); return obex_data_indication(self); } } static bool obex_check_srm_input(obex_t *self) { if (self->object->rsp_mode == OBEX_RSP_MODE_SINGLE && !(self->srm_flags & OBEX_SRM_FLAG_WAIT_LOCAL) && ((self->mode == OBEX_MODE_CLIENT && self->state == STATE_REQUEST) || (self->mode == OBEX_MODE_SERVER && self->state == STATE_RESPONSE))) { result_t ret = obex_handle_input(self); if (ret == RESULT_TIMEOUT) { self->substate = SUBSTATE_TX_PREPARE; return false; } } return true; } /* * Function obex_work (self) * * Do some work on the current transferred object. * */ result_t obex_work(obex_t *self) { result_t ret; if (self->state == STATE_IDLE) { ret = obex_handle_input(self); if (ret != RESULT_SUCCESS) return ret; } else if (self->substate == SUBSTATE_RX) { if (obex_check_srm_input(self)) { ret = obex_handle_input(self); if (ret != RESULT_SUCCESS) return ret; } } else if (self->substate == SUBSTATE_TX) { if (!obex_msg_tx_status(self)) { if (!obex_data_request_transmit(self)) { enum obex_cmd cmd = OBEX_CMD_ABORT; if (self->object) cmd = obex_object_getcmd(self->object); obex_deliver_event(self, OBEX_EV_LINKERR, cmd, 0, TRUE); self->mode = OBEX_MODE_SERVER; self->state = STATE_IDLE; return RESULT_ERROR; } if (!obex_msg_tx_status(self)) return RESULT_TIMEOUT; } } return obex_mode(self); } /** Read a message from transport into the RX message buffer. */ result_t obex_data_indication(obex_t *self) { obex_common_hdr_t *hdr; buf_t *msg; int actual; unsigned int size; DEBUG(4, "\n"); obex_return_val_if_fail(self != NULL, RESULT_ERROR); msg = self->rx_msg; /* First we need 3 bytes to be able to know how much data to read */ if (buf_get_length(msg) < sizeof(*hdr)) { size_t readsize = sizeof(*hdr) - buf_get_length(msg); actual = obex_transport_read(self, readsize); DEBUG(4, "Got %d bytes\n", actual); /* Check if we are still connected */ /* do not error if the data is from non-empty but * partial buffer (custom transport) */ if (actual < 0) { obex_deliver_event(self, OBEX_EV_LINKERR, 0, 0, TRUE); return RESULT_ERROR; } if (actual == 0) return RESULT_TIMEOUT; } /* If we have 3 bytes data we can decide how big the packet is */ if (buf_get_length(msg) >= sizeof(*hdr)) { hdr = buf_get(msg); size = ntohs(hdr->len); actual = 0; if (buf_get_length(msg) < size) { size_t readsize = size - buf_get_length(msg); actual = obex_transport_read(self, readsize); /* Check if we are still connected */ /* do not error if the data is from non-empty * but partial buffer (custom transport) */ if (actual < 0) { obex_deliver_event(self, OBEX_EV_LINKERR, 0, 0, TRUE); return RESULT_ERROR; } if (actual == 0) return RESULT_TIMEOUT; } } else { /* Wait until we have at least 3 bytes data */ DEBUG(3, "Need at least 3 bytes got only %lu!\n", (unsigned long)buf_get_length(msg)); return RESULT_SUCCESS; } /* New data has been inserted at the end of message */ DEBUG(1, "Got %d bytes msg len=%lu\n", actual, (unsigned long)buf_get_length(msg)); /* * Make sure that the buffer we have, actually has the specified * number of bytes. If not the frame may have been fragmented, and * we will then need to read more from the socket. */ /* Make sure we have a whole packet */ if (size > buf_get_length(msg)) { DEBUG(3, "Need more data, size=%d, len=%lu!\n", size, (unsigned long)buf_get_length(msg)); /* I'll be back! */ return RESULT_SUCCESS; } DUMPBUFFER(2, "Rx", msg); return RESULT_SUCCESS; } /** Remove message from RX message buffer after evaluation */ void obex_data_receive_finished(obex_t *self) { buf_t *msg = self->rx_msg; unsigned int size = obex_msg_get_len(self); DEBUG(4, "Pulling %u bytes\n", size); buf_clear(msg, size); } /* * Function obex_cancel_request () * * Cancel an ongoing request * */ int obex_cancelrequest(obex_t *self, int nice) { /* If we have no ongoing request do nothing */ if (self->object == NULL) return 0; /* Abort request without sending abort */ if (!nice) { /* Deliver event will delete the object */ obex_deliver_event(self, OBEX_EV_ABORT, 0, 0, TRUE); buf_clear(self->tx_msg, buf_get_length(self->tx_msg)); buf_clear(self->rx_msg, buf_get_length(self->rx_msg)); /* Since we didn't send ABORT to peer we are out of sync * and need to disconnect transport immediately, so we * signal link error to app */ obex_deliver_event(self, OBEX_EV_LINKERR, 0, 0, FALSE); return 1; } else { /* The client or server code will take action at the * right time. */ self->object->abort = true; return 1; } } openobex-1.7.2-Source/lib/obex_main.h000644 001750 001750 00000005767 12701160572 020610 0ustar00hendrikhendrik000000 000000 /** \file obex_main.h Implementation of the Object Exchange Protocol OBEX. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1998, 1999, 2000 Dag Brattli, All Rights Reserved. Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef OBEX_MAIN_H #define OBEX_MAIN_H #include "obex_incl.h" #include "defines.h" #include struct databuffer; struct obex_object; #include "obex_transport.h" #include "defines.h" #include "debug.h" void obex_library_init(void); struct obex { uint16_t mtu_tx; /* Maximum OBEX TX packet size */ uint16_t mtu_rx; /* Maximum OBEX RX packet size */ uint16_t mtu_tx_max; /* Maximum TX we can accept */ enum obex_state state; enum obex_substate substate; enum obex_mode mode; enum obex_rsp_mode rsp_mode; /* OBEX_RSP_MODE_* */ unsigned int init_flags; unsigned int srm_flags; /* Flags for single response mode */ struct databuffer *tx_msg; /* Reusable transmit message */ struct databuffer *rx_msg; /* Reusable receive message */ struct obex_object *object; /* Current object being transfered */ obex_event_t eventcb; /* Event-callback */ enum obex_event abort_event; /**< event for application when server aborts */ obex_transport_t *trans; /* Transport being used */ obex_interface_t *interfaces; /* Array of discovered interfaces */ int interfaces_number; /* Number of discovered interfaces */ void * userdata; /* For user */ }; obex_t * obex_create(obex_event_t eventcb, unsigned int flags); void obex_destroy(obex_t *self); /* Common header used by all frames */ #pragma pack(1) struct obex_common_hdr { uint8_t opcode; uint16_t len; }; #pragma pack() typedef struct obex_common_hdr obex_common_hdr_t; void obex_deliver_event(obex_t *self, enum obex_event event, enum obex_cmd cmd, enum obex_rsp rsp, bool delete_object); result_t obex_handle_input(obex_t *self); result_t obex_work(struct obex *self); enum obex_data_direction obex_get_data_direction(obex_t *self); int obex_get_buffer_status(struct databuffer *msg); int obex_data_indication(struct obex *self); void obex_data_receive_finished(obex_t *self); int obex_set_mtu(obex_t *self, uint16_t mtu_rx, uint16_t mtu_tx_max); bool obex_data_request_init(struct obex *self); void obex_data_request_prepare(struct obex *self, int opcode); int obex_cancelrequest(struct obex *self, int nice); char *obex_response_to_string(int rsp); #endif openobex-1.7.2-Source/lib/obex_transport.c000644 001750 001750 00000017270 12701160572 021703 0ustar00hendrikhendrik000000 000000 /** \file obex_transport.c Handle different types of transports. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999, 2000 Pontus Fuchs, All Rights Reserved. Copyright (c) 1999, 2000 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifdef HAVE_CONFIG_H #include #endif #include "obex_main.h" #include "databuffer.h" #include "obex_transport.h" #include "obex_msg.h" #include #include #include #if defined(_WIN32) #include #endif #ifdef HAVE_IRDA #include "transport/irobex.h" #endif /*HAVE_IRDA*/ #ifdef HAVE_BLUETOOTH #include "transport/btobex.h" #endif /*HAVE_BLUETOOTH*/ #ifdef HAVE_USB #include "transport/usbobex.h" #endif /*HAVE_USB*/ #include "transport/inobex.h" #include "transport/customtrans.h" #include "transport/fdobex.h" struct obex_transport * obex_transport_create(struct obex_transport_ops *ops) { struct obex_transport *trans = calloc(1, sizeof(*trans)); if (!trans) return NULL; trans->ops = ops; trans->data = NULL; if (ops->create) trans->data = ops->create(); trans->timeout = -1; /* no time-out */ trans->connected = false; trans->server = false; return trans; } bool obex_transport_init(obex_t *self, int transport) { switch (transport) { #ifdef HAVE_IRDA case OBEX_TRANS_IRDA: self->trans = irobex_transport_create(); break; #endif /*HAVE_IRDA*/ case OBEX_TRANS_INET: self->trans = inobex_transport_create(); break; case OBEX_TRANS_CUSTOM: self->trans = custom_transport_create(); break; #ifdef HAVE_BLUETOOTH case OBEX_TRANS_BLUETOOTH: self->trans = btobex_transport_create(); break; #endif /*HAVE_BLUETOOTH*/ case OBEX_TRANS_FD: self->trans = fdobex_transport_create(); break; #ifdef HAVE_USB case OBEX_TRANS_USB: self->trans = usbobex_transport_create(); /* Set MTU to the maximum, if using USB transport - Alex Kanavin */ self->mtu_rx = OBEX_MAXIMUM_MTU; self->mtu_tx = OBEX_MINIMUM_MTU; self->mtu_tx_max = OBEX_MAXIMUM_MTU; break; #endif /*HAVE_USB*/ default: self->trans = NULL; break; } if (!self->trans) return false; if (self->trans->ops->init) return self->trans->ops->init(self); else return true; } void obex_transport_cleanup(obex_t *self) { obex_transport_disconnect(self); if (self->trans->ops->cleanup) self->trans->ops->cleanup(self); obex_transport_free_interfaces(self); free(self->trans); self->trans = NULL; } bool obex_transport_is_server(obex_t *self) { return self->trans->server; } /* * Function obex_transport_accept(self) * * Accept an incoming connection. * */ bool obex_transport_accept(obex_t *self, const obex_t *server) { DEBUG(4, "\n"); if (self != server) self->trans = obex_transport_create(server->trans->ops); self->trans->server = false; if (self->trans->ops->server.accept) self->trans->connected = self->trans->ops->server.accept(self, server); return self->trans->connected; } /* * Function obex_transport_get_timeout(self) * * Report current timeout * */ int64_t obex_transport_get_timeout(obex_t *self) { DEBUG(4, "\n"); return self->trans->timeout; } /* * Function obex_transport_set_timeout(self, timeout) * * Change timeout * */ void obex_transport_set_timeout(obex_t *self, int64_t timeout) { DEBUG(4, "\n"); self->trans->timeout = timeout; } /* * Function obex_transport_handle_input(self) * * Used when working in synchronous mode. * */ result_t obex_transport_handle_input(obex_t *self) { DEBUG(4, "\n"); if (self->trans->connected && obex_msg_rx_status(self)) { DEBUG(4, "full message already in buffer\n"); return RESULT_SUCCESS; } if (self->trans->ops->handle_input) return self->trans->ops->handle_input(self); else return RESULT_ERROR; } /* * Function obex_transport_set_local_addr(self, addr, len) * * Set the local server address to bind and listen to. * */ bool obex_transport_set_local_addr(obex_t *self, struct sockaddr *addr, size_t len) { if (!self->trans->connected && self->trans->ops->set_local_addr) return self->trans->ops->set_local_addr(self, addr, len); return false; } /* * Function obex_transport_set_local_addr(self, addr, len) * * Set the remote server address to connect to. * */ bool obex_transport_set_remote_addr(obex_t *self, struct sockaddr *addr, size_t len) { if (!self->trans->connected && self->trans->ops->set_remote_addr) return self->trans->ops->set_remote_addr(self, addr, len); return false; } /* * Function obex_transport_connect_request (self, service) * * Try to connect transport * */ bool obex_transport_connect_request(obex_t *self) { if (self->trans->connected) return false; if (self->trans->ops->client.connect) self->trans->connected = self->trans->ops->client.connect(self); return self->trans->connected; } /* * Function obex_transport_disconnect (self) * * Disconnect transport * * Used either after an accept, or directly at client request (app. exits) * Note : obex_delete_socket() will catch the case when the socket * doesn't exist (-1)... */ void obex_transport_disconnect(obex_t *self) { if (self->trans->connected && self->trans->ops->disconnect) self->trans->connected = !self->trans->ops->disconnect(self); } /* * Function obex_transport_listen (self) * * Prepare for incomming connections * */ bool obex_transport_listen(obex_t *self) { if (self->trans->ops->server.listen) self->trans->server = self->trans->ops->server.listen(self); return self->trans->server; } /* * Function obex_transport_write () * * Do the writing * */ ssize_t obex_transport_write(obex_t *self, buf_t *msg) { if (!self->trans->connected) return 0; if (self->trans->ops->write) return self->trans->ops->write(self, msg); return -1; } /* * Function obex_transport_read () * * Do the reading * */ ssize_t obex_transport_read(obex_t *self, int max) { struct databuffer *msg = self->rx_msg; size_t msglen = buf_get_length(msg); void *buf; if (!self->trans->connected) return 0; if (buf_set_size(msg, msglen + self->mtu_rx)) return -1; buf = (uint8_t *)buf_get(msg) + msglen; if (self->trans->ops->read) { ssize_t ret = self->trans->ops->read(self, buf, max); if (ret > 0) buf_append(msg, NULL, ret); return ret; } else return 0; } void obex_transport_enumerate(struct obex *self) { struct obex_transport_ops *ops = self->trans->ops; int i; if (self->interfaces) return; if (ops->client.find_interfaces) i = ops->client.find_interfaces(self, &self->interfaces); else i = 0; self->interfaces_number = i; } void obex_transport_free_interfaces(struct obex *self) { int i, interfaces_number; DEBUG(4, "\n"); interfaces_number = self->interfaces_number; self->interfaces_number = 0; if (self->interfaces == NULL) return; if (self->trans->ops->client.free_interface == NULL) goto done; for (i = 0; i < interfaces_number; i++) self->trans->ops->client.free_interface(&self->interfaces[i]); done: free(self->interfaces); self->interfaces = NULL; } int obex_transport_get_fd(struct obex *self) { struct obex_transport_ops *ops = self->trans->ops; if (ops->get_fd) return ops->get_fd(self); else return -1; } openobex-1.7.2-Source/lib/obex_transport.h000644 001750 001750 00000006276 12701170013 021703 0ustar00hendrikhendrik000000 000000 /** \file obex_transport.h Handle different types of transports. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 1999 Dag Brattli, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef OBEX_TRANSPORT_H #define OBEX_TRANSPORT_H #ifdef _WIN32 #include #include #else #include #include #include #include #endif #include /* forward declaration for all transport includes */ struct obex_transport_ops; struct obex; struct databuffer; struct obex_transport_ops { void * (*create)(void); bool (*init)(obex_t*); void (*cleanup)(obex_t*); result_t (*handle_input)(obex_t*); ssize_t (*write)(obex_t*, struct databuffer*); ssize_t (*read)(obex_t*, void*, int); bool (*disconnect)(obex_t*); int (*get_fd)(obex_t*); bool (*set_local_addr)(obex_t*, struct sockaddr*, size_t); bool (*set_remote_addr)(obex_t*, struct sockaddr*, size_t); struct { bool (*listen)(obex_t*); bool (*accept)(obex_t*, const obex_t*); } server; struct { bool (*connect)(obex_t*); int (*find_interfaces)(obex_t*, obex_interface_t**); void (*free_interface)(obex_interface_t*); bool (*select_interface)(obex_t*, obex_interface_t*); } client; }; struct obex_transport * obex_transport_create(struct obex_transport_ops *ops); typedef struct obex_transport { struct obex_transport_ops *ops; void *data; /* Private data for the transport */ int64_t timeout; /* set timeout */ bool connected; /* Link connection state */ bool server; /* Listens on local interface */ } obex_transport_t; bool obex_transport_init(obex_t *self, int transport); void obex_transport_cleanup(obex_t *self); bool obex_transport_is_server(obex_t *self); bool obex_transport_accept(obex_t *self, const obex_t *server); int64_t obex_transport_get_timeout(struct obex *self); void obex_transport_set_timeout(struct obex *self, int64_t timeout); result_t obex_transport_handle_input(struct obex *self); bool obex_transport_connect_request(struct obex *self); void obex_transport_disconnect(struct obex *self); bool obex_transport_listen(struct obex *self); ssize_t obex_transport_write(struct obex *self, struct databuffer *msg); ssize_t obex_transport_read(struct obex *self, int count); void obex_transport_enumerate(struct obex *self); void obex_transport_free_interfaces(struct obex *self); int obex_transport_get_fd(struct obex *self); bool obex_transport_set_local_addr(obex_t *self, struct sockaddr *addr, size_t len); bool obex_transport_set_remote_addr(obex_t *self, struct sockaddr *addr, size_t len); #endif /* OBEX_TRANSPORT_H */ openobex-1.7.2-Source/lib/obex_transport_sock.c000644 001750 001750 00000023642 12701160572 022722 0ustar00hendrikhendrik000000 000000 /** * @file obex_transport_sock.c * * OBEX header releated functions. * OpenOBEX library - Free implementation of the Object Exchange protocol. * * Copyright (c) 2012 Hendrik Sattler, All Rights Reserved. * * OpenOBEX is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the * Free Software Foundation; either version 2.1 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with OpenOBEX. If not, see . */ #ifdef _WIN32 #include #endif /* _WIN32 */ #include #include #include #include #include "obex_main.h" #include "obex_transport.h" #include "obex_transport_sock.h" #include "databuffer.h" #include "cloexec.h" #include "nonblock.h" #ifdef _WIN32 #define WSA_VER_MAJOR 2 #define WSA_VER_MINOR 2 #endif socket_t create_stream_socket(int domain, int proto, unsigned int flags) { int type = SOCK_STREAM; socket_t fd; if (flags & OBEX_FL_CLOEXEC) fd = socket_cloexec(domain, type, proto); else fd = socket(domain, type, proto); if (flags & OBEX_FL_NONBLOCK) socket_set_nonblocking(fd); return fd; } bool close_socket(socket_t fd) { if (fd != INVALID_SOCKET) { #ifdef _WIN32 return (closesocket(fd) == 0); #else /* _WIN32 */ return (close(fd) == 0); #endif /* _WIN32 */ } return false; } /** Initialize the socket interface */ bool obex_transport_sock_init(void) { #ifdef _WIN32 WORD ver = MAKEWORD(WSA_VER_MAJOR,WSA_VER_MINOR); WSADATA WSAData; if (WSAStartup (ver, &WSAData) != 0) { DEBUG(4, "WSAStartup failed (%d)\n", WSAGetLastError()); return false; } if (LOBYTE(WSAData.wVersion) != WSA_VER_MAJOR || HIBYTE(WSAData.wVersion) != WSA_VER_MINOR) { DEBUG(4, "WSA version mismatch\n"); WSACleanup(); return false; } #endif return true; } /** Deinitialize the socket interface */ void obex_transport_sock_cleanup(void) { #ifdef _WIN32 WSACleanup(); #endif } /** Create a stream socket with behavior as selected by the user. * Supported behaviours are close-on-exec and non-blocking. * * @param self the obex instance * @param domain the socket domain to use * @param proto the socket protocol within domain * @return a socket */ struct obex_sock * obex_transport_sock_create(int domain, int proto, socklen_t addr_size, unsigned int flags) { struct obex_sock *sock = calloc(1, sizeof(*sock)); #define SAVE_FLAGS (OBEX_FL_CLOEXEC | OBEX_FL_NONBLOCK | OBEX_FL_KEEPSERVER) DEBUG(4, "\n"); if (sock == NULL) return NULL; sock->domain = domain; sock->proto = proto; sock->addr_size = addr_size; sock->flags = flags & SAVE_FLAGS; sock->fd = INVALID_SOCKET; return sock; } /** Close socket. */ bool obex_transport_sock_disconnect(struct obex_sock *sock) { bool res; DEBUG(4, "\n"); res = close_socket(sock->fd); if (res) sock->fd = INVALID_SOCKET; return res; } /** Close socket. */ void obex_transport_sock_destroy(struct obex_sock *sock) { DEBUG(4, "\n"); obex_transport_sock_disconnect(sock); free(sock); } socket_t obex_transport_sock_get_fd(struct obex_sock *sock) { return sock->fd; } /** Set the local address */ bool obex_transport_sock_set_local(struct obex_sock *sock, const struct sockaddr *addr, socklen_t len) { if (len != sock->addr_size || sock->domain != addr->sa_family) return false; memcpy(&sock->local, addr, len); return true; } /** Set the remote address */ bool obex_transport_sock_set_remote(struct obex_sock *sock, const struct sockaddr *addr, socklen_t len) { if (len != sock->addr_size || sock->domain != addr->sa_family) return false; memcpy(&sock->remote, addr, len); return true; } /** Send a buffer. * It may happen (especially with non-blocking mode) that the buffer is only * sent partially. * * @param sock the socket instance * @param msg the message to send * @param timeout give up after timeout (in milliseconds) * @return -1 on error, else number of sent bytes */ ssize_t obex_transport_sock_send(struct obex_sock *sock, struct databuffer *msg, int64_t timeout) { size_t size = buf_get_length(msg); socket_t fd = sock->fd; ssize_t status; fd_set fdset; if (size == 0) return 0; DEBUG(1, "sending %lu bytes\n", (unsigned long)size); FD_ZERO(&fdset); FD_SET(fd, &fdset); if (timeout >= 0) { struct timeval time = {(long)(timeout / 1000), (long)(timeout % 1000)}; status = select((int)fd + 1, NULL, &fdset, NULL, &time); } else { status = select((int)fd + 1, NULL, &fdset, NULL, NULL); } if (status == 0) return 0; /* call send() if no error */ else if (status > 0) status = send(fd, buf_get(msg), size, 0); /* The following are not really transport errors. */ else #if defined(_WIN32) if (status == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) status = 0; #else if (status == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) status = 0; #endif return status; } /** Connect to a remote server */ bool obex_transport_sock_connect(struct obex_sock *sock) { socket_t fd = sock->fd; int ret; DEBUG(4, "\n"); if (fd == INVALID_SOCKET) { fd = sock->fd = create_stream_socket(sock->domain, sock->proto, sock->flags); if (fd == INVALID_SOCKET) { DEBUG(4, "No valid socket: %d\n", errno); goto err; } } if (sock->set_sock_opts) if (!sock->set_sock_opts(fd)) { DEBUG(4, "Failed to set socket options\n"); goto err; } /* Only bind if a local address was specified */ if (sock->local.ss_family != AF_UNSPEC) { ret = bind(fd, (struct sockaddr*)&sock->local, sock->addr_size); if (ret < 0) { DEBUG(4, "Cannot bind to local address: %d\n", errno); goto err; } } ret = connect(fd, (struct sockaddr*) &sock->remote, sock->addr_size); #if defined(_WIN32) if (ret == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) ret = 0; #else if (ret == -1 && errno == EINPROGRESS) ret = 0; #endif if (ret == -1) { DEBUG(4, "Connect failed: %d\n", errno); goto err; } return true; err: obex_transport_sock_disconnect(sock); return false; } bool obex_transport_sock_listen(struct obex_sock *sock) { socket_t fd = sock->fd; if (fd == INVALID_SOCKET) { fd = sock->fd = create_stream_socket(sock->domain, sock->proto, sock->flags); if (fd == INVALID_SOCKET) { DEBUG(4, "No valid socket: %d\n", errno); goto err; } } if (sock->set_sock_opts) if (!sock->set_sock_opts(fd)) { DEBUG(4, "Failed to set socket options\n"); goto err; } if (bind(fd, (struct sockaddr *)&sock->local, sock->addr_size) == -1) { DEBUG(0, "Error doing bind\n"); goto err; } if (listen(fd, 1) == -1) { DEBUG(0, "Error doing listen\n"); goto err; } DEBUG(4, "We are now listening for connections\n"); return true; err: obex_transport_sock_disconnect(sock); return false; } /** Accept an incoming client connection * * @param sock the server socket instance * @return the client socket instance */ struct obex_sock * obex_transport_sock_accept(struct obex_sock *sock) { socket_t serverfd = sock->fd; unsigned int flags = sock->flags; socklen_t socklen = sock->addr_size; struct obex_sock *client; struct sockaddr *addr; if (flags & OBEX_FL_KEEPSERVER) client = calloc(1, sizeof(*sock)); else client = sock; if (client == NULL) return NULL; client->fd = INVALID_SOCKET; client->addr_size = sock->addr_size; client->flags = sock->flags; addr = (struct sockaddr *) &client->remote; // Accept the connection: get socket for the new client if (flags & OBEX_FL_CLOEXEC) client->fd = accept_cloexec(serverfd, addr, &socklen); else client->fd = accept(serverfd, addr, &socklen); if (client->fd == INVALID_SOCKET) goto err_out; if (getsockname(client->fd, (struct sockaddr *)&client->local, &socklen) == -1) { obex_transport_sock_disconnect(client); goto err_out; } if (flags & OBEX_FL_NONBLOCK) socket_set_nonblocking(client->fd); if (client == sock) (void)close_socket(serverfd); return client; err_out: if (client != sock) free(client); return NULL; } /** Wait for incoming data/events * * @param sock the socket instance * @param timeout give up after timeout (in milliseconds) * @return -1 on failure, 0 on timeout, >0 on success */ result_t obex_transport_sock_wait(struct obex_sock *sock, int64_t timeout) { socket_t fd = sock->fd; fd_set fdset; int ret; DEBUG(4, "\n"); /* Check of we have any fd's to do select on. */ if (fd == INVALID_SOCKET) { DEBUG(0, "No valid socket is open\n"); return RESULT_ERROR; } /* Add the fd's to the set. */ FD_ZERO(&fdset); FD_SET(fd, &fdset); /* Wait for input */ if (timeout >= 0) { struct timeval time = {(long)(timeout / 1000), (long)(timeout % 1000)}; ret = select((int)fd + 1, &fdset, NULL, NULL, &time); } else { ret = select((int)fd + 1, &fdset, NULL, NULL, NULL); } /* Check if this is a timeout (0) or error (-1) */ if (ret < 0) return RESULT_ERROR; else if (ret == 0) return RESULT_TIMEOUT; else return RESULT_SUCCESS; } /** Receive into a buffer * It may happen that less than requested bytes are received. * * @param sock the socket instance * @param buf the buffer to receive into * @param buflen the maximum size to receive * @return -1 on error, else number of received bytes */ ssize_t obex_transport_sock_recv(struct obex_sock *sock, void *buf, int buflen) { socket_t fd = sock->fd; ssize_t status = recv(fd, buf, buflen, 0); /* The following are not really transport errors. */ #if defined(_WIN32) if (status == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) status = 0; #else if (status == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) status = 0; #endif return status; } openobex-1.7.2-Source/lib/obex_transport_sock.h000644 001750 001750 00000005605 12701160572 022726 0ustar00hendrikhendrik000000 000000 /** * @file obex_transport_sock.c * * OBEX header releated functions. * OpenOBEX library - Free implementation of the Object Exchange protocol. * * Copyright (c) 2012 Hendrik Sattler, All Rights Reserved. * * OpenOBEX is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the * Free Software Foundation; either version 2.1 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with OpenOBEX. If not, see . */ #ifndef OBEX_TRANSPORT_SOCK_H #define OBEX_TRANSPORT_SOCK_H #ifdef _WIN32 #include #define socket_t SOCKET #else #include #include #define socket_t int #define INVALID_SOCKET -1 #endif #include "defines.h" /** a socket instance */ struct obex_sock { /** socket domain */ int domain; /** socket protocol */ int proto; /** the kernel descriptor for this socket */ socket_t fd; /** the local address of this socket */ struct sockaddr_storage local; /** the remote address of this socket */ struct sockaddr_storage remote; /** the address size of this socket type */ socklen_t addr_size; /** socket OBEX_FL_* flags */ unsigned int flags; /** callback to set transport-specific socket options */ bool (*set_sock_opts)(socket_t); }; bool obex_transport_sock_init(void); void obex_transport_sock_cleanup(void); socket_t create_stream_socket(int domain, int proto, unsigned int flags); bool close_socket(socket_t fd); struct obex_sock * obex_transport_sock_create(int domain, int proto, socklen_t addr_size, unsigned int flags); void obex_transport_sock_destroy(struct obex_sock *sock); socket_t obex_transport_sock_get_fd(struct obex_sock *sock); bool obex_transport_sock_set_local(struct obex_sock *sock, const struct sockaddr *addr, socklen_t len); bool obex_transport_sock_set_remote(struct obex_sock *sock, const struct sockaddr *addr, socklen_t len); bool obex_transport_sock_connect(struct obex_sock *sock); bool obex_transport_sock_listen(struct obex_sock *sock); struct obex_sock * obex_transport_sock_accept(struct obex_sock *sock); bool obex_transport_sock_disconnect(struct obex_sock *sock); ssize_t obex_transport_sock_send(struct obex_sock *sock, struct databuffer *msg, int64_t timeout); result_t obex_transport_sock_wait(struct obex_sock *sock, int64_t timeout); ssize_t obex_transport_sock_recv(struct obex_sock *sock, void *buf, int buflen); result_t obex_transport_sock_handle_input(struct obex_sock *sock, obex_t *self); #endif /* OBEX_TRANSPORT_SOCK_H */ openobex-1.7.2-Source/lib/nonblock.h000644 001750 001750 00000002245 12313536571 020445 0ustar00hendrikhendrik000000 000000 /** \file nonblock.h wrapper functions to enable/disable non-blocking OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2010 Hendrik Sattler, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #if defined(_WIN32) #include #else #include #endif static __inline void socket_set_nonblocking(socket_t fd) { #if defined(_WIN32) unsigned long val = 1; (void)ioctlsocket(fd, FIONBIO, &val); #else long status = fcntl(fd, F_GETFL); if (status == -1) status = 0; (void)fcntl(fd, F_SETFL, status | O_NONBLOCK); #endif } openobex-1.7.2-Source/lib/membuf.c000644 001750 001750 00000010671 12237700274 020106 0ustar00hendrikhendrik000000 000000 /** \file membuf.c Memory buffer handling routines. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2012 Hendrik Sattler, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #include "membuf.h" #include "databuffer.h" #include "debug.h" #include #include #include #include /* If an object has no expected length we have to reallocate every * ALLOCATION_TRESHOLD bytes */ #if defined _SC_PAGESIZE #define ALLOCATION_TRESHOLD (size_t)sysconf(_SC_PAGESIZE) #else #define ALLOCATION_TRESHOLD (size_t)4096 #endif struct membuf_data { uint8_t *buffer; size_t buffer_size; size_t offset; size_t data_len; }; static int membuf_set_size(void *self, size_t new_size) { struct membuf_data *p = self; uint8_t *tmp; new_size += p->offset; if (new_size == 0 && p->buffer == NULL) return 0; if (new_size == 0) { free(p->buffer); p->buffer = NULL; p->data_len = 0; p->buffer_size = 0; return 0; } tmp = realloc(p->buffer, new_size); if (!tmp) return -errno; p->buffer = tmp; p->buffer_size = new_size; if (p->buffer_size < (p->offset + p->data_len)) { p->data_len = p->buffer_size - p->offset; } else if (p->buffer_size > (p->offset + p->data_len)) { memset(p->buffer + (p->offset + p->data_len), 0, p->buffer_size - (p->offset + p->data_len)); } return 0; } static void *membuf_new(size_t default_size) { struct membuf_data *p; p = malloc(sizeof(*p)); if (!p) return NULL; p->buffer = NULL; p->buffer_size = 0; p->offset = 0; p->data_len = 0; if (membuf_set_size(p, default_size) < 0) { free(p); p = NULL; } return (void*)p; } static void membuf_delete(void *self) { struct membuf_data *p = self; if (!p) return; if (p->buffer) { free(p->buffer); } free(p); } static size_t membuf_get_offset(void *self) { struct membuf_data *p = self; if (!p) return 0; else return p->offset; } static void membuf_set_offset(void *self, size_t offset) { struct membuf_data *p = self; if (!p) return; p->data_len = (p->offset + p->data_len) - offset; p->offset = offset; } static size_t membuf_get_size(void *self) { struct membuf_data *p = self; if (!p) return 0; else return p->buffer_size - p->offset; } static size_t membuf_get_length(const void *self) { const struct membuf_data *p = self; if (!p) return 0; else return p->data_len; } static void* membuf_get(const void *self) { const struct membuf_data *p = self; if (!p) return NULL; else return p->buffer + p->offset; } static void membuf_clear(void *self, size_t len) { struct membuf_data *p = self; if (!p || !p->data_len) return; if (len < p->data_len) memmove(membuf_get(self), (uint8_t *)membuf_get(self)+len, p->data_len - len); p->data_len -= len; memset((uint8_t *)membuf_get(self) + p->data_len, 0, len); } static int membuf_append(void *self, const void *data, size_t len) { struct membuf_data *p = self; if (!p) return -EINVAL; DEBUG(4, "Request to append %lu bytes\n", (unsigned long)len); if (len > (p->buffer_size - (p->offset + p->data_len))) { size_t alloc_size = ALLOCATION_TRESHOLD; int ret; if (len > alloc_size) alloc_size = len; DEBUG(4, "Resizing buffer to %lu\n", (unsigned long)p->buffer_size + alloc_size); ret = membuf_set_size(self, p->buffer_size + alloc_size); if (ret < 0) { DEBUG(4, "Resizing failed\n"); return ret; } } if (data) { void *dest = ((uint8_t *)p->buffer) + (p->offset + p->data_len); memcpy(dest, data, len); } p->data_len += len; return 0; } static struct databuffer_ops membuf_ops = { &membuf_new, &membuf_delete, &membuf_get_offset, &membuf_set_offset, &membuf_get_size, &membuf_set_size, &membuf_get_length, &membuf_get, &membuf_clear, &membuf_append, }; struct databuffer *membuf_create(size_t default_size) { return buf_create(default_size, &membuf_ops); } openobex-1.7.2-Source/lib/obex.sym000644 001750 001750 00000001712 12110201112 020123 0ustar00hendrikhendrik000000 000000 OBEX_Init OBEX_Cleanup OBEX_SetUserData OBEX_GetUserData OBEX_SetUserCallBack OBEX_SetTransportMTU OBEX_GetFD OBEX_RegisterCTransport OBEX_SetCustomData OBEX_GetCustomData OBEX_TransportConnect OBEX_TransportDisconnect OBEX_CustomDataFeed OBEX_HandleInput OBEX_SetTimeout OBEX_Work OBEX_GetDataDirection OBEX_ServerRegister OBEX_ServerAccept OBEX_Request OBEX_CancelRequest OBEX_SuspendRequest OBEX_ResumeRequest OBEX_SetReponseMode OBEX_ObjectNew OBEX_ObjectDelete OBEX_ObjectGetSpace OBEX_ObjectAddHeader OBEX_ObjectGetNextHeader OBEX_ObjectReParseHeaders OBEX_ObjectSetRsp OBEX_ObjectGetNonHdrData OBEX_ObjectSetNonHdrData OBEX_ObjectSetHdrOffset OBEX_ObjectReadStream OBEX_ObjectGetCommand OBEX_ResponseToString TcpOBEX_ServerRegister TcpOBEX_TransportConnect IrOBEX_ServerRegister IrOBEX_TransportConnect BtOBEX_ServerRegister BtOBEX_TransportConnect FdOBEX_TransportSetup OBEX_InterfaceConnect OBEX_EnumerateInterfaces OBEX_GetInterfaceByIndex OBEX_FreeInterfaces openobex-1.7.2-Source/lib/obex_msg.c000644 001750 001750 00000013113 12604167677 020444 0ustar00hendrikhendrik000000 000000 /** * @file obex_msg.c * * Bridge between obex object and raw message buffer. * OpenOBEX library - Free implementation of the Object Exchange protocol. * * Copyright (c) 2012 Hendrik Sattler, All Rights Reserved. * * OpenOBEX is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the * Free Software Foundation; either version 2.1 of the License, or (at your * option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with OpenOBEX. If not, see . */ #include "obex_msg.h" #include "obex_main.h" #include "obex_object.h" #include "obex_hdr.h" #include "defines.h" static unsigned int obex_srm_tx_flags_decode (uint8_t flag) { switch (flag) { case 0x00: return OBEX_SRM_FLAG_WAIT_LOCAL; case 0x01: return OBEX_SRM_FLAG_WAIT_REMOTE; case 0x02: return (OBEX_SRM_FLAG_WAIT_LOCAL | OBEX_SRM_FLAG_WAIT_REMOTE); default: return 0; } } static unsigned int obex_srm_rx_flags_decode (uint8_t flag) { switch (flag) { case 0x00: return OBEX_SRM_FLAG_WAIT_REMOTE; case 0x01: return OBEX_SRM_FLAG_WAIT_LOCAL; case 0x02: return (OBEX_SRM_FLAG_WAIT_LOCAL | OBEX_SRM_FLAG_WAIT_REMOTE); default: return 0; } } static bool obex_msg_post_prepare(obex_t *self, obex_object_t *object, const struct obex_hdr_it *from, const struct obex_hdr_it *to) { struct obex_hdr_it it; struct obex_hdr *hdr; obex_hdr_it_init_from(&it, from); hdr = obex_hdr_it_get(&it); /* loop over all headers in that are non-NULL and finished... */ while (hdr != NULL && obex_hdr_is_finished(hdr)) { if (self->rsp_mode == OBEX_RSP_MODE_SINGLE && obex_hdr_get_id(hdr) == OBEX_HDR_ID_SRM_FLAGS) { const uint8_t *data = obex_hdr_get_data_ptr(hdr); self->srm_flags &= ~OBEX_SRM_FLAG_WAIT_REMOTE; self->srm_flags |= obex_srm_tx_flags_decode(data[0]); } /* ...but only in the range [from..to]. The last entry * must be included if it is finished. */ if (obex_hdr_it_equals(&it, to)) break; obex_hdr_it_next(&it); hdr = obex_hdr_it_get(&it); } return true; } bool obex_msg_prepare(obex_t *self, obex_object_t *object, bool allowfinal) { buf_t *txmsg = self->tx_msg; uint16_t tx_left = self->mtu_tx - sizeof(struct obex_common_hdr); int real_opcode; struct obex_hdr_it it; obex_hdr_it_init_from(&it, object->tx_it); if (!obex_data_request_init(self)) return false; if (!obex_object_append_data(object, txmsg, tx_left)) return false; real_opcode = obex_object_get_opcode(self->object, allowfinal, self->mode); DEBUG(4, "Generating packet with opcode %d\n", real_opcode); obex_data_request_prepare(self, real_opcode); return obex_msg_post_prepare(self, object, &it, object->tx_it); } int obex_msg_getspace(obex_t *self, obex_object_t *object, unsigned int flags) { size_t objlen = sizeof(struct obex_common_hdr); if (flags & OBEX_FL_FIT_ONE_PACKET) objlen += obex_object_get_size(object); return self->mtu_tx - objlen; } /** Check if the RX message buffer contains at least one full message. */ bool obex_msg_rx_status(const obex_t *self) { buf_t *msg = self->rx_msg; obex_common_hdr_t *hdr = buf_get(msg); return (buf_get_length(msg) >= sizeof(*hdr) && buf_get_length(msg) >= ntohs(hdr->len)); } /** Check if the TX message buffer was sent completely */ bool obex_msg_tx_status(const obex_t *self) { buf_t *msg = self->tx_msg; return (buf_get_length(msg) == 0); } int obex_msg_get_opcode(const obex_t *self) { buf_t *msg = self->rx_msg; obex_common_hdr_t *hdr = buf_get(msg); if (!obex_msg_rx_status(self)) return -1; return hdr->opcode; } size_t obex_msg_get_len(const obex_t *self) { buf_t *msg = self->rx_msg; obex_common_hdr_t *hdr; if (!obex_msg_rx_status(self)) return -1; hdr = buf_get(msg); return (size_t)ntohs(hdr->len); } void obex_msg_pre_receive(obex_t *self) { if (self->rsp_mode == OBEX_RSP_MODE_SINGLE) self->srm_flags &= ~OBEX_SRM_FLAG_WAIT_LOCAL; } int obex_msg_post_receive(obex_t *self) { obex_object_t *object = self->object; struct obex_hdr *hdr; if (!object->rx_it) return 0; /* loop over all new headers */ hdr = obex_hdr_it_get(object->rx_it); while (hdr != NULL) { if (self->rsp_mode == OBEX_RSP_MODE_SINGLE && obex_hdr_get_id(hdr) == OBEX_HDR_ID_SRM_FLAGS) { const uint8_t *data = obex_hdr_get_data_ptr(hdr); self->srm_flags |= obex_srm_rx_flags_decode(data[0]); } obex_hdr_it_next(object->rx_it); hdr = obex_hdr_it_get(object->rx_it); } return 0; } int obex_msg_receive_filtered(obex_t *self, obex_object_t *object, uint64_t filter, bool first_run) { buf_t *msg = self->rx_msg; size_t len; const uint8_t *data; int hlen; DEBUG(4, "\n"); if (!obex_msg_rx_status(self)) return 0; data = buf_get(msg); len = sizeof(struct obex_common_hdr); if (first_run) obex_msg_pre_receive(self); data += len; len = obex_msg_get_len(self) - len; if (first_run && len > 0) if (obex_object_receive_nonhdr_data(object, data, len) < 0) return -1; data += object->headeroffset; len -= object->headeroffset; if (len > 0) { hlen = obex_object_receive_headers(object, data, len, filter); if (hlen < 0) return hlen; } return obex_msg_post_receive(self); } int obex_msg_receive(obex_t *self, obex_object_t *object) { return obex_msg_receive_filtered(self, object, 0, TRUE); } openobex-1.7.2-Source/lib/CMakeLists.txt000644 001750 001750 00000015634 12701161355 021230 0ustar00hendrikhendrik000000 000000 # # Main library version and shared object version # # this defines supported properties that are set from # variables of the form openobex_* set ( openobex_PROPERTIES VERSION SOVERSION COMPILE_DEFINITIONS LINK_FLAGS ) # the ABI version, must be increased on incompatible changes set ( openobex_SOVERSION "2" ) set ( SOURCES api.c obex_client.c obex_connect.c obex_hdr.c obex_hdr_membuf.c obex_hdr_ptr.c obex_hdr_stream.c obex_body.c obex_main.c obex_msg.c obex_object.c obex_server.c obex_transport.c obex_transport_sock.c databuffer.c membuf.c transport/inobex.c transport/fdobex.c transport/customtrans.c ) include_directories ( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ) set ( HEADERS obex_client.h obex_connect.h obex_hdr.h obex_body.h obex_main.h obex_msg.h obex_object.h obex_server.h obex_transport.h databuffer.h membuf.h debug.h defines.h obex_incl.h cloexec.h nonblock.h transport/inobex.h transport/fdobex.h transport/customtrans.h ) if ( CMAKE_SYSTEM_NAME STREQUAL "Linux" ) # Activates some functions not defined without add_definitions ( -D_GNU_SOURCE ) endif ( CMAKE_SYSTEM_NAME STREQUAL "Linux" ) if ( NOT OBEX_DEBUG ) set ( OBEX_DEBUG 0 CACHE STRING "Amount of debug message (1-4)" ) endif ( NOT OBEX_DEBUG ) list ( APPEND openobex_COMPILE_DEFINITIONS OBEX_DEBUG=${OBEX_DEBUG} ) if ( NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" ) option ( OBEX_DEBUG_SYSLOG "Use SysLog facility instead of stderr for debug messages" ) if ( OBEX_DEBUG_SYSLOG ) list ( APPEND openobex_COMPILE_DEFINITIONS OBEX_DEBUG_SYSLOG ) endif ( OBEX_DEBUG_SYSLOG ) endif ( NOT CMAKE_SYSTEM_NAME STREQUAL "Windows" ) if ( NOT OBEX_DUMP ) set ( OBEX_DUMP 0 CACHE STRING "Tx/Rx message dump" ) endif ( NOT OBEX_DUMP ) list ( APPEND openobex_COMPILE_DEFINITIONS OBEX_DUMP=${OBEX_DUMP} ) if ( OPENOBEX_IRDA ) list ( APPEND SOURCES transport/irobex.c ) list ( APPEND HEADERS transport/irobex.h transport/irda_wrap.h ) endif ( OPENOBEX_IRDA ) if ( OPENOBEX_BLUETOOTH ) list ( APPEND SOURCES transport/btobex.c ) list ( APPEND HEADERS transport/btobex.h transport/bluez_compat.h ) endif ( OPENOBEX_BLUETOOTH ) if ( OPENOBEX_USB ) list ( APPEND openobex_LIBRARIES ${LibUSB_LIBRARIES} ) include_directories ( SYSTEM ${LibUSB_INCLUDE_DIRS} ) if ( LibUSB_VERSION_1.0 ) list ( APPEND SOURCES transport/usb1obex.c transport/usbutils.c ) else ( LibUSB_VERSION_1.0 ) list ( APPEND SOURCES transport/usbobex.c transport/usbutils.c ) endif ( LibUSB_VERSION_1.0 ) list ( APPEND HEADERS transport/usbobex.h transport/usbutils.h ) endif ( OPENOBEX_USB ) set ( openobex_LINK_FLAGS "${openobex_LINK_FLAGS} ${LINKER_FLAG_NOUNDEFINED}" ) if ( WIN32 ) if ( CMAKE_COMPILER_IS_GNUCC ) set ( openobex_LINK_FLAGS "${openobex_LINK_FLAGS} -Wl,--disable-stdcall-fixup -Wl,--add-stdcall-alias" ) endif ( CMAKE_COMPILER_IS_GNUCC ) list ( APPEND openobex_LIBRARIES ws2_32 ) if ( CMAKE_RC_COMPILER ) set ( OPENOBEX_RC_FILE "${CMAKE_CURRENT_BINARY_DIR}/openobex.rc" ) configure_file ( "${CMAKE_CURRENT_SOURCE_DIR}/openobex.rc.in" "${OPENOBEX_RC_FILE}" @ONLY ) endif ( CMAKE_RC_COMPILER ) if ( MSVC ) set ( OPENOBEX_DEF_FILE "${CMAKE_CURRENT_BINARY_DIR}/openobex.def" ) file ( WRITE "${OPENOBEX_DEF_FILE}" "VERSION ${openobex_VERSION_MAJOR}.${openobex_VERSION_MINOR}\n" ) file ( APPEND "${OPENOBEX_DEF_FILE}" "EXPORTS\n" ) file ( READ "${CMAKE_CURRENT_SOURCE_DIR}/obex.sym" OPENOBEX_SYMBOLS ) file ( APPEND "${OPENOBEX_DEF_FILE}" "${OPENOBEX_SYMBOLS}\n" ) # MSVC <= 7.1 needs some special tricks if ( MSVC_VERSION LESS "1400" ) list ( APPEND SOURCES win32compat.c ) endif ( MSVC_VERSION LESS "1400" ) endif ( MSVC ) endif ( WIN32 ) if ( CYGWIN ) #also define _WIN32 under CygWin list ( APPEND openobex_COMPILE_DEFINITIONS _WIN32) endif ( CYGWIN ) # Add the openobex library target add_library ( openobex ${SOURCES} ${HEADERS} ${openobex_PUBLIC_HEADERS} ${OPENOBEX_RC_FILE} ${OPENOBEX_DEF_FILE} ) target_link_libraries ( openobex PRIVATE ${openobex_LIBRARIES} ) foreach ( i ${openobex_PROPERTIES} ) if ( DEFINED openobex_${i} ) set_property ( TARGET openobex PROPERTY ${i} ${openobex_${i}} ) endif ( DEFINED openobex_${i} ) endforeach ( i ) generate_export_header( openobex ) install ( TARGETS openobex EXPORT openobex-target RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT library LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT library ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT devel ) # # Create the openobex-config file for the build tree # export ( TARGETS openobex FILE ${CMAKE_CURRENT_BINARY_DIR}/openobex-build.cmake ) configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/openobex-build-settings.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/openobex-build-settings.cmake @ONLY ) # # Create and copy the openobex-config.cmake files for the installed copy # set ( CMAKE_INSTALL_CMAKEBASEDIR ${CMAKE_INSTALL_LIBDIR}/cmake CACHE PATH "Where to install the cmake config files" ) file(RELATIVE_PATH CMAKE_INSTALL_REL_INCLUDEDIR ${CMAKE_INSTALL_FULL_LIBDIR}/cmake/OpenObex ${CMAKE_INSTALL_FULL_INCLUDEDIR} ) configure_file ( ${PROJECT_SOURCE_DIR}/openobex-config.cmake.in ${PROJECT_BINARY_DIR}/openobex-config.cmake @ONLY ) configure_file ( ${PROJECT_SOURCE_DIR}/openobex-config-version.cmake.in ${PROJECT_BINARY_DIR}/openobex-config-version.cmake @ONLY ) install ( FILES ${PROJECT_BINARY_DIR}/openobex-config.cmake ${PROJECT_BINARY_DIR}/openobex-config-version.cmake DESTINATION ${CMAKE_INSTALL_CMAKEBASEDIR}/OpenObex-${openobex_VERSION} COMPONENT devel ) install ( EXPORT openobex-target DESTINATION ${CMAKE_INSTALL_CMAKEBASEDIR}/OpenObex-${openobex_VERSION} COMPONENT devel ) # # Copy the .pc file to install it only if the lib gets installed # add_custom_command ( TARGET openobex COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${PROJECT_BINARY_DIR}/openobex.pc ${CMAKE_CURRENT_BINARY_DIR}/openobex.pc VERBATIM ) install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/openobex.pc DESTINATION ${PKGCONFIG_INSTALL_DIR} COMPONENT devel OPTIONAL ) # include ( GetPrerequisites ) # get_prerequisites ( openobex CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS 0 1 ) # By default, do not warn when built on machines using only VS Express: if ( NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ) set ( CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON ) endif ( NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ) include ( InstallRequiredSystemLibraries ) openobex-1.7.2-Source/lib/databuffer.c000644 001750 001750 00000007520 12604167677 020751 0ustar00hendrikhendrik000000 000000 /** \file databuffer.c Network buffer handling routines. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2005 Herton Ronaldo Krzesinski, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #include "databuffer.h" #include "obex_main.h" #include #include #include #include #include int slist_has_more(slist_t *list) { return (!slist_is_empty(list) && !slist_is_empty(list->next)); } void *slist_get(slist_t *list) { if (slist_is_empty(list)) return NULL; else return list->data; } slist_t *slist_append(slist_t *list, void *element) { slist_t *node, *p; node = malloc(sizeof(*node)); assert(node != NULL); node->data = element; node->next = NULL; if (!list) return node; p = list; while (p->next) p = p->next; p->next = node; return list; } slist_t *slist_remove(slist_t *list, void *element) { slist_t *prev, *next; if (!list) return NULL; prev = list; next = list; while (next != NULL) { if (next->data == element) { /* if first element, update list pointer */ if (next == list) { list = list->next; prev = list; free(next); next = prev; } else { prev->next = next->next; free(next); next = prev->next; } continue; } prev = next; next = next->next; } return list; } struct databuffer *buf_create(size_t default_size, struct databuffer_ops *ops) { struct databuffer *self = malloc(sizeof(*self)); if (!self) return NULL; self->ops = ops; self->ops_data = self->ops->new(default_size); if (!self->ops_data) { free(self); return NULL; } return self; } void buf_delete(struct databuffer *self) { if (self->ops->delete) self->ops->delete(self->ops_data); free(self); } size_t buf_get_offset(struct databuffer *self) { if (self->ops->get_offset) return self->ops->get_offset(self->ops_data); else return 0; } void buf_set_offset(struct databuffer *self, size_t offset) { if (self->ops->set_offset) self->ops->set_offset(self->ops_data, offset); } size_t buf_get_size(struct databuffer *self) { if (self->ops->get_size) return self->ops->get_size(self->ops_data); else return 0; } int buf_set_size(struct databuffer *self, size_t new_size) { if (self->ops->set_size) return self->ops->set_size(self->ops_data, new_size); else return 0; } size_t buf_get_length(const struct databuffer *self) { if (self->ops->get_length) return self->ops->get_length(self->ops_data); else return 0; } void *buf_get(const struct databuffer *self) { if (self->ops->get) return self->ops->get(self->ops_data); else return NULL; } void buf_clear(struct databuffer *self, size_t len) { if (self->ops->clear) self->ops->clear(self->ops_data, len); } int buf_append(struct databuffer *self, const void *data, size_t len) { if (self->ops->append) return self->ops->append(self->ops_data, data, len); else return -EINVAL; } void buf_dump(buf_t *p, const char *label) { unsigned int i, n; if (!p || !label) return; n = 0; for (i = 0; i < buf_get_length(p); ++i) { if (n == 0) log_debug("%s%s(%04x):", log_debug_prefix, label, i); log_debug(" %02X", *((uint8_t *)buf_get(p) + i)); if (n >= 0xF || i == buf_get_length(p) - 1) { log_debug("\n"); n = 0; } else n++; } } openobex-1.7.2-Source/lib/databuffer.h000644 001750 001750 00000004777 12604167677 020771 0ustar00hendrikhendrik000000 000000 /** \file databuffer.h Network buffer handling routines. OpenOBEX library - Free implementation of the Object Exchange protocol. Copyright (c) 2005 Herton Ronaldo Krzesinski, All Rights Reserved. OpenOBEX is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OpenOBEX. If not, see . */ #ifndef DATABUFFER_H #define DATABUFFER_H #define __need_size_t #include #include #include /* * Implements a single linked list */ struct databuffer_list { void *data; struct databuffer_list *next; }; typedef struct databuffer_list slist_t; /** This implements an abstracted data buffer. */ struct databuffer_ops { void* (*new)(size_t default_size); void (*delete)(void *self); size_t (*get_offset)(void *self); void (*set_offset)(void *self, size_t offset); size_t (*get_size)(void *self); int (*set_size)(void *self, size_t new_size); size_t (*get_length)(const void *self); void *(*get)(const void *self); void (*clear)(void *self, size_t len); int (*append)(void *self, const void *data, size_t len); }; struct databuffer { struct databuffer_ops *ops; void *ops_data; }; typedef struct databuffer buf_t; #include struct databuffer *buf_create(size_t default_size, struct databuffer_ops *ops); void buf_delete(struct databuffer *self); size_t buf_get_offset(struct databuffer *self); void buf_set_offset(struct databuffer *self, size_t offset); size_t buf_get_size(struct databuffer *self); int buf_set_size(struct databuffer *self, size_t new_size); size_t buf_get_length(const struct databuffer *self); void *buf_get(const struct databuffer *self); void buf_clear(struct databuffer *self, size_t len); int buf_append(struct databuffer *self, const void *data, size_t len); void buf_dump(buf_t *p, const char *label); #define slist_is_empty(l) ((l) == NULL) int slist_has_more(slist_t *list); void *slist_get(slist_t *list); slist_t *slist_append(slist_t *list, void *element); slist_t *slist_remove(slist_t *list, void *element); #endif openobex-1.7.2-Source/lib/defines.h000644 001750 001750 00000001456 12604167677 020272 0ustar00hendrikhendrik000000 000000 #ifndef OPENOBEX_DEFINES_H #define OPENOBEX_DEFINES_H #include #include #ifdef TRUE #undef TRUE #endif #define TRUE true #ifdef FALSE #undef FALSE #endif #define FALSE false enum result_type { RESULT_ERROR = -1, RESULT_TIMEOUT = 0, RESULT_SUCCESS = 1, }; typedef enum result_type result_t; #define obex_return_if_fail(test) \ do { if (!(test)) return; } while(0) #define obex_return_val_if_fail(test, val) \ do { if (!(test)) return val; } while(0) #define OBEX_VERSION 0x10 /* OBEX Protocol Version 1.1 */ enum obex_state { STATE_IDLE, STATE_REQUEST, STATE_RESPONSE, STATE_ABORT, }; enum obex_substate { SUBSTATE_RX, SUBSTATE_TX_PREPARE, SUBSTATE_TX, }; #define OBEX_SRM_FLAG_WAIT_LOCAL (1 << 0) #define OBEX_SRM_FLAG_WAIT_REMOTE (1 << 1) #endif openobex-1.7.2-Source/openobex.pc.in000644 001750 001750 00000000521 12701161546 020461 0ustar00hendrikhendrik000000 000000 prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: OpenOBEX Description: Free implementation of the Object Exchange protocol Version: @openobex_VERSION@ Requires.private: @REQUIRES@ Libs: -L${libdir} -lopenobex Libs.private: @LIBS_PRIVATE@ Cflags: -I${includedir} Cflags.private: @OPENOBEX_CFLAGS@ openobex-1.7.2-Source/udev/000755 001750 001750 00000000000 12701534273 016657 5ustar00hendrikhendrik000000 000000 openobex-1.7.2-Source/udev/openobex.rules.in000644 001750 001750 00000000315 11612777701 022163 0ustar00hendrikhendrik000000 000000 #udev script to make USB CDC devices with OBEX accessible to users ACTION=="add", SUBSYSTEM=="usb", PROGRAM="@prefix@/sbin/obex-check-device $attr{idVendor} $attr{idProduct}", MODE="660", GROUP="plugdev" openobex-1.7.2-Source/udev/CMakeLists.txt000644 001750 001750 00000002705 12701160572 021420 0ustar00hendrikhendrik000000 000000 if ( CMAKE_SYSTEM_NAME STREQUAL "Linux" AND OPENOBEX_USB ) add_executable ( obex-check-device obex-check-device.c ) target_link_libraries ( obex-check-device openobex ) install ( TARGETS obex-check-device DESTINATION ${CMAKE_INSTALL_SBINDIR} COMPONENT system ) # The udev rules file needs to be configured to have the right # path to obex-check-device. configure_file ( openobex.rules.in openobex.rules @ONLY ) # If there is a udev.pc pkg-config file in the system, use it. if (NOT CMAKE_INSTALL_UDEVRULESDIR) set ( UDEVDIR /lib/udev ) find_package ( PkgConfig ) if ( PKG_CONFIG_FOUND ) pkg_check_modules ( PKGCONFIG_UDEV udev ) if ( PKGCONFIG_UDEV_FOUND ) execute_process( COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=udevdir udev OUTPUT_VARIABLE PKGCONFIG_UDEVDIR OUTPUT_STRIP_TRAILING_WHITESPACE ) if ( PKGCONFIG_UDEVDIR ) file ( TO_CMAKE_PATH "${PKGCONFIG_UDEVDIR}" UDEVDIR ) endif ( PKGCONFIG_UDEVDIR ) endif ( PKGCONFIG_UDEV_FOUND ) endif ( PKG_CONFIG_FOUND ) endif (NOT CMAKE_INSTALL_UDEVRULESDIR) set ( CMAKE_INSTALL_UDEVRULESDIR ${UDEVDIR}/rules.d CACHE PATH "Where to install udev rules" ) mark_as_advanced ( CMAKE_INSTALL_UDEVRULESDIR ) install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/openobex.rules DESTINATION ${CMAKE_INSTALL_UDEVRULESDIR} COMPONENT system RENAME 60-openobex.rules ) endif ( CMAKE_SYSTEM_NAME STREQUAL "Linux" AND OPENOBEX_USB ) openobex-1.7.2-Source/udev/obex-check-device.c000644 001750 001750 00000003661 12701160572 022273 0ustar00hendrikhendrik000000 000000 /** \file apps/obex_find.c * Help udev to find connectable OBEX USB devices. * * Copyright (c) 2011 Hendrik Sattler * * OpenOBEX is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with OpenOBEX. If not, see . */ #include #include #include #include #include static void obex_event_cb(obex_t *handle, obex_object_t *obj, int mode, int event, int obex_cmd, int obex_rsp) { } static int match_usb_interface(obex_usb_intf_t *intf, uint16_t vendor, uint16_t product) { return (intf->idVendor == vendor && intf->idProduct == product); } static int find_usb_device(uint16_t vendor, uint16_t product) { obex_t *handle; int found; int matched = 0; int i = 0; handle = OBEX_Init(OBEX_TRANS_USB, obex_event_cb, 0); if (!handle) return 0; found = OBEX_EnumerateInterfaces(handle); for (; !matched && i < found; ++i) { obex_interface_t *intf = OBEX_GetInterfaceByIndex(handle, i); matched = match_usb_interface(&intf->usb, vendor, product); } OBEX_Cleanup(handle); return matched; } int main (int argc, char **argv) { unsigned long vendor; unsigned long product; if (argc < 2) return 0; vendor = strtoul(argv[1], NULL, 16); product = strtoul(argv[2], NULL, 16); if (vendor <= 0xFFFF && product <= 0xFFFF && find_usb_device((uint16_t)vendor, (uint16_t)product)) return EXIT_SUCCESS; return EXIT_FAILURE; } openobex-1.7.2-Source/README000644 001750 001750 00000000473 11731067320 016574 0ustar00hendrikhendrik000000 000000 OpenOBEX - Free implementation of the Object Exchange protocol ************************************************************** Information =========== Mailing lists: openobex-users@lists.sf.net - OpenOBEX discussions For additional information about the project visit OpenOBEX web site: http://www.openobex.org openobex-1.7.2-Source/openobex-config.cmake.in000644 001750 001750 00000001671 12114575776 022425 0ustar00hendrikhendrik000000 000000 # - Config file for the OpenObex package # It defines the following variables # OpenObex_INCLUDE_DIRS - include directories for FooBar # OpenObex_LIBRARIES - libraries to link against get_filename_component(OpenObex_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) if (EXISTS "${OpenObex_CMAKE_DIR}/lib/openobex-build.cmake") #in build tree include(${OpenObex_CMAKE_DIR}/lib/openobex-build.cmake) include(${OpenObex_CMAKE_DIR}/lib/openobex-build-settings.cmake) set(OpenObex_INCLUDE_DIRS ${OpenObex_CMAKE_DIR}/include ${OpenObex_SOURCE_DIR}/include ) else () #in installed tree include(${OpenObex_CMAKE_DIR}/openobex-target.cmake) set(OpenObex_CMAKE_REL_INCLUDE_DIR "@CMAKE_INSTALL_REL_INCLUDEDIR@") get_filename_component(OpenObex_ABS_INCLUDE_DIR "${OpenObex_CMAKE_DIR}/${OpenObex_CMAKE_REL_INCLUDE_DIR}" ABSOLUTE) set(OpenObex_INCLUDE_DIRS "${OpenObex_ABS_INCLUDE_DIR}") endif() set(OpenObex_LIBRARIES openobex) openobex-1.7.2-Source/UPGRADING.txt000644 001750 001750 00000002210 12126004431 017755 0ustar00hendrikhendrik000000 000000 Upgrade guide from previous version of openobex =============================================== Upgrading to version 1.7 ------------------------ When using an event loop that triggers on incoming data, you must call OBEX_HandleInput() after each call to OBEX_Request() to actually send the request. Upgrading to version 1.6 ------------------------ The function OBEX_UnicodeToAscii() and its counterpart OBEX_AsciiToUnicode() are gone. Please use the more complete functionality from your toolkit. If you use one of the functions InOBEX_ServerRegister() and InOBEX_TransportConnect(), please change to TcpOBEX_ServerRegister() and TcpOBEX_TransportConnect(). The functions OBEX_GetCustomData() and OBEX_SetCustomData() will really only work with OBEX_TRANS_CUSTOM. Also, obex_t and obex_object_t changed the declared type. If you pass it around, make sure to use them as pointer. To use the bluetooth function, include the bluetooth headers of your system before including openobex/obex.h or define bt_addr_t to the proper type. The function OBEX_FindInterfaces is replaced by the functions OBEX_EnumerateInterfaces() and OBEX_GetInterfaceByIndex(). openobex-1.7.2-Source/INSTALL_Win32.txt000644 001750 001750 00000005614 11753252545 020560 0ustar00hendrikhendrik000000 000000 How to compile OpenObex on Windows platform =========================================== You should read INSTALL.txt before continuing reading this file. 1 Requirements ============== The requirements to compile OpenObex on Windows are fairly low: 1. a compiler 2. the Platform SDK (now also called Windows SDK) 3. LibUSB-Win32[1] 4. CMake(>= 2.8.5)[2] The supported compilers are: * Microsoft Visual Studio 2010 (10) * Microsoft Visual Studio 2008 (9) * Microsoft Visual Studio 2005 (8) * Microsoft Visual Studio .NET 2003 (7.1) * MinGW gcc * Cygwin gcc Visual Studio 2008 and 2010 already include the SDK. [1]: at http://libusb-win32.sf.net (if not compiling for cygwin) [2]: at http://www.cmake.org 2 Compilation ============= Visual Studio ------------- Using Visual Studio >= 2008 (Express versions are sufficient) is the recommended way of compiling under Windows. You must open the console link that runs the proper vcvars.bat (see Start menu). Then, you _MUST_ add the directories of the platform SDK include files, libraries and executables to the environment variables INCLUDE, LIB and PATH. Now, your build environment is set up. You can now call cmake with the proper generator (see "cmake --help"). Using the "NMake Makefiles" generator, OpenObex can be compiled directly in the command prompt window: > mkdir build > cd build > cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release .. > nmake MinGW ----- Install MinGW, including core and mingw32-make, to e.g. C:\mingw. To get Bluetooth and Irda support, you must copy the following files from the Platform SDK include directory to usr/local/include in the MinGW installation directory: ws2bth.h bthdef.h bthsdpdef.h af_irda.h Either you add MinGW bin directory to PATH, or you call the mingw32-make with full path, both variations work. Then, at the command prompt: > set PATH=%PATH%;C:\mingw\bin > mkdir build > cd build > cmake -G"MinGW Makefiles" .. > mingw32-make You can also use MSYS as environment: > mkdir build > cd build > cmake -G"MSYS Makefiles" .. > make Cygwin ------ You must not use the Windows version of CMake but a version compiled specially for cygwin. You may also install cygwin version of libusb. Copy the same files as for the MinGW case to /usr/local/include. Then cou can run in the cygwin shell command window: $ mkdir build $ cd build $ cmake -G"Unix Makefiles" .. $ make 3 Installation ============== You can run the installation directly by calling the "install" make target. With the DESTDIR variable, you can add an additional prefix: $ make install DESTDIR=/some/directory Additionally, when you used CMake, you can create installation packages but a few steps are needed: * install NSIS * install a ZIP program (e.g. info-zip) Now you are ready to run the "package" make target. openobex-1.7.2-Source/CMakeLists.txt000644 001750 001750 00000014571 12701534214 020457 0ustar00hendrikhendrik000000 000000 cmake_minimum_required ( VERSION 3.1 FATAL_ERROR ) project ( openobex LANGUAGES C VERSION 1.7.2 ) # # The path for our own CMake modules # set ( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules ) # # Define the default build type # set ( CMAKE_CONFIGURATION_TYPES "Release;Debug" CACHE STRING "" FORCE ) if ( NOT CMAKE_BUILD_TYPE ) set ( CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE ) endif ( NOT CMAKE_BUILD_TYPE ) include ( MaintainerMode ) include ( GNUInstallDirs ) # This module currently expects C++ to be enabled in CMake-2.8.10. include ( GenerateExportHeader ) add_compiler_export_flags ( C ) # # define how to build libraries # option ( BUILD_SHARED_LIBS "Build shared libraries" ON ) # # check common compiler flags # include ( CheckCCompilerFlag ) if ( CMAKE_COMPILER_IS_GNUCC ) set ( LINKER_FLAG_NOUNDEFINED -Wl,--no-undefined ) check_c_compiler_flag ( "${LINKER_FLAG_NOUNDEFINED}" COMPILER_SUPPORT_NOUNDEFINED ) if ( NOT COMPILER_SUPPORT_NOUNDEFINED ) set ( LINKER_FLAG_NOUNDEFINED ) endif ( NOT COMPILER_SUPPORT_NOUNDEFINED ) endif ( CMAKE_COMPILER_IS_GNUCC ) if ( MSVC ) # Some compiler options for MSVC to not print non-sense warnings. add_definitions ( -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE ) endif ( MSVC ) # # which transports shall be included # find_package ( Bluetooth ) set ( OPENOBEX_BLUETOOTH_AVAILABLE ${Bluetooth_FOUND} ) find_package ( Irda ) set ( OPENOBEX_IRDA_AVAILABLE ${Irda_FOUND} ) find_package ( LibUSB ) set ( OPENOBEX_USB_AVAILABLE ${LibUSB_FOUND} ) foreach ( transport BLUETOOTH IRDA USB ) if ( OPENOBEX_${transport}_AVAILABLE ) set ( OPENOBEX_${transport} ON CACHE BOOL "Build with ${transport} support") else ( OPENOBEX_${transport}_AVAILABLE ) set ( OPENOBEX_${transport} OFF CACHE BOOL "Build with ${transport} support") endif ( OPENOBEX_${transport}_AVAILABLE ) endforeach ( transport ) if ( OPENOBEX_USB ) if ( LibUSB_VERSION_1.0 ) add_definitions ( -DHAVE_USB1 ) endif ( LibUSB_VERSION_1.0 ) add_definitions ( -DHAVE_USB ) endif ( OPENOBEX_USB ) if ( OPENOBEX_IRDA ) add_definitions ( -DHAVE_IRDA ) if ( WIN32 ) add_definitions ( -DHAVE_IRDA_WINDOWS ) else ( WIN32 ) string ( TOUPPER "HAVE_IRDA_${CMAKE_SYSTEM_NAME}" IRDA_SYSTEM_DEFINITION ) add_definitions ( -D${IRDA_SYSTEM_DEFINITION} ) endif ( WIN32 ) endif ( OPENOBEX_IRDA ) if ( OPENOBEX_BLUETOOTH ) add_definitions ( -DHAVE_BLUETOOTH ) if ( WIN32 ) add_definitions ( -DHAVE_BLUETOOTH_WINDOWS ) else ( WIN32 ) string ( TOUPPER "HAVE_BLUETOOTH_${CMAKE_SYSTEM_NAME}" BLUETOOTH_SYSTEM_DEFINITION ) add_definitions ( -D${BLUETOOTH_SYSTEM_DEFINITION} ) endif ( WIN32 ) endif ( OPENOBEX_BLUETOOTH ) # # create pkg-config files # these get copied and installed in the library dirs # TODO: those files should be moved to subdirs for each library # set ( prefix "${CMAKE_INSTALL_PREFIX}" ) set ( exec_prefix "\${prefix}" ) set ( libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}" ) set ( includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}" ) set ( top_srcdir "${CMAKE_SOURCE_DIR}" ) set ( top_builddir "${CMAKE_BINARY_DIR}" ) if ( OPENOBEX_BLUETOOTH AND UNIT AND NOT WIN32 ) foreach ( lib Bluetooth_LIBRARIES ) set ( LIBS_PRIVATE "${LIBS_PRIVATE} ${lib}" ) endforeach ( lib ) endif ( OPENOBEX_BLUETOOTH AND UNIT AND NOT WIN32 ) if ( OPENOBEX_USB AND UNIX AND NOT WIN32 ) if ( PKGCONFIG_LIBUSB_FOUND ) if ( LibUSB_VERSION_1.0 ) set ( REQUIRES "${REQUIRES} libusb-1.0" ) else ( LibUSB_VERSION_1.0 ) set ( REQUIRES "${REQUIRES} libusb" ) endif ( LibUSB_VERSION_1.0 ) else ( PKGCONFIG_LIBUSB_FOUND ) foreach ( lib LibUSB_LIBRARIES ) set ( LIBS_PRIVATE "${LIBS_PRIVATE} ${lib}" ) endforeach ( lib ) endif ( PKGCONFIG_LIBUSB_FOUND ) endif ( OPENOBEX_USB AND UNIX AND NOT WIN32 ) configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/openobex.pc.in ${CMAKE_CURRENT_BINARY_DIR}/openobex.pc @ONLY ) if ( NOT PKGCONFIG_INSTALL_DIR ) set ( PKGCONFIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}/pkgconfig CACHE PATH "Where to install .pc files to" FORCE ) endif ( NOT PKGCONFIG_INSTALL_DIR ) mark_as_advanced ( PKGCONFIG_INSTALL_DIR ) # # process include directory # set ( openobex_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" ) include_directories ( "${openobex_INCLUDE_DIRS}" ) add_subdirectory ( include/openobex ) if ( MSVC ) include_directories ( AFTER SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/include/msvc" ) endif ( MSVC ) # # build the main library # add_subdirectory ( lib ) link_directories ( "${CMAKE_CURRENT_BINARY_DIR}/lib" ) if ( BUILD_SHARED_LIBS ) add_definitions ( -DOPENOBEX_DLL ) endif ( BUILD_SHARED_LIBS ) option ( EXPORT_PACKAGE "Register build directory for find_package" OFF ) if ( EXPORT_PACKAGE ) export ( PACKAGE OpenObex ) endif ( EXPORT_PACKAGE ) # # build udev support # add_subdirectory ( udev ) # # build the applications # add_custom_target ( openobex-apps ) add_subdirectory ( apps ) # # build the documentation # option ( BUILD_DOCUMENTATION "Build library and application documentation" ON) if ( BUILD_DOCUMENTATION ) add_subdirectory ( doc ) endif ( BUILD_DOCUMENTATION ) # # The following adds CPack support # set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenObex" ) set ( CPACK_PACKAGE_VENDOR "The OpenObex Development Team" ) set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING.LIB" ) set ( CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README" ) set ( CPACK_PACKAGE_VERSION_MAJOR "${openobex_VERSION_MAJOR}" ) set ( CPACK_PACKAGE_VERSION_MINOR "${openobex_VERSION_MINOR}" ) set ( CPACK_PACKAGE_VERSION_PATCH "${openobex_VERSION_PATCH}" ) set ( CPACK_PACKAGE_VERSION "${openobex_VERSION}" ) if ( UNIX ) set ( CPACK_GENERATOR "TGZ" ) set ( CPACK_SOURCE_GENERATOR "TGZ" ) elseif ( WIN32 ) # # For NSIS, install from http://nsis.sf.net. # For ZIP, install e.g. info-zip from http://www.info-zip.org. # set ( CPACK_GENERATOR "ZIP;NSIS" ) set ( CPACK_SOURCE_GENERATOR "ZIP" ) endif ( UNIX ) set ( CPACK_SOURCE_IGNORE_FILES "/build/" "/\\\\.git/" "/\\\\.gitignore$" "~$" ) # this must _follow_ the settings! include ( CPack ) openobex-1.7.2-Source/ChangeLog000644 001750 001750 00000006646 12115446271 017501 0ustar00hendrikhendrik000000 000000 ver 1.7: Add support for CMake config files Internal code reorganisation and rewrite Add new function set for better control than OBEX_HandleInput(): * OBEX_SetTimeout(), * OBEX_Work() and * OBEX_GetDataDirection() ver 1.6: Change ABI from 1 to 2 because: * Redo the USB changes from version 1.4 * Remove InOBEX_* function, use the TcpOBEX_* functions instead * Remove the simple Unicode<->ASCII functions Add support for Single Response Mode Add manpages for all example applications Add udev support Add new example app to find IrDA and USB OBEX devices Add fixes for FreeBSD Add support for libusb-1.x Add support for close-on-exec ver 1.5: Revert USB changes that broke the ABI. Add more documentation and update manual pages. Add missing files to distribution. Fix obex_object_resume for server side role. Fix security issue when creating file. ver 1.4: Add OBEX_ObjectGetSpace function. Add OBEX_ObjectGetCommand function. Add Bluetooth support for FreeBSD and NetBSD. Add support for using OBEX over IPv6. Add support for Win32 platform. Fix support for document generation. Fix public visible symbols of the libraries. Fix handling of unexpected data from the server. Fix return value interpretation of obex_object_send. Fix obex_object_resume handling if sending fails. Allow suspending before the first packet has been sent. ver 1.3: Add support for setting the creation-ID. Updated constants to match IrOBEX 1.3. Replace netbuf implementation with databuffer. Fix segmentation fault when receiving invalid OBEX packets. ver 1.2: Add OBEX_EV_REQCHECK support. Add support for suspend after sending a header. Add support for empty headers for buggy OBEX servers. Fix memory leak in obex_object_send(). ver 1.1: Fix list of exported functions (Bug 644690). Fix duplicate string from basename() result (Bug 668977). Fix wrong order of sanity checks (Bug 703452). Fix memory leak in send_stream() function. ISO C99 says that inttypes.h includes stdint.h header. Add proper client side ABORT support. Add support for OBEX_SuspendRequest() and OBEX_ResumeRequest(). Add USB transport support. Increase the allowed maximum MTU to 64kB-1. Disconnect when an ABORT fails. Make it possible to include headers from C++ source code. Advertise OBEX Protocol Version 1.0. ver 1.0.1: Make OBEX_TRANS_BLUETOOTH working on Big-endian platform. Add COPYING.LIB for LGPL stuff. Don't auto generate openobex.spec file. ver 1.0.0: Make 1.0.0-pre5 the final release. ver 1.0.0-pre5: Add Bluetooth server support. Add OBEX_SetCustomData() and OBEX_GetCustomData(). Replace OBEX_GetResponseMessage() with OBEX_ResponseToString(). ver 1.0.0-pre4: Add Bluetooth client support. Change Bluetooth MTU to OBEX_DEFAULT_MTU. Change type of RFCOMM channel to uint8_t. Return static strings from obex_get_response_message(). Add OBEX_TRANS_FD support. ver 1.0.0-pre3: Fix workaround for Bluetooth support, again. Implement correct handling of OBEX_EV_REQDONE. Replace OBEX_TRANS_CUST with OBEX_TRANS_CUSTOM. Remove default prefix statement. Remove GLib dependencies. Change g_htons() into htons(). ver 1.0.0-pre2: Add support for DEBUG and DUMP. Add streaming support and push command. Disable IrDA discovery if a valid IrDA address is supplied. Fix workaround for compilation without Bluetooth support. ver 1.0.0-pre1: Support for Bluetooth transport layer. Handle unexpected data in continue. Allow higher MTUs. openobex-1.7.2-Source/INSTALL.txt000644 001750 001750 00000003066 11753252545 017575 0ustar00hendrikhendrik000000 000000 How to compile OpenObex ======================= The compilation of OpenObex is done using CMake. The following OBEX transports are available: * Bluetooth (not all systems, see below) * Irda (not all systems, see below) * TCP * USB * Custom transport * File descriptor The following operating systems are supported: * Linux [Bluetooth, Irda] * FreeBSD [Bluetooth] * NetBSD [Bluetooth] * Windows [Bluetooth(MS stack), Irda] Non-listed operating systems may still be supported. For Windows operating system, please see INSTALL_Win32.txt. 1 Requirements ============== 1. a C compiler (e.g. GCC) 2. LibUSB [1] 3. CMake(>= 2.8.5)[2] [1]: at http://libusb.sf.net [2]: at http://www.cmake.org 2 Compilation ============= It is recommended to not build in the source directory. To build in any other directory, just run cmake with the path to the source directory as last argument. A mix of this is a 'build' subdirectory in the source tree. The example below uses this method. At the command line, run: $ mkdir build $ cd build $ cmake .. $ make You can also use a substitute like cmake-gui or ccmake. Different build front-ends are also possible, the default are "Unix Makefiles". You might want to adjust the installation prefix by changing the CMAKE_INSTALL_PREFIX variable like, the default is /usr/local. 3 Installation ============== Then you can install the files by running the "install" make target. When using CMake, the "package" make target will create a compressed tarball with the binaries. openobex-1.7.2-Source/openobex-config-version.cmake.in000644 001750 001750 00000000271 12701166077 024073 0ustar00hendrikhendrik000000 000000 set ( PACKAGE_VERSION "@openobex_VERSION@" ) if ( PACKAGE_VERSION VERSION_EQUAL PACKAGE_FIND_VERSION) set ( PACKAGE_VERSION_EXACT 1 ) set ( PACKAGE_VERSION_COMPATIBLE 1 ) endif ()