summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJinkun Jang <jinkun.jang@samsung.com>2013-03-19 17:06:49 +0900
committerJinkun Jang <jinkun.jang@samsung.com>2013-03-19 17:06:49 +0900
commitf3071015148fc02ee2135ac071623f1dd350bdb3 (patch)
treebb52544e34c49b4e47f4c169e38c1f85a812870f
parent06e2dff413544d0e1465e0cb4897fe32e4de2c22 (diff)
downloadlibmedia-service-f3071015148fc02ee2135ac071623f1dd350bdb3.tar.gz
libmedia-service-f3071015148fc02ee2135ac071623f1dd350bdb3.tar.bz2
libmedia-service-f3071015148fc02ee2135ac071623f1dd350bdb3.zip
sync with tizen_2.0
-rw-r--r--AUTHORS2
-rwxr-xr-xCMakeLists.txt111
-rw-r--r--LICENSE733
-rwxr-xr-xLICENSE.APLv2.0201
-rw-r--r--LICENSE.BSD-style23
-rw-r--r--LICENSE.LGPLv2.1504
-rw-r--r--NOTICE13
-rwxr-xr-ximage/SLP_MediaSvc_PG_image001.pngbin0 -> 12349 bytes
-rwxr-xr-ximage/SLP_MediaSvc_PG_image002.pngbin0 -> 22406 bytes
-rwxr-xr-ximage/SLP_MusicSVC_PG_image001.pngbin0 -> 20214 bytes
-rwxr-xr-ximage/SLP_MusicSVC_PG_image002.pngbin0 -> 19401 bytes
-rwxr-xr-xinclude/media-svc-error.h89
-rwxr-xr-xinclude/media-svc-types.h53
-rwxr-xr-xinclude/media-svc.h247
-rw-r--r--libmedia-service.manifest6
-rwxr-xr-xlibmedia-service.pc.in13
-rw-r--r--md5/md5.c253
-rw-r--r--md5/md5.h39
-rwxr-xr-xmd5/media-svc-hash.c133
-rwxr-xr-xmd5/media-svc-hash.h24
-rwxr-xr-xpackaging/libmedia-service.spec73
-rwxr-xr-xplugin/media-content-plugin.c787
-rwxr-xr-xsrc/common/media-svc-album.c124
-rwxr-xr-xsrc/common/media-svc-db-utils.c692
-rwxr-xr-xsrc/common/media-svc-debug.c111
-rwxr-xr-xsrc/common/media-svc-media-folder.c146
-rwxr-xr-xsrc/common/media-svc-media.c667
-rwxr-xr-xsrc/common/media-svc-util.c1953
-rwxr-xr-xsrc/common/media-svc.c1084
-rwxr-xr-xsrc/include/common/media-svc-album.h32
-rwxr-xr-xsrc/include/common/media-svc-db-utils.h50
-rwxr-xr-xsrc/include/common/media-svc-debug.h96
-rwxr-xr-xsrc/include/common/media-svc-env.h204
-rwxr-xr-xsrc/include/common/media-svc-media-folder.h35
-rwxr-xr-xsrc/include/common/media-svc-media.h48
-rwxr-xr-xsrc/include/common/media-svc-util.h146
-rw-r--r--test/plugin/Makefile14
-rwxr-xr-xtest/plugin/media_svc_plugin_test.c234
-rw-r--r--uuid/clear.c43
-rw-r--r--uuid/compare.c55
-rw-r--r--uuid/copy.c45
-rw-r--r--uuid/gen_uuid.c672
-rw-r--r--uuid/isnull.c48
-rw-r--r--uuid/pack.c69
-rw-r--r--uuid/parse.c79
-rw-r--r--uuid/unpack.c63
-rw-r--r--uuid/unparse.c76
-rw-r--r--uuid/uuid.h103
-rw-r--r--uuid/uuidP.h66
-rw-r--r--uuid/uuid_time.c171
-rw-r--r--uuid/uuid_types.h50
-rw-r--r--uuid/uuidd.h54
52 files changed, 10534 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..677fb81
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,2 @@
+Haejeong Kim <backto.kim at samsung dot com>
+Hyunjun Ko <zzoon.ko at samsung dot com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100755
index 0000000..af7ccc4
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,111 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(media-service C)
+SET(VERSION_MAJOR 1)
+SET(VERSION "${VERSION_MAJOR}.0.0")
+
+SET(MEDIASERVICE-LIB "media-service")
+SET(MEDIASERVICE-HASH-LIB "media-svc-hash")
+SET(MEDIACONTENT-PLUGIN-LIB "media-content-plugin")
+SET(SRCS
+ uuid/clear.c
+ uuid/compare.c
+ uuid/copy.c
+ uuid/gen_uuid.c
+ uuid/isnull.c
+ uuid/pack.c
+ uuid/parse.c
+ uuid/unpack.c
+ uuid/unparse.c
+ uuid/uuid_time.c
+
+ src/common/media-svc.c
+ src/common/media-svc-media.c
+ src/common/media-svc-album.c
+ src/common/media-svc-media-folder.c
+ src/common/media-svc-db-utils.c
+ src/common/media-svc-util.c
+ src/common/media-svc-debug.c
+ )
+
+SET(HASH_SRCS
+ md5/md5.c
+ md5/media-svc-hash.c
+ )
+
+SET(PLUGIN_SRCS
+ plugin/media-svc-plugin.c
+ )
+SET(CONTENTPLUGIN_SRCS
+ plugin/media-content-plugin.c
+ )
+
+SET(VENDOR "samsung")
+SET(PACKAGE ${PROJECT_NAME})
+SET(PKGNAME "com.${VENDOR}.${PACKAGE}")
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(BINDIR "${PREFIX}/bin")
+SET(DATADIR "${PREFIX}/share")
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ SET(CMAKE_BUILD_TYPE "Release")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src/include/common ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/uuid ${CMAKE_SOURCE_DIR}/md5)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED glib-2.0 dlog sqlite3 db-util libexif mm-common mm-fileinfo drm-client media-thumbnail libmedia-utils aul)
+
+
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC")
+SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
+SET(CMAKE_C_FLAGS_RELEASE "-O2 -fPIC")
+
+FIND_PROGRAM(UNAME NAMES uname)
+EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
+IF("${ARCH}" STREQUAL "arm")
+ ADD_DEFINITIONS("-DTARGET")
+ MESSAGE("add -DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DVENDOR=\"${VENDOR}\"")
+ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"")
+ADD_DEFINITIONS("-DPACKAGE_NAME=\"${PKGNAME}\"")
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+ADD_DEFINITIONS("-D_FILE_OFFSET_BITS=64")
+#ADD_DEFINITIONS("-D_PERFORMANCE_CHECK_")
+#ADD_DEFINITIONS("-D_USE_LOG_FILE_")
+
+SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--hash-style=both")
+CONFIGURE_FILE(libmedia-service.pc.in libmedia-service.pc @ONLY)
+INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libmedia-service.pc DESTINATION lib/pkgconfig)
+
+LINK_DIRECTORIES(lib)
+
+ADD_LIBRARY(${MEDIASERVICE-HASH-LIB} SHARED ${HASH_SRCS})
+SET_TARGET_PROPERTIES(${MEDIASERVICE-HASH-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${MEDIASERVICE-HASH-LIB} PROPERTIES VERSION ${VERSION})
+ADD_LIBRARY(${MEDIASERVICE-LIB} SHARED ${SRCS})
+TARGET_LINK_LIBRARIES(${MEDIASERVICE-LIB} ${pkgs_LDFLAGS} ${MEDIASERVICE-HASH-LIB})
+SET_TARGET_PROPERTIES(${MEDIASERVICE-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${MEDIASERVICE-LIB} PROPERTIES VERSION ${VERSION})
+ADD_LIBRARY(${MEDIACONTENT-PLUGIN-LIB} SHARED ${CONTENTPLUGIN_SRCS})
+TARGET_LINK_LIBRARIES(${MEDIACONTENT-PLUGIN-LIB} ${MEDIASERVICE-LIB})
+SET_TARGET_PROPERTIES(${MEDIACONTENT-PLUGIN-LIB} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${MEDIACONTENT-PLUGIN-LIB} PROPERTIES VERSION ${VERSION})
+
+INSTALL(TARGETS ${MEDIASERVICE-LIB} LIBRARY DESTINATION lib)
+INSTALL(TARGETS ${MEDIASERVICE-HASH-LIB} LIBRARY DESTINATION lib)
+INSTALL(TARGETS ${MEDIACONTENT-PLUGIN-LIB} LIBRARY DESTINATION lib)
+
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-svc.h DESTINATION include/media-service/)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-svc-error.h DESTINATION include/media-service/)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/media-svc-types.h DESTINATION include/media-service/)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..51cfd5c
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,733 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
+ 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.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
+BSD-style
+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 names of the authors may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
+INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
+
diff --git a/LICENSE.APLv2.0 b/LICENSE.APLv2.0
new file mode 100755
index 0000000..261eeb9
--- /dev/null
+++ b/LICENSE.APLv2.0
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/LICENSE.BSD-style b/LICENSE.BSD-style
new file mode 100644
index 0000000..9894c14
--- /dev/null
+++ b/LICENSE.BSD-style
@@ -0,0 +1,23 @@
+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 names of the authors may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 JCRAFT,
+INC. OR ANY CONTRIBUTORS TO THIS SOFTWARE 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.
diff --git a/LICENSE.LGPLv2.1 b/LICENSE.LGPLv2.1
new file mode 100644
index 0000000..8add30a
--- /dev/null
+++ b/LICENSE.LGPLv2.1
@@ -0,0 +1,504 @@
+ 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.
+
+ <one line to give the library's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ 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.
+
+ <signature of Ty Coon>, 1 April 1990
+ Ty Coon, President of Vice
+
+That's all there is to it!
+
+
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..8bd60d4
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,13 @@
+Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
+Except as noted, this software is licensed under Apache License, Version 2.
+Please, see the LICENSE file for Apache License terms and conditions.
+
+Some parts of libmedia-service are licensed under the GNU Lesser General Public License version 2.1
+See the LICENSE file for LGPL License terms and conditions.
+Specifically, the LGPL parts of libmedia-service are
+ - md5/media-svc-hash.c
+
+Some parts of libmedia-service are licensed under BSD-style
+See the LICENSE file for BSD-style License terms and conditions.
+Specifically, the BSD-style parts of libmedia-service are
+ - uuid/
diff --git a/image/SLP_MediaSvc_PG_image001.png b/image/SLP_MediaSvc_PG_image001.png
new file mode 100755
index 0000000..d120338
--- /dev/null
+++ b/image/SLP_MediaSvc_PG_image001.png
Binary files differ
diff --git a/image/SLP_MediaSvc_PG_image002.png b/image/SLP_MediaSvc_PG_image002.png
new file mode 100755
index 0000000..5edce77
--- /dev/null
+++ b/image/SLP_MediaSvc_PG_image002.png
Binary files differ
diff --git a/image/SLP_MusicSVC_PG_image001.png b/image/SLP_MusicSVC_PG_image001.png
new file mode 100755
index 0000000..fbb7cc4
--- /dev/null
+++ b/image/SLP_MusicSVC_PG_image001.png
Binary files differ
diff --git a/image/SLP_MusicSVC_PG_image002.png b/image/SLP_MusicSVC_PG_image002.png
new file mode 100755
index 0000000..7d783be
--- /dev/null
+++ b/image/SLP_MusicSVC_PG_image002.png
Binary files differ
diff --git a/include/media-svc-error.h b/include/media-svc-error.h
new file mode 100755
index 0000000..ed28a53
--- /dev/null
+++ b/include/media-svc-error.h
@@ -0,0 +1,89 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+#ifndef _MEDIA_SVC_ERROR_H_
+#define _MEDIA_SVC_ERROR_H_
+
+/**
+ @addtogroup MEDIA_SVC
+ @{
+ * @file media-svc-error.h
+ * @brief This file defines error codes for media service.
+
+ */
+
+/**
+ @defgroup MEDIA_SVC_COMMON Global data structure and error code
+ @{
+
+ @par
+ type definition and error code
+ */
+
+
+#define MEDIA_INFO_ERROR_NONE 0 /**< No Error */
+
+#define MEDIA_INFO_ERROR_INVALID_PARAMETER -1 /**< Invalid parameter */
+#define MEDIA_INFO_ERROR_INVALID_MEDIA -2 /**< Invalid media */
+#define MEDIA_INFO_ERROR_INVALID_FILE_FORMAT -3 /**< Invalid file format */
+#define MEDIA_INFO_ERROR_INVALID_PATH -4 /**< Invalid file path */
+#define MEDIA_INFO_ERROR_OUT_OF_MEMORY -5 /**< Out of memory */
+#define MEDIA_INFO_ERROR_OUT_OF_STORAGE -6 /**< Out of storage */
+#define MEDIA_INFO_ERROR_INSERT_FAIL -7 /**< Insert failed */
+#define MEDIA_INFO_ERROR_DRM_INSERT_FAIL -8 /**< DRM file insert failed */
+
+#define MEDIA_INFO_ERROR_ITEM_NOT_FOUND -11 /**< Item not found */
+#define MEDIA_INFO_ERROR_FILE_NOT_FOUND -12 /**< File not found */
+#define MEDIA_INFO_ERROR_APPEND_ITEM_FAILED -13 /**< Append item failed */
+#define MEDIA_INFO_ERROR_REMOVE_ITEM_FAILED -14 /**< Remove item failed */
+#define MEDIA_INFO_ERROR_GET_ITEM_FAILED -15 /**< Get item failed */
+#define MEDIA_INFO_ERROR_REMOVE_FILE_FAILED -16 /**< Remove file failed */
+#define MEDIA_INFO_ERROR_EXTRACT_FAILED -17 /**< Extract Failed */
+#define MEDIA_INFO_ERROR_MAKE_PLAYLIST_NAME_FAILED -18 /**< fail to make new playlist name */
+
+#define MEDIA_INFO_ERROR_DATABASE_CONNECT -100 /**< DB connect error */
+#define MEDIA_INFO_ERROR_DATABASE_DISCONNECT -101 /**< DB disconnect error */
+#define MEDIA_INFO_ERROR_DATABASE_QUERY -104 /**< DB query error */
+#define MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN -105 /**< DB table open error */
+#define MEDIA_INFO_ERROR_DATABASE_INVALID -106 /**< DB invalid error */
+#define MEDIA_INFO_ERROR_DATABASE_INTERNAL -107 /**< DB internal error */
+#define MEDIA_INFO_ERROR_DATABASE_NO_RECORD -108 /**< Item not found in DB */
+
+#define MEDIA_INFO_ERROR_SOCKET_CONN -201 /**< Socket connect error */
+#define MEDIA_INFO_ERROR_SOCKET_MSG -202 /**< Socket message error */
+#define MEDIA_INFO_ERROR_SOCKET_SEND -203 /**< Socket send error */
+#define MEDIA_INFO_ERROR_SOCKET_RECEIVE -204 /**< Socket receive error */
+#define MEDIA_INFO_ERROR_SOCKET_RECEIVE_TIMEOUT -205 /**< Socket time out */
+
+#define MEDIA_INFO_ERROR_INTERNAL -998 /**< Internal error */
+#define MEDIA_INFO_ERROR_UNKNOWN -999 /**< Unknown error */
+#define MEDIA_INFO_ERROR_NOT_IMPLEMENTED -200 /**< Not implemented */
+/**
+ @}
+*/
+
+/**
+ @}
+*/
+
+#endif /*_MEDIA_SVC_ERROR_H_*/
diff --git a/include/media-svc-types.h b/include/media-svc-types.h
new file mode 100755
index 0000000..2f202ec
--- /dev/null
+++ b/include/media-svc-types.h
@@ -0,0 +1,53 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+#ifndef _MEDIA_SVC_TYPES_H_
+#define _MEDIA_SVC_TYPES_H_
+
+#ifndef DEPRECATED_API
+# define DEPRECATED_API __attribute__ ((deprecated))
+#endif
+
+typedef void MediaSvcHandle; /**< Handle */
+
+/**
+ * Type definition for storage type
+ */
+typedef enum{
+ MEDIA_SVC_STORAGE_INTERNAL, /**< Internal storage*/
+ MEDIA_SVC_STORAGE_EXTERNAL, /**< External storage*/
+ MEDIA_SVC_STORAGE_MAX, /**< Invalid storage*/
+}media_svc_storage_type_e;
+
+/**
+ * Type definition for content type
+ */
+typedef enum{
+ MEDIA_SVC_MEDIA_TYPE_IMAGE = 0, /**< Image Content*/
+ MEDIA_SVC_MEDIA_TYPE_VIDEO = 1, /**< Video Content*/
+ MEDIA_SVC_MEDIA_TYPE_SOUND = 2, /**< Sound Content like Ringtone*/
+ MEDIA_SVC_MEDIA_TYPE_MUSIC = 3, /**< Music Content like mp3*/
+ MEDIA_SVC_MEDIA_TYPE_OTHER = 4, /**< Invalid Content*/
+}media_svc_media_type_e;
+
+#endif /*_MEDIA_SVC_TYPES_H_*/
diff --git a/include/media-svc.h b/include/media-svc.h
new file mode 100755
index 0000000..1471d3d
--- /dev/null
+++ b/include/media-svc.h
@@ -0,0 +1,247 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+#ifndef _MEDIA_SVC_H_
+#define _MEDIA_SVC_H_
+
+#include "media-svc-types.h"
+#include "media-svc-error.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ @defgroup MEDIA_SVC Media Information Service
+ @{
+ * @file media-svc.h
+ * @brief This file defines API's for media service.
+ * @version 1.0
+ */
+
+/**
+ @defgroup MEDIA_SVC_API Media Database API
+ @{
+
+ @par
+ manage the service database.
+ */
+
+
+/**
+ * media_svc_connect:
+ * Connect to the media database. This is the function that an user who wants to get a handle to access the media database.
+ *
+ * @param handle [out] Handle to access database.
+ * @return This function returns zero(MEDIA_INFO_ERROR_NONE) on success, or negative value with error code.
+ * Please refer 'media-info-error.h' to know the exact meaning of the error.
+ * @see media_svc_disconnect
+ * @pre None
+ * @post call media_svc_disconnect to disconnect media database.
+ * @remark The database name is "/opt/usr/dbspace/.media.db".
+ * @par example
+ * @code
+
+#include <media-info.h>
+
+void connect_media_db()
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ MediaSvcHandle* my_handle = NULL;
+
+ // connect to the media database
+ ret = media_svc_connect(&my_handle);
+
+ if (ret < 0)
+ {
+ printf("Fatal error to connect DB\n");
+ return;
+ }
+
+ return;
+}
+
+ * @endcode
+ */
+int media_svc_connect(MediaSvcHandle **handle);
+
+
+/**
+ * media_svc_disconnect:
+ * Disconnect to the media database. This is the function that an user who wants to disconnect the media database.
+ *
+ * @param handle [in] Handle to access database.
+ * @return This function returns zero(MEDIA_INFO_ERROR_NONE) on success, or negative value with error code.
+ * Please refer 'media-info-error.h' to know the exact meaning of the error.
+ * @see media_svc_connect
+ * @pre call media_svc_connect to connect media database.
+ * @post None
+ * @remark The database name is "/opt/usr/dbspace/.media.db".
+ * @par example
+ * @code
+
+#include <media-info.h>
+
+void disconnect_media_db()
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ MediaSvcHandle* my_handle = NULL;
+
+ // connect to the media database
+ ret = media_svc_connect(&my_handle);
+
+ if (ret < 0)
+ {
+ printf("Fatal error to connect DB\n");
+ return;
+ }
+
+ //
+ // Do something using my_handle
+ //
+
+
+ ret = media_svc_disconnect(my_handle);
+ if (ret < 0)
+ {
+ printf("Fatal error to disconnect DB\n");
+ }
+
+ return;
+}
+
+ * @endcode
+ */
+int media_svc_disconnect(MediaSvcHandle *handle);
+
+
+/**
+ * media_svc_create_table:
+ * Create table of media database and set Index and Triggers.
+ *
+ * @param handle [in] Handle to access database.
+ * @return This function returns zero(MEDIA_INFO_ERROR_NONE) on success, or negative value with error code.
+ * Please refer 'media-info-error.h' to know the exact meaning of the error.
+ * @see None
+ * @pre call media_svc_connect to connect media database.
+ * @post call media_svc_disconnect to disconnect media database.
+ * @remark The database name is "/opt/usr/dbspace/.media.db".
+ * @par example
+ * @code
+
+#include <media-info.h>
+
+void create_media_db_table()
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ MediaSvcHandle* my_handle = NULL;
+
+ // connect to the media database
+ ret = media_svc_connect(&my_handle);
+
+ if (ret < 0)
+ {
+ printf("Fatal error to connect DB\n");
+ return;
+ }
+
+ ret = media_svc_create_table(my_handle);
+ if (ret < 0)
+ {
+ printf("Fatal error to create DB table\n");
+ }
+
+ ret = media_svc_disconnect(my_handle);
+ if (ret < 0)
+ {
+ printf("Fatal error to disconnect DB\n");
+ }
+
+ return;
+}
+
+ * @endcode
+ */
+
+int media_svc_create_table(MediaSvcHandle *handle);
+
+int media_svc_check_item_exist_by_path(MediaSvcHandle *handle, const char *path);
+
+int media_svc_insert_folder(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path);
+
+int media_svc_insert_item_begin(MediaSvcHandle *handle, int data_cnt);
+
+int media_svc_insert_item_end(MediaSvcHandle *handle);
+
+int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, const char *mime_type, media_svc_media_type_e media_type);
+
+int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, const char *mime_type, media_svc_media_type_e media_type);
+
+int media_svc_move_item_begin(MediaSvcHandle *handle, int data_cnt);
+
+int media_svc_move_item_end(MediaSvcHandle *handle);
+
+int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_storage, const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path);
+
+int media_svc_set_item_validity_begin(MediaSvcHandle *handle, int data_cnt);
+
+int media_svc_set_item_validity_end(MediaSvcHandle *handle);
+
+int media_svc_set_item_validity(MediaSvcHandle *handle, const char *path, int validity);
+
+int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *path);
+
+int media_svc_delete_all_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type);
+
+int media_svc_delete_invalid_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type);
+
+int media_svc_delete_invalid_items_in_folder(MediaSvcHandle *handle, const char *folder_path);
+
+int media_svc_set_all_storage_items_validity(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, int validity);
+
+int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *folder_path, int validity, int recursive);
+
+int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, media_svc_media_type_e media_type);
+
+int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const char *dst_path);
+
+int media_svc_request_update_db(const char *db_query);
+
+int media_svc_get_storage_type(const char *path, media_svc_storage_type_e *storage_type);
+
+int media_svc_get_mime_type(const char *path, char *mimetype);
+
+int media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type);
+
+/** @} */
+
+/**
+ @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_MEDIA_SVC_H_*/
diff --git a/libmedia-service.manifest b/libmedia-service.manifest
new file mode 100644
index 0000000..ca37499
--- /dev/null
+++ b/libmedia-service.manifest
@@ -0,0 +1,6 @@
+<manifest>
+ <request>
+ <domain name="_" />
+ </request>
+</manifest>
+
diff --git a/libmedia-service.pc.in b/libmedia-service.pc.in
new file mode 100755
index 0000000..978a9c9
--- /dev/null
+++ b/libmedia-service.pc.in
@@ -0,0 +1,13 @@
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIBDIR@
+includedir=@INCLUDEDIR@
+
+Name: @PROJECT_NAME@
+Description: Samsung Linux platform @PROJECT_NAME@ library
+Version: @VERSION@
+Requires: glib-2.0 dlog sqlite3 db-util mm-common
+Libs: -L${libdir} -lmedia-service -lmedia-svc-hash
+Cflags: -I${includedir}/media-service
diff --git a/md5/md5.c b/md5/md5.c
new file mode 100644
index 0000000..59b47ba
--- /dev/null
+++ b/md5/md5.c
@@ -0,0 +1,253 @@
+/*
+ * This code implements the MD5 message-digest algorithm.
+ * The algorithm is due to Ron Rivest. This code was
+ * written by Colin Plumb in 1993, no copyright is claimed.
+ * This code is in the public domain; do with it what you wish.
+ *
+ * Equivalent code is available from RSA Data Security, Inc.
+ * This code has been tested against that, and is equivalent,
+ * except that you don't need to include two pages of legalese
+ * with every copy.
+ *
+ * To compute the message digest of a chunk of bytes, declare an
+ * MD5Context structure, pass it to MD5Init, call MD5Update as
+ * needed on buffers full of bytes, and then call MD5Final, which
+ * will fill a supplied 16-byte array with the digest.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h> /* for memcpy() */
+#include "md5.h"
+
+#if (__BYTE_ORDER == 1234)
+#define byteReverse(buf, len) /* Nothing */
+#else
+void byteReverse(unsigned char *buf, unsigned longs);
+
+/*
+ * Note: this code is harmless on little-endian machines.
+ */
+void byteReverse(unsigned char *buf, unsigned longs)
+{
+ uint32_t t;
+ do {
+ t = (uint32_t) ((unsigned)buf[3] << 8 | buf[2]) << 16 |
+ ((unsigned)buf[1] << 8 | buf[0]);
+ *(uint32_t *) buf = t;
+ buf += 4;
+ } while (--longs);
+}
+#endif
+
+/*
+ * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
+ * initialization constants.
+ */
+void MD5Init(MD5_CTX *ctx)
+{
+ ctx->buf[0] = 0x67452301;
+ ctx->buf[1] = 0xefcdab89;
+ ctx->buf[2] = 0x98badcfe;
+ ctx->buf[3] = 0x10325476;
+
+ ctx->bits[0] = 0;
+ ctx->bits[1] = 0;
+}
+
+/*
+ * Update context to reflect the concatenation of another buffer full
+ * of bytes.
+ */
+void MD5Update(MD5_CTX *ctx, unsigned char const *buf, unsigned len)
+{
+ uint32_t t;
+
+ /* Update bitcount */
+
+ t = ctx->bits[0];
+ if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t) {
+ ctx->bits[1]++; /* Carry from low to high */
+ }
+
+ ctx->bits[1] += len >> 29;
+
+ t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
+
+ /* Handle any leading odd-sized chunks */
+
+ if (t) {
+ unsigned char *p = (unsigned char *)ctx->in + t;
+
+ t = 64 - t;
+ if (len < t) {
+ memcpy(p, buf, len);
+ return;
+ }
+ memcpy(p, buf, t);
+ byteReverse(ctx->in, 16);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ buf += t;
+ len -= t;
+ }
+ /* Process data in 64-byte chunks */
+
+ while (len >= 64) {
+ memcpy(ctx->in, buf, 64);
+ byteReverse(ctx->in, 16);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ buf += 64;
+ len -= 64;
+ }
+
+ /* Handle any remaining bytes of data. */
+
+ memcpy(ctx->in, buf, len);
+}
+
+/*
+ * Final wrapup - pad to 64-byte boundary with the bit pattern
+ * 1 0* (64-bit count of bits processed, MSB-first)
+ */
+void MD5Final(unsigned char digest[16], MD5_CTX *ctx)
+{
+ unsigned count;
+ unsigned char *p;
+
+ /* Compute number of bytes mod 64 */
+ count = (ctx->bits[0] >> 3) & 0x3F;
+
+ /* Set the first char of padding to 0x80. This is safe since there is
+ always at least one byte free */
+ p = ctx->in + count;
+ *p++ = 0x80;
+
+ /* Bytes of padding needed to make 64 bytes */
+ count = 64 - 1 - count;
+
+ /* Pad out to 56 mod 64 */
+ if (count < 8) {
+ /* Two lots of padding: Pad the first block to 64 bytes */
+ memset(p, 0, count);
+ byteReverse(ctx->in, 16);
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+
+ /* Now fill the next block with 56 bytes */
+ memset(ctx->in, 0, 56);
+ } else {
+ /* Pad block to 56 bytes */
+ memset(p, 0, count - 8);
+ }
+ byteReverse(ctx->in, 14);
+
+ /* Append length in bits and transform */
+ ((uint32_t *) ctx->in)[14] = ctx->bits[0];
+ ((uint32_t *) ctx->in)[15] = ctx->bits[1];
+
+ MD5Transform(ctx->buf, (uint32_t *) ctx->in);
+ byteReverse((unsigned char *)ctx->buf, 4);
+ memcpy(digest, ctx->buf, 16);
+ memset((char *)ctx, 0, sizeof(ctx)); /* In case it's sensitive */
+}
+
+/* The four core functions - F1 is optimized somewhat */
+
+/* #define F1(x, y, z) (x & y | ~x & z) */
+#define F1(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
+#define F2(x, y, z) (F1((z), (x), (y)))
+#define F3(x, y, z) ((x) ^ (y) ^ (z))
+#define F4(x, y, z) ((y) ^ ((x) | ~(z)))
+
+/* This is the central step in the MD5 algorithm. */
+#define MD5STEP(f, w, x, y, z, data, s) \
+(w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x)
+
+/*
+ * The core of the MD5 algorithm, this alters an existing MD5 hash to
+ * reflect the addition of 16 longwords of new data. MD5Update blocks
+ * the data and converts bytes into longwords for this routine.
+ */
+void MD5Transform(uint32_t buf[4], uint32_t const in[16])
+{
+ register uint32_t a, b, c, d;
+
+ a = buf[0];
+ b = buf[1];
+ c = buf[2];
+ d = buf[3];
+
+ MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
+ MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
+ MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
+ MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
+ MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
+ MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
+ MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
+ MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
+ MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
+ MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
+ MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
+ MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
+ MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
+ MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
+ MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
+ MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
+
+ MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
+ MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
+ MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
+ MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
+ MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
+ MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
+ MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
+ MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
+ MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
+ MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
+ MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
+ MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
+ MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
+ MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
+ MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
+ MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
+
+ MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
+ MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
+ MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
+ MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
+ MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
+ MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
+ MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
+ MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
+ MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
+ MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
+ MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
+ MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
+ MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
+ MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
+ MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
+ MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
+
+ MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
+ MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
+ MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
+ MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
+ MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
+ MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
+ MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
+ MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
+ MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
+ MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
+ MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
+ MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
+ MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
+ MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
+ MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
+ MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
+
+ buf[0] += a;
+ buf[1] += b;
+ buf[2] += c;
+ buf[3] += d;
+}
diff --git a/md5/md5.h b/md5/md5.h
new file mode 100644
index 0000000..dac53fb
--- /dev/null
+++ b/md5/md5.h
@@ -0,0 +1,39 @@
+/*
+ * This code implements the MD5 message-digest algorithm.
+ * The algorithm is due to Ron Rivest. This code was
+ * written by Colin Plumb in 1993, no copyright is claimed.
+ * This code is in the public domain; do with it what you wish.
+ *
+ * Equivalent code is available from RSA Data Security, Inc.
+ * This code has been tested against that, and is equivalent,
+ * except that you don't need to include two pages of legalese
+ * with every copy.
+ *
+ * To compute the message digest of a chunk of bytes, declare an
+ * MD5Context structure, pass it to MD5Init, call MD5Update as
+ * needed on buffers full of bytes, and then call MD5Final, which
+ * will fill a supplied 16-byte array with the digest.
+ */
+
+
+#ifndef _MD5_H_
+#define _MD5_H_
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#define MD5_HASHBYTES 16
+
+typedef struct MD5Context {
+ uint32_t buf[4];
+ uint32_t bits[2];
+ unsigned char in[64];
+} MD5_CTX;
+
+extern void MD5Init(MD5_CTX *context);
+extern void MD5Update(MD5_CTX *context,unsigned char const *buf,unsigned len);
+extern void MD5Final(unsigned char digest[MD5_HASHBYTES], MD5_CTX *context);
+
+extern void MD5Transform(uint32_t buf[4], uint32_t const in[16]);
+
+#endif
diff --git a/md5/media-svc-hash.c b/md5/media-svc-hash.c
new file mode 100755
index 0000000..ae8209d
--- /dev/null
+++ b/md5/media-svc-hash.c
@@ -0,0 +1,133 @@
+/* GLIB - Library of useful routines for C programming
+ *
+ * gconvert.c: Convert between character sets using iconv
+ * Copyright Red Hat Inc., 2000
+ * Authors: Havoc Pennington <hp@redhat.com>, Owen Taylor <otaylor@redhat.com
+ *
+ * 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 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/* The array below is taken from gconvert.c, which is licensed by GNU Lesser General Public License
+ * Code to escape string is also taken partially from gconvert.c
+ * File name is changed to media-svc-hash.c
+ */
+
+#include "md5.h"
+#include <string.h>
+#include <alloca.h>
+#include "media-svc-hash.h"
+#include "media-svc-error.h"
+
+
+static const char ACCEPTABLE_URI_CHARS[96] = {
+ /* ! " # $ % & ' ( ) * + , - . / */
+ 0x00, 0x3F, 0x20, 0x20, 0x28, 0x00, 0x2C, 0x3F, 0x3F, 0x3F, 0x3F, 0x2A,
+ 0x28, 0x3F, 0x3F, 0x1C,
+ /* 0 1 2 3 4 5 6 7 8 9 : ; < = > ? */
+ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x38, 0x20,
+ 0x20, 0x2C, 0x20, 0x20,
+ /* @ A B C D E F G H I J K L M N O */
+ 0x38, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
+ 0x3F, 0x3F, 0x3F, 0x3F,
+ /* P Q R S T U V W X Y Z [ \ ] ^ _ */
+ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20,
+ 0x20, 0x20, 0x20, 0x3F,
+ /* ` a b c d e f g h i j k l m n o */
+ 0x20, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
+ 0x3F, 0x3F, 0x3F, 0x3F,
+ /* p q r s t u v w x y z { | } ~ DEL */
+ 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x20,
+ 0x20, 0x20, 0x3F, 0x20
+};
+
+char *_mb_svc_generate_hash_name(const char *file)
+{
+ int n;
+ MD5_CTX ctx;
+ static char md5out[(2 * MD5_HASHBYTES) + 1];
+ unsigned char hash[MD5_HASHBYTES];
+ static const char hex[] = "0123456789abcdef";
+
+ char *uri;
+ char *t;
+ const unsigned char *c;
+ int length;
+
+ if (!file) {
+ return NULL;
+ }
+
+ length = 3 * strlen(file) + 9;
+
+ memset(md5out, 0, sizeof(md5out));
+
+#define _check_uri_char(c) \
+((c) >= 32 && (c) < 128 && (ACCEPTABLE_URI_CHARS[(c) - 32] & 0x08))
+
+ uri = alloca(length);
+ if (uri == NULL) {
+ return NULL;
+ }
+
+ strncpy(uri, "file://", length);
+ uri[length - 1] = '\0';
+ t = uri + sizeof("file://") - 1;
+
+ for (c = (const unsigned char *)file; *c != '\0'; c++) {
+ if (!_check_uri_char(*c)) {
+ *t++ = '%';
+ *t++ = hex[*c >> 4];
+ *t++ = hex[*c & 15];
+ } else {
+ *t++ = *c;
+ }
+ }
+ *t = '\0';
+#undef _check_uri_char
+
+ MD5Init(&ctx);
+ MD5Update(&ctx, (unsigned char const *)uri, (unsigned)strlen(uri));
+ MD5Final(hash, &ctx);
+
+ for (n = 0; n < MD5_HASHBYTES; n++) {
+ md5out[2 * n] = hex[hash[n] >> 4];
+ md5out[2 * n + 1] = hex[hash[n] & 0x0f];
+ }
+ md5out[2 * n] = '\0';
+
+ return md5out;
+}
+
+int mb_svc_generate_hash_code(const char *origin_path, char *hash_code, int max_length)
+{
+ char *hash = NULL;
+
+ if (max_length < ((2 * MD5_HASHBYTES) + 1)) {
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ hash = _mb_svc_generate_hash_name(origin_path);
+
+ if (hash == NULL) {
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ strncpy(hash_code, hash, max_length);
+ hash_code[strlen(hash_code)] ='\0';
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
diff --git a/md5/media-svc-hash.h b/md5/media-svc-hash.h
new file mode 100755
index 0000000..3aedc65
--- /dev/null
+++ b/md5/media-svc-hash.h
@@ -0,0 +1,24 @@
+/*
+ * 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 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., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _MEDIA_SVC_HASH_
+#define _MEDIA_SVC_HASH_
+
+int mb_svc_generate_hash_code(const char *origin_path, char *hash_code, int max_length);
+
+#endif /*MEDIA_SVC_HASH_*/
+
diff --git a/packaging/libmedia-service.spec b/packaging/libmedia-service.spec
new file mode 100755
index 0000000..38ec448
--- /dev/null
+++ b/packaging/libmedia-service.spec
@@ -0,0 +1,73 @@
+Name: libmedia-service
+Summary: Media information service library for multimedia applications.
+Version: 0.2.19
+Release: 1
+Group: System/Libraries
+License: Apache License, Version 2.0
+Source0: %{name}-%{version}.tar.gz
+
+Requires(post): /sbin/ldconfig
+Requires(postun): /sbin/ldconfig
+
+BuildRequires: cmake
+BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(aul)
+BuildRequires: pkgconfig(libexif)
+BuildRequires: pkgconfig(mm-common)
+BuildRequires: pkgconfig(sqlite3)
+BuildRequires: pkgconfig(db-util)
+BuildRequires: pkgconfig(mm-fileinfo)
+BuildRequires: pkgconfig(media-thumbnail)
+BuildRequires: pkgconfig(drm-client)
+BuildRequires: pkgconfig(libmedia-utils)
+
+%description
+Media information service library for multimedia applications.
+
+%package devel
+Summary: Media information service library for multimedia applications. (development)
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+Media information service library for multimedia applications. (development files)
+
+
+%prep
+%setup -q
+
+
+%build
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix}
+make %{?jobs:-j%jobs}
+
+%install
+rm -rf %{buildroot}
+%make_install
+
+#License
+mkdir -p %{buildroot}/%{_datadir}/license
+cp -rf %{_builddir}/%{name}-%{version}/LICENSE %{buildroot}/%{_datadir}/license/%{name}
+
+%post -p /sbin/ldconfig
+%postun -p /sbin/ldconfig
+
+%files
+%manifest libmedia-service.manifest
+%defattr(-,root,root,-)
+%{_libdir}/libmedia-service.so
+%{_libdir}/libmedia-service.so.1
+%{_libdir}/libmedia-service.so.1.0.0
+%{_libdir}/libmedia-svc-hash.so
+%{_libdir}/libmedia-svc-hash.so.1
+%{_libdir}/libmedia-svc-hash.so.1.0.0
+%{_libdir}/libmedia-content-plugin.so
+%{_libdir}/libmedia-content-plugin.so.1
+%{_libdir}/libmedia-content-plugin.so.1.0.0
+#License
+%{_datadir}/license/%{name}
+
+%files devel
+%{_libdir}/pkgconfig/libmedia-service.pc
+%{_includedir}/media-service/*.h
diff --git a/plugin/media-content-plugin.c b/plugin/media-content-plugin.c
new file mode 100755
index 0000000..97f59f7
--- /dev/null
+++ b/plugin/media-content-plugin.c
@@ -0,0 +1,787 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <string.h>
+#include <mm_file.h>
+#include <media-thumbnail.h>
+#include "media-svc.h"
+
+#define MEDIA_SVC_PLUGIN_ERROR_NONE 0
+#define MEDIA_SVC_PLUGIN_ERROR -1
+
+#define STRING_VALID(str) \
+ ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
+#define STORAGE_VALID(storage)\
+ (((storage == MEDIA_SVC_STORAGE_INTERNAL) || (storage == MEDIA_SVC_STORAGE_EXTERNAL)) ? TRUE : FALSE)
+
+
+typedef enum{
+ ERR_HANDLE = 1,
+ ERR_FILE_PATH,
+ ERR_FOLDER_PATH,
+ ERR_MIME_TYPE,
+ ERR_NOT_MEDIAFILE,
+ ERR_STORAGE_TYPE,
+ ERR_CHECK_ITEM,
+ ERR_MAX,
+}media_svc_error_type_e;
+
+#define MS_CATEGORY_UNKNOWN 0x00000000 /**< Default */
+#define MS_CATEGORY_ETC 0x00000001 /**< ETC category */
+#define MS_CATEGORY_IMAGE 0x00000002 /**< Image category */
+#define MS_CATEGORY_VIDEO 0x00000004 /**< Video category */
+#define MS_CATEGORY_MUSIC 0x00000008 /**< Music category */
+#define MS_CATEGORY_SOUND 0x00000010 /**< Sound category */
+
+#define CONTENT_TYPE_NUM 4
+#define MUSIC_MIME_NUM 29
+#define SOUND_MIME_NUM 1
+#define MIME_TYPE_LENGTH 255
+#define MIME_LENGTH 50
+#define _3GP_FILE ".3gp"
+#define _MP4_FILE ".mp4"
+
+
+typedef struct {
+ char content_type[15];
+ int category_by_mime;
+} fex_content_table_t;
+
+static const fex_content_table_t content_category[CONTENT_TYPE_NUM] = {
+ {"audio", MS_CATEGORY_SOUND},
+ {"image", MS_CATEGORY_IMAGE},
+ {"video", MS_CATEGORY_VIDEO},
+ {"application", MS_CATEGORY_ETC},
+};
+
+static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
+ /*known mime types of normal files*/
+ "mpeg",
+ "ogg",
+ "x-ms-wma",
+ "x-flac",
+ "mp4",
+ /* known mime types of drm files*/
+ "mp3",
+ "x-mp3", /*alias of audio/mpeg*/
+ "x-mpeg", /*alias of audio/mpeg*/
+ "3gpp",
+ "x-ogg", /*alias of audio/ogg*/
+ "vnd.ms-playready.media.pya:*.pya", /*playready*/
+ "wma",
+ "aac",
+ "x-m4a", /*alias of audio/mp4*/
+ /* below mimes are rare*/
+ "x-vorbis+ogg",
+ "x-flac+ogg",
+ "x-matroska",
+ "ac3",
+ "mp2",
+ "x-ape",
+ "x-ms-asx",
+ "vnd.rn-realaudio",
+
+ "x-vorbis", /*alias of audio/x-vorbis+ogg*/
+ "vorbis", /*alias of audio/x-vorbis+ogg*/
+ "x-oggflac",
+ "x-mp2", /*alias of audio/mp2*/
+ "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
+ "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
+ "x-wav",
+};
+
+static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
+ "x-smaf",
+};
+
+static int __get_content_type_from_mime(const char * path, const char * mimetype, int * category);
+static int __get_content_type(const char * file_path, const char * mime_type);
+static void __set_error_message(int err_type, char ** err_msg);
+
+static int __get_content_type_from_mime(const char * path, const char * mimetype, int * category)
+{
+ int i = 0;
+ int err = 0;
+
+ *category = MS_CATEGORY_UNKNOWN;
+
+ //MS_DBG("mime type : %s", mimetype);
+
+ /*categorize from mimetype */
+ for (i = 0; i < CONTENT_TYPE_NUM; i++) {
+ if (strstr(mimetype, content_category[i].content_type) != NULL) {
+ *category = (*category | content_category[i].category_by_mime);
+ break;
+ }
+ }
+
+ /*in application type, exitst sound file ex) x-smafs */
+ if (*category & MS_CATEGORY_ETC) {
+ int prefix_len = strlen(content_category[0].content_type);
+
+ for (i = 0; i < SOUND_MIME_NUM; i++) {
+ if (strstr(mimetype + prefix_len, sound_mime_table[i]) != NULL) {
+ *category ^= MS_CATEGORY_ETC;
+ *category |= MS_CATEGORY_SOUND;
+ break;
+ }
+ }
+ }
+
+ /*check music file in soun files. */
+ if (*category & MS_CATEGORY_SOUND) {
+ int prefix_len = strlen(content_category[0].content_type) + 1;
+
+ //MS_DBG("mime_type : %s", mimetype + prefix_len);
+
+ for (i = 0; i < MUSIC_MIME_NUM; i++) {
+ if (strcmp(mimetype + prefix_len, music_mime_table[i]) == 0) {
+ *category ^= MS_CATEGORY_SOUND;
+ *category |= MS_CATEGORY_MUSIC;
+ break;
+ }
+ }
+
+ /*m3u file is playlist but mime type is "audio/x-mpegurl". but It has to be classified into MS_CATEGORY_ETC since playlist is not a sound track*/
+ if(strncasecmp(mimetype, "audio/x-mpegurl", strlen("audio/x-mpegurl")) == 0) {
+ *category ^= MS_CATEGORY_SOUND;
+ *category |= MS_CATEGORY_ETC;
+ }
+ } else if (*category & MS_CATEGORY_VIDEO) {
+ /*some video files don't have video stream. in this case it is categorize as music. */
+ /*"3gp" and "mp4" must check video stream and then categorize in directly. */
+ char file_ext[10] = {0};
+ memset(file_ext, 0, sizeof(file_ext));
+ if((_media_svc_get_file_ext(path, file_ext)) && strlen(file_ext) > 0) {
+ if ((strncasecmp(file_ext, _3GP_FILE, 4) == 0) || (strncasecmp(file_ext, _MP4_FILE, 5) == 0)) {
+ int audio = 0;
+ int video = 0;
+
+ err = mm_file_get_stream_info(path, &audio, &video);
+ if (err == 0) {
+ if (audio > 0 && video == 0) {
+ *category ^= MS_CATEGORY_VIDEO;
+ *category |= MS_CATEGORY_MUSIC;
+ }
+ }
+ }
+ }
+ }
+
+ //MS_DBG("category_from_ext : %d", *category);
+
+ return err;
+}
+
+static int __get_content_type(const char * file_path, const char * mime_type)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+ int category = 0;
+
+ ret = __get_content_type_from_mime(file_path, mime_type, &category);
+
+ if (category & MS_CATEGORY_SOUND) return MEDIA_SVC_MEDIA_TYPE_SOUND;
+ else if (category & MS_CATEGORY_MUSIC) return MEDIA_SVC_MEDIA_TYPE_MUSIC;
+ else if (category & MS_CATEGORY_IMAGE) return MEDIA_SVC_MEDIA_TYPE_IMAGE;
+ else if (category & MS_CATEGORY_VIDEO) return MEDIA_SVC_MEDIA_TYPE_VIDEO;
+ else return MEDIA_SVC_MEDIA_TYPE_OTHER;
+}
+
+static void __set_error_message(int err_type, char ** err_msg)
+{
+ if (err_msg)
+ *err_msg = NULL;
+ else
+ return;
+
+ if(err_type == ERR_HANDLE)
+ *err_msg = strdup("invalid handle");
+ else if(err_type == ERR_FILE_PATH)
+ *err_msg = strdup("invalid file path");
+ else if(err_type == ERR_FOLDER_PATH)
+ *err_msg = strdup("invalid folder path");
+ else if(err_type == ERR_MIME_TYPE)
+ *err_msg = strdup("invalid mime type");
+ else if(err_type == ERR_NOT_MEDIAFILE)
+ *err_msg = strdup("not media content");
+ else if(err_type == ERR_STORAGE_TYPE)
+ *err_msg = strdup("invalid storage type");
+ else if(err_type == ERR_CHECK_ITEM)
+ *err_msg = strdup("item does not exist");
+ else if(err_type == MEDIA_INFO_ERROR_DATABASE_CONNECT)
+ *err_msg = strdup("DB connect error");
+ else if(err_type == MEDIA_INFO_ERROR_DATABASE_DISCONNECT)
+ *err_msg = strdup("DB disconnect error");
+ else if(err_type == MEDIA_INFO_ERROR_INVALID_PARAMETER)
+ *err_msg = strdup("invalid parameter");
+ else if(err_type == MEDIA_INFO_ERROR_DATABASE_INTERNAL)
+ *err_msg = strdup("DB internal error");
+ else if(err_type == MEDIA_INFO_ERROR_DATABASE_NO_RECORD)
+ *err_msg = strdup("not found in DB");
+ else if(err_type == MEDIA_INFO_ERROR_INTERNAL)
+ *err_msg = strdup("media service internal error");
+ else
+ *err_msg = strdup("error unknown");
+
+ return;
+}
+
+int check_item(const char *file_path, const char * mime_type, char ** err_msg)
+{
+ if (!STRING_VALID(file_path)) {
+ __set_error_message(ERR_FILE_PATH, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(mime_type)) {
+ __set_error_message(ERR_MIME_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int connect(void ** handle, char ** err_msg)
+{
+ int ret = media_svc_connect(handle);
+
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int disconnect(void * handle, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_disconnect(handle);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int check_item_exist(void* handle, const char *file_path, int storage_type, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(file_path)) {
+ __set_error_message(ERR_FILE_PATH, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if(!STORAGE_VALID(storage_type)) {
+ __set_error_message(ERR_STORAGE_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_check_item_exist_by_path(handle, file_path);
+ if(ret == MEDIA_INFO_ERROR_NONE)
+ return MEDIA_SVC_PLUGIN_ERROR_NONE; //exist
+
+ __set_error_message(ERR_CHECK_ITEM, err_msg);
+
+ return MEDIA_SVC_PLUGIN_ERROR; //not exist
+}
+
+int insert_item_begin(void * handle, int item_cnt, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_insert_item_begin(handle, item_cnt);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int insert_item_end(void * handle, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_insert_item_end(handle);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int insert_item(void * handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(file_path)) {
+ __set_error_message(ERR_FILE_PATH, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(mime_type)) {
+ __set_error_message(ERR_MIME_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if(!STORAGE_VALID(storage_type)) {
+ __set_error_message(ERR_STORAGE_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ media_svc_media_type_e content_type = __get_content_type(file_path, mime_type);
+
+ ret = media_svc_insert_item_bulk(handle, storage_type, file_path, mime_type, content_type);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int insert_item_immediately(void * handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(file_path)) {
+ __set_error_message(ERR_FILE_PATH, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(mime_type)) {
+ __set_error_message(ERR_MIME_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if(!STORAGE_VALID(storage_type)) {
+ __set_error_message(ERR_STORAGE_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ media_svc_media_type_e content_type = __get_content_type(file_path, mime_type);
+
+ ret = media_svc_insert_item_immediately(handle, storage_type, file_path, mime_type, content_type);
+
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int move_item_begin(void * handle, int item_cnt, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_move_item_begin(handle, item_cnt);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int move_item_end(void * handle, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_move_item_end(handle);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int move_item(void * handle, const char *src_path, int src_storage_type, const char *dest_path, int dest_storage_type, const char * mime_type, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if ((!STRING_VALID(src_path)) || (!STRING_VALID(dest_path))) {
+ __set_error_message(ERR_FILE_PATH, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(mime_type)) {
+ __set_error_message(ERR_MIME_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if((!STORAGE_VALID(src_storage_type)) || (!STORAGE_VALID(dest_storage_type))) {
+ __set_error_message(ERR_STORAGE_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_move_item(handle, src_storage_type, src_path, dest_storage_type, dest_path);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int set_all_storage_items_validity(void * handle, int storage_type, int validity, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if(!STORAGE_VALID(storage_type)) {
+ __set_error_message(ERR_STORAGE_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_set_all_storage_items_validity(handle, storage_type, validity);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int set_folder_item_validity(void * handle, const char * folder_path, int validity, int recursive, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(folder_path)) {
+ __set_error_message(ERR_FOLDER_PATH, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_set_folder_items_validity(handle, folder_path, validity, recursive);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int set_item_validity_begin(void * handle, int item_cnt, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_set_item_validity_begin(handle, item_cnt);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int set_item_validity_end(void * handle, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_set_item_validity_end(handle);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int set_item_validity(void * handle, const char *file_path, int storage_type, const char * mime_type, int validity, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(file_path)) {
+ __set_error_message(ERR_FILE_PATH, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(mime_type)) {
+ __set_error_message(ERR_MIME_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if(!STORAGE_VALID(storage_type)) {
+ __set_error_message(ERR_STORAGE_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_set_item_validity(handle, file_path, validity);
+
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int delete_item(void * handle, const char *file_path, int storage_type, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(file_path)) {
+ __set_error_message(ERR_FILE_PATH, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if(!STORAGE_VALID(storage_type)) {
+ __set_error_message(ERR_STORAGE_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_check_item_exist_by_path(handle, file_path);
+ if(ret == 0) {
+ ret = media_svc_delete_item_by_path(handle, file_path);
+
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+ else
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+ }
+
+ __set_error_message(ERR_CHECK_ITEM, err_msg); //not exist in DB so can't delete item.
+ return MEDIA_SVC_PLUGIN_ERROR;
+}
+
+int delete_all_items_in_storage(void * handle, int storage_type, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if(!STORAGE_VALID(storage_type)) {
+ __set_error_message(ERR_STORAGE_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_delete_all_items_in_storage(handle, storage_type);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int delete_all_invalid_items_in_storage(void * handle, int storage_type, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if(!STORAGE_VALID(storage_type)) {
+ __set_error_message(ERR_STORAGE_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_delete_invalid_items_in_storage(handle, storage_type);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int delete_all_invalid_items_in_folder(void * handle, const char *folder_path, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(folder_path)) {
+ __set_error_message(ERR_FOLDER_PATH, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = media_svc_delete_invalid_items_in_folder(handle, folder_path);
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int delete_all_items(void * handle, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_INTERNAL, err_msg);
+ if(ret < 0)
+ return MEDIA_SVC_PLUGIN_ERROR;
+
+ ret = delete_all_items_in_storage(handle, MEDIA_SVC_STORAGE_EXTERNAL, err_msg);
+ if(ret < 0)
+ return MEDIA_SVC_PLUGIN_ERROR;
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int refresh_item(void * handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ if(handle == NULL) {
+ __set_error_message(ERR_HANDLE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(file_path)) {
+ __set_error_message(ERR_FILE_PATH, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if (!STRING_VALID(mime_type)) {
+ __set_error_message(ERR_MIME_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ if(!STORAGE_VALID(storage_type)) {
+ __set_error_message(ERR_STORAGE_TYPE, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ media_svc_media_type_e content_type = __get_content_type(file_path, mime_type);
+
+ ret = media_svc_refresh_item(handle, storage_type, file_path, content_type);
+
+ if(ret < 0) {
+ __set_error_message(ret, err_msg);
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int update_begin(void)
+{
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
+
+int update_end(void)
+{
+ int ret = MEDIA_SVC_PLUGIN_ERROR_NONE;
+
+ ret = thumbnail_request_extract_all_thumbs();
+ if (ret < 0) {
+ return MEDIA_SVC_PLUGIN_ERROR;
+ }
+
+ return MEDIA_SVC_PLUGIN_ERROR_NONE;
+}
diff --git a/src/common/media-svc-album.c b/src/common/media-svc-album.c
new file mode 100755
index 0000000..6f66160
--- /dev/null
+++ b/src/common/media-svc-album.c
@@ -0,0 +1,124 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include "media-svc-album.h"
+#include "media-svc-error.h"
+#include "media-svc-debug.h"
+#include "media-svc-env.h"
+#include "media-svc-util.h"
+#include "media-svc-db-utils.h"
+
+int _media_svc_get_album_id(sqlite3 *handle, const char *album, const char *artist, int * album_id)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = NULL;
+
+ media_svc_retvm_if(album == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "album is NULL");
+
+ if(artist != NULL) {
+ sql = sqlite3_mprintf("SELECT album_id FROM %s WHERE name = '%q' AND artist = '%q';", MEDIA_SVC_DB_TABLE_ALBUM, album, artist);
+ } else {
+ sql = sqlite3_mprintf("SELECT album_id FROM %s WHERE name = '%q' AND artist IS NULL;", MEDIA_SVC_DB_TABLE_ALBUM, album, artist);
+ }
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ if(ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
+ media_svc_debug("there is no album.");
+ }
+ else {
+ media_svc_error("error when _media_svc_get_album_id. err = [%d]", ret);
+ }
+ return ret;
+ }
+
+ *album_id = sqlite3_column_int(sql_stmt, 0);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return ret;
+}
+
+int _media_svc_get_album_art_by_album_id(sqlite3 *handle, int album_id, char **album_art)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *value = NULL;
+
+ char *sql = sqlite3_mprintf("SELECT album_art FROM %s WHERE album_id=%d", MEDIA_SVC_DB_TABLE_ALBUM, album_id);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ if(ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
+ media_svc_debug("there is no album_id.");
+ }
+ else {
+ media_svc_error("error when _media_svc_get_folder_id_by_foldername. err = [%d]", ret);
+ }
+ return ret;
+ }
+
+ value = (char *)sqlite3_column_text(sql_stmt, 0);
+
+ if (STRING_VALID(value)) {
+ ret = __media_svc_malloc_and_strncpy(album_art, value);
+ if (ret < 0) {
+ media_svc_error("__media_svc_malloc_and_strncpy failed: %d", ret);
+ SQLITE3_FINALIZE(sql_stmt);
+ return ret;
+ }
+ } else {
+ *album_art = NULL;
+ }
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_append_album(sqlite3 *handle, const char *album, const char *artist, const char *album_art, int * album_id)
+{
+ int err = -1;
+
+ char *sql = sqlite3_mprintf("INSERT INTO %s (name, artist, album_art, album_art) values (%Q, %Q, %Q, %Q); ",
+ MEDIA_SVC_DB_TABLE_ALBUM, album, artist, album_art, album_art);
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("failed to insert albums");
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ //*album_id = sqlite3_last_insert_rowid(handle);
+ int inserted_album_id = 0;
+ err = _media_svc_get_album_id(handle, album, artist, &inserted_album_id);
+ if (err < 0) {
+ media_svc_error("Failed _media_svc_get_album_id : %d", err);
+ return err;
+ }
+
+ *album_id = inserted_album_id;
+
+ return MEDIA_INFO_ERROR_NONE;
+}
diff --git a/src/common/media-svc-db-utils.c b/src/common/media-svc-db-utils.c
new file mode 100755
index 0000000..5d30705
--- /dev/null
+++ b/src/common/media-svc-db-utils.c
@@ -0,0 +1,692 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <unistd.h>
+#include <db-util.h>
+#include <media-util.h>
+#include "media-svc-env.h"
+#include "media-svc-debug.h"
+#include "media-svc-error.h"
+#include "media-svc-util.h"
+#include "media-svc-db-utils.h"
+#include "media-util-db.h"
+
+static int __media_svc_busy_handler(void *pData, int count);
+
+static int __media_svc_busy_handler(void *pData, int count)
+{
+ usleep(50000);
+
+ media_svc_debug("media_svc_busy_handler called : %d", count);
+
+ return 100 - count;
+}
+
+int _media_svc_connect_db_with_handle(sqlite3 **db_handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ media_svc_debug_func();
+
+ /*Connect DB*/
+ ret = db_util_open(MEDIA_SVC_DB_NAME, db_handle, DB_UTIL_REGISTER_HOOK_METHOD);
+
+ if (SQLITE_OK != ret) {
+
+ media_svc_error("error when db open");
+ *db_handle = NULL;
+ return MEDIA_INFO_ERROR_DATABASE_CONNECT;
+ }
+
+ /*Register busy handler*/
+ if (*db_handle) {
+ ret = sqlite3_busy_handler(*db_handle, __media_svc_busy_handler, NULL);
+
+ if (SQLITE_OK != ret) {
+
+ if (*db_handle) {
+ media_svc_error("[error when register busy handler] %s\n", sqlite3_errmsg(*db_handle));
+ }
+
+ db_util_close(*db_handle);
+ *db_handle = NULL;
+
+ return MEDIA_INFO_ERROR_DATABASE_CONNECT;
+ }
+ } else {
+ *db_handle = NULL;
+ return MEDIA_INFO_ERROR_DATABASE_CONNECT;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_disconnect_db_with_handle(sqlite3 *db_handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ media_svc_debug_func();
+
+ ret = db_util_close(db_handle);
+
+ if (SQLITE_OK != ret) {
+ media_svc_error("Error when db close : %s", sqlite3_errmsg(db_handle));
+ db_handle = NULL;
+ return MEDIA_INFO_ERROR_DATABASE_DISCONNECT;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_create_media_table(sqlite3 *db_handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ char * sql = NULL;
+
+ media_svc_debug_func();
+
+ sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
+ media_uuid TEXT PRIMARY KEY, \
+ path TEXT NOT NULL UNIQUE, \
+ file_name TEXT NOT NULL, \
+ media_type INTEGER,\
+ mime_type TEXT, \
+ size INTEGER DEFAULT 0, \
+ added_time INTEGER DEFAULT 0,\
+ modified_time INTEGER DEFAULT 0, \
+ folder_uuid TEXT NOT NULL, \
+ thumbnail_path TEXT, \
+ title TEXT, \
+ album_id INTEGER DEFAULT 0, \
+ album TEXT, \
+ artist TEXT, \
+ genre TEXT, \
+ composer TEXT, \
+ year TEXT, \
+ recorded_date TEXT, \
+ copyright TEXT, \
+ track_num TEXT, \
+ description TEXT, \
+ bitrate INTEGER DEFAULT -1, \
+ samplerate INTEGER DEFAULT -1, \
+ channel INTEGER DEFAULT -1, \
+ duration INTEGER DEFAULT -1, \
+ longitude DOUBLE DEFAULT 0, \
+ latitude DOUBLE DEFAULT 0, \
+ altitude DOUBLE DEFAULT 0, \
+ width INTEGER DEFAULT -1, \
+ height INTEGER DEFAULT -1, \
+ datetaken TEXT, \
+ orientation INTEGER DEFAULT -1, \
+ played_count INTEGER DEFAULT 0, \
+ last_played_time INTEGER DEFAULT 0, \
+ last_played_position INTEGER DEFAULT 0, \
+ rating INTEGER DEFAULT 0, \
+ favourite INTEGER DEFAULT 0, \
+ author TEXT, \
+ provider TEXT, \
+ content_name TEXT, \
+ category TEXT, \
+ location_tag TEXT, \
+ age_rating TEXT, \
+ keyword TEXT, \
+ is_drm INTEGER DEFAULT 0, \
+ storage_type INTEGER, \
+ validity INTEGER DEFAULT 1, \
+ unique(path, file_name) \
+ );",
+ MEDIA_SVC_DB_TABLE_MEDIA);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create db table (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ /* Create Index*/
+ sql = sqlite3_mprintf(" CREATE INDEX IF NOT EXISTS media_media_type_idx on %s (media_type); \
+ CREATE INDEX IF NOT EXISTS media_title_idx on %s (title); \
+ CREATE INDEX IF NOT EXISTS media_modified_time_idx on %s (modified_time); \
+ CREATE INDEX IF NOT EXISTS media_provider_idx on %s (provider); \
+ ",
+ MEDIA_SVC_DB_TABLE_MEDIA,
+ MEDIA_SVC_DB_TABLE_MEDIA,
+ MEDIA_SVC_DB_TABLE_MEDIA,
+ MEDIA_SVC_DB_TABLE_MEDIA);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create db table (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_create_folder_table(sqlite3 *db_handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ char * sql = NULL;
+
+ media_svc_debug_func();
+
+ sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
+ folder_uuid TEXT PRIMARY KEY, \
+ path TEXT NOT NULL UNIQUE, \
+ name TEXT NOT NULL, \
+ modified_time INTEGER DEFAULT 0, \
+ storage_type INTEGER, \
+ unique(path, name) \
+ );",
+ MEDIA_SVC_DB_TABLE_FOLDER);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create db table (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ /* Create Trigger to remove folder which have no content from folder when media remove from media_table*/
+ sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS folder_cleanup \
+ DELETE ON %s BEGIN DELETE FROM %s \
+ WHERE (SELECT count(*) FROM %s WHERE folder_uuid=old.folder_uuid)=1 AND folder_uuid=old.folder_uuid;END;",
+ MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_TABLE_MEDIA);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create trigger (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_create_playlist_table(sqlite3 *db_handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ char * sql = NULL;
+
+ media_svc_debug_func();
+
+ /*Create playlist table*/
+ sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
+ playlist_id INTEGER PRIMARY KEY AUTOINCREMENT, \
+ name TEXT NOT NULL UNIQUE\
+ );",
+ MEDIA_SVC_DB_TABLE_PLAYLIST);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create db table (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ /*Create playlist_map table*/
+ sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
+ _id INTEGER PRIMARY KEY AUTOINCREMENT, \
+ playlist_id INTEGER NOT NULL,\
+ media_uuid TEXT NOT NULL,\
+ play_order INTEGER NOT NULL\
+ );",
+ MEDIA_SVC_DB_TABLE_PLAYLIST_MAP);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create db table (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ /* Create Trigger to remove media from playlist_map when media remove from media_table*/
+ sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS playlist_map_cleanup \
+ DELETE ON %s BEGIN DELETE FROM %s WHERE media_uuid=old.media_uuid;END;",
+ MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create trigger (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ /* Create Trigger to remove media from playlist_map when playlist removed from playlist table*/
+ sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS playlist_map_cleanup_1 \
+ DELETE ON %s BEGIN DELETE FROM %s WHERE playlist_id=old.playlist_id;END;",
+ MEDIA_SVC_DB_TABLE_PLAYLIST, MEDIA_SVC_DB_TABLE_PLAYLIST_MAP);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create trigger (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_create_album_table(sqlite3 *db_handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ char * sql = NULL;
+
+ media_svc_debug_func();
+
+ sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
+ album_id INTEGER PRIMARY KEY AUTOINCREMENT, \
+ name TEXT NOT NULL,\
+ artist TEXT, \
+ album_art TEXT, \
+ unique(name, artist) \
+ );",
+ MEDIA_SVC_DB_TABLE_ALBUM);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create db table (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ /* Create Trigger to remove album when media remove from media_table*/
+ sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS album_cleanup \
+ DELETE ON %s BEGIN DELETE FROM %s \
+ WHERE (SELECT count(*) FROM %s WHERE album_id=old.album_id)=1 AND album_id=old.album_id;END;",
+ MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_ALBUM, MEDIA_SVC_DB_TABLE_MEDIA);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create trigger (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_create_tag_table(sqlite3 *db_handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ char * sql = NULL;
+
+ media_svc_debug_func();
+
+ /*Create tag table*/
+ sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
+ tag_id INTEGER PRIMARY KEY AUTOINCREMENT, \
+ name TEXT NOT NULL UNIQUE\
+ );",
+ MEDIA_SVC_DB_TABLE_TAG);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create db table (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ /*Create tag_map table*/
+ sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
+ _id INTEGER PRIMARY KEY AUTOINCREMENT, \
+ tag_id INTEGER NOT NULL,\
+ media_uuid TEXT NOT NULL,\
+ unique(tag_id, media_uuid) \
+ );",
+ MEDIA_SVC_DB_TABLE_TAG_MAP);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create db table (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ /* Create Trigger to remove media from tag_map when media remove from media_table*/
+ sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS tag_map_cleanup \
+ DELETE ON %s BEGIN DELETE FROM %s WHERE media_uuid=old.media_uuid;END;",
+ MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_TAG_MAP);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create trigger (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ /* Create Trigger to remove media from tag_map when tag removed from tag table*/
+ sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS tag_map_cleanup_1 \
+ DELETE ON %s BEGIN DELETE FROM %s WHERE tag_id=old.tag_id;END;",
+ MEDIA_SVC_DB_TABLE_TAG, MEDIA_SVC_DB_TABLE_TAG_MAP);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create trigger (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_create_bookmark_table(sqlite3 *db_handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ char * sql = NULL;
+
+ media_svc_debug_func();
+
+ sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
+ bookmark_id INTEGER PRIMARY KEY AUTOINCREMENT, \
+ media_uuid TEXT NOT NULL,\
+ marked_time INTEGER DEFAULT 0, \
+ thumbnail_path TEXT, \
+ unique(media_uuid, marked_time) \
+ );",
+ MEDIA_SVC_DB_TABLE_BOOKMARK);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create db table (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ /* Create Trigger to remove media from tag_map when media remove from media_table*/
+ sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS bookmark_cleanup \
+ DELETE ON %s BEGIN DELETE FROM %s WHERE media_uuid=old.media_uuid;END;",
+ MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_BOOKMARK);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create trigger (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_create_custom_table(sqlite3 *db_handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ char * sql = NULL;
+
+ media_svc_debug_func();
+
+ sql = sqlite3_mprintf("CREATE TABLE IF NOT EXISTS %s (\
+ _id INTEGER PRIMARY KEY AUTOINCREMENT, \
+ media_uuid TEXT, \
+ media_type INTEGER,\
+ author TEXT, \
+ provider TEXT, \
+ content_name TEXT, \
+ category TEXT, \
+ location_tag TEXT, \
+ age_rating TEXT \
+ );",
+ MEDIA_SVC_DB_TABLE_CUSTOM);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create db table (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ /* Create Trigger to remove media from tag_map when media remove from media_table*/
+ sql = sqlite3_mprintf("CREATE TRIGGER IF NOT EXISTS custom_cleanup \
+ DELETE ON %s BEGIN DELETE FROM %s WHERE media_uuid=old.media_uuid;END;",
+ MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_CUSTOM);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create trigger (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ /* Create Index*/
+ sql = sqlite3_mprintf("CREATE INDEX IF NOT EXISTS custom_provider_idx on %s (provider); \
+ ",
+ MEDIA_SVC_DB_TABLE_CUSTOM);
+
+ media_svc_retv_if(sql == NULL, MEDIA_INFO_ERROR_OUT_OF_MEMORY);
+
+ ret = _media_svc_sql_query(db_handle, sql);
+ sqlite3_free(sql);
+ if (ret != SQLITE_OK) {
+ media_svc_error("It failed to create db table (%d)", ret);
+ return MEDIA_INFO_ERROR_DATABASE_TABLE_OPEN;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_request_update_db(const char *sql_str)
+{
+ int ret = MS_MEDIA_ERR_NONE;
+
+ ret = media_db_request_update_db(sql_str);
+
+ return ret;
+}
+
+int _media_svc_sql_query(sqlite3 *db_handle, const char *sql_str)
+{
+ int err = -1;
+
+ media_svc_debug("[SQL query] : %s", sql_str);
+#if 1
+ //DB will be updated by Media Server.
+ err = _media_svc_request_update_db(sql_str);
+
+ return _media_svc_error_convert(err);
+#else
+ char *zErrMsg = NULL;
+ media_svc_retvm_if(sql_str == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "sql_str is NULL");
+
+ err = sqlite3_exec(db_handle, sql_str, NULL, NULL, &zErrMsg);
+
+ if (SQLITE_OK != err) {
+ media_svc_error("failed to execute [%s], err[%d]", zErrMsg, err);
+ } else {
+ media_svc_debug("query success");
+ }
+
+ if (zErrMsg)
+ sqlite3_free (zErrMsg);
+ return err;
+#endif
+}
+
+int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt** stmt)
+{
+ int err = -1;
+
+ media_svc_debug("[SQL query] : %s", sql_str);
+
+ err = sqlite3_prepare_v2(handle, sql_str, -1, stmt, NULL);
+ sqlite3_free((char *)sql_str);
+
+ if (err != SQLITE_OK) {
+ media_svc_error ("prepare error [%s]", sqlite3_errmsg(handle));
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ err = sqlite3_step(*stmt);
+ if (err != SQLITE_ROW) {
+ media_svc_error("Item not found. end of row [%s]", sqlite3_errmsg(handle));
+ SQLITE3_FINALIZE(*stmt);
+ return MEDIA_INFO_ERROR_DATABASE_NO_RECORD;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_sql_begin_trans(sqlite3 *handle)
+{
+ int err = MEDIA_INFO_ERROR_NONE;
+
+ media_svc_debug("========_media_svc_sql_begin_trans");
+#if 1
+ //err = _media_svc_request_update_db("BEGIN IMMEDIATE;");
+ err = media_db_request_update_db_batch_start("BEGIN IMMEDIATE;");
+
+ return _media_svc_error_convert(err);
+#else
+ char *err_msg = NULL;
+
+ if (SQLITE_OK != sqlite3_exec(handle, "BEGIN IMMEDIATE;", NULL, NULL, &err_msg)) {
+ media_svc_error("Error:failed to begin transaction: error=%s", err_msg);
+ sqlite3_free(err_msg);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ sqlite3_free(err_msg);
+ return err;
+#endif
+}
+
+int _media_svc_sql_end_trans(sqlite3 *handle)
+{
+ int err = MEDIA_INFO_ERROR_NONE;
+
+ media_svc_debug("========_media_svc_sql_end_trans");
+#if 1
+ err = media_db_request_update_db_batch_end("COMMIT;");
+ //err = _media_svc_request_update_db("COMMIT;");
+ return _media_svc_error_convert(err);
+#else
+ char *err_msg = NULL;
+ if (SQLITE_OK != sqlite3_exec(handle, "COMMIT;", NULL, NULL, &err_msg)) {
+ media_svc_error("Error:failed to end transaction: error=%s", err_msg);
+ sqlite3_free(err_msg);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ sqlite3_free(err_msg);
+ return err;
+#endif
+}
+
+int _media_svc_sql_rollback_trans(sqlite3 *handle)
+{
+ int err = MEDIA_INFO_ERROR_NONE;
+
+ media_svc_debug("========_media_svc_sql_rollback_trans");
+#if 1
+ err = _media_svc_request_update_db("ROLLBACK;");
+ return _media_svc_error_convert(err);
+#else
+ char *err_msg = NULL;
+ if (SQLITE_OK != sqlite3_exec(handle, "ROLLBACK;", NULL, NULL, &err_msg)) {
+ media_svc_error("Error:failed to rollback transaction: error=%s", err_msg);
+ sqlite3_free(err_msg);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ sqlite3_free(err_msg);
+ return err;
+#endif
+}
+
+int _media_svc_sql_query_list(sqlite3 *handle, GList **query_list)
+{
+ int i = 0;
+ int length = g_list_length(*query_list);
+ int err = -1;
+ char *sql = NULL;
+
+ media_svc_debug("query list length : [%d]", length);
+
+ for (i = 0; i < length; i++) {
+ sql = (char*)g_list_nth_data(*query_list, i);
+ if(sql != NULL) {
+ //err = _media_svc_sql_query(handle, sql);
+ err = media_db_request_update_db_batch(sql);
+ //if (err != SQLITE_OK) {
+ // media_svc_error("A query failed in batch");
+ if (err < MS_MEDIA_ERR_NONE) {
+ media_svc_error("media_db_request_update_db_batch failed : %d", err);
+ }
+ sqlite3_free(sql);
+ sql = NULL;
+ }
+ }
+
+ _media_svc_sql_query_release(query_list);
+
+ return MEDIA_INFO_ERROR_NONE;
+
+}
+
+void _media_svc_sql_query_add(GList **query_list, char **query)
+{
+ *query_list = g_list_append( *query_list, *query);
+}
+
+void _media_svc_sql_query_release(GList **query_list)
+{
+ if (*query_list) {
+ media_svc_debug("_svc_sql_query_release");
+ g_list_free(*query_list);
+ *query_list = NULL;
+ }
+}
diff --git a/src/common/media-svc-debug.c b/src/common/media-svc-debug.c
new file mode 100755
index 0000000..53617c6
--- /dev/null
+++ b/src/common/media-svc-debug.c
@@ -0,0 +1,111 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <unistd.h>
+#include <asm/unistd.h>
+#include <time.h>
+#include <sys/time.h>
+#include "media-svc-debug.h"
+
+#ifdef _PERFORMANCE_CHECK_
+static long g_time_usec = 0L;
+#endif
+
+#ifdef _USE_LOG_FILE_
+static FILE *g_log_fp = NULL;
+static char _g_file_path[1024] = "\0";
+
+FILE *get_fp()
+{
+ return g_log_fp;
+}
+
+void mediainfo_init_file_debug()
+{
+ if (g_log_fp == NULL) {
+ snprintf(_g_file_path, sizeof(_g_file_path), "/tmp/%s",
+ "media-info");
+ if (access(_g_file_path, R_OK == 0)) {
+ remove(_g_file_path);
+ }
+
+ g_log_fp = fopen(_g_file_path, "a");
+ }
+}
+
+void mediainfo_close_file_debug()
+{
+ if (g_log_fp != NULL) {
+ fclose(g_log_fp);
+ g_log_fp = NULL;
+ }
+}
+
+#endif
+
+long mediainfo_get_debug_time(void)
+{
+#ifdef _PERFORMANCE_CHECK_
+ struct timeval time;
+ gettimeofday(&time, NULL);
+ return time.tv_sec * 1000000 + time.tv_usec;
+#else
+ return 0L;
+#endif
+}
+
+void mediainfo_reset_debug_time(void)
+{
+#ifdef _PERFORMANCE_CHECK_
+ struct timeval time;
+ gettimeofday(&time, NULL);
+ g_time_usec = time.tv_sec * 1000000 + time.tv_usec;
+#endif
+}
+
+void mediainfo_print_debug_time(char *time_string)
+{
+#ifdef _PERFORMANCE_CHECK_
+ struct timeval time;
+ double totaltime = 0.0;
+
+ gettimeofday(&time, NULL);
+ totaltime =
+ (double)(time.tv_sec * 1000000 + time.tv_usec -
+ g_time_usec) / CLOCKS_PER_SEC;
+
+ media_svc_debug("time [%s] : %f \n", time_string, totaltime);
+#endif
+}
+
+void
+mediainfo_print_debug_time_ex(long start, long end, const char *func_name,
+ char *time_string)
+{
+#ifdef _PERFORMANCE_CHECK_
+ double totaltime = 0.0;
+
+ totaltime = (double)(end - start) / CLOCKS_PER_SEC;
+
+ media_svc_debug("time [%s: %s] : %f \n", func_name, time_string,
+ totaltime);
+#endif
+}
diff --git a/src/common/media-svc-media-folder.c b/src/common/media-svc-media-folder.c
new file mode 100755
index 0000000..2a1678a
--- /dev/null
+++ b/src/common/media-svc-media-folder.c
@@ -0,0 +1,146 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <glib/gstdio.h>
+#include "media-svc-media-folder.h"
+#include "media-svc-error.h"
+#include "media-svc-debug.h"
+#include "media-svc-env.h"
+#include "media-svc-util.h"
+#include "media-svc-db-utils.h"
+
+extern __thread GList *g_media_svc_move_item_query_list;
+
+int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *folder_name, char *folder_id)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+
+ char *sql = sqlite3_mprintf("SELECT folder_uuid FROM %s WHERE path = '%q';", MEDIA_SVC_DB_TABLE_FOLDER, folder_name);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ if(ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
+ media_svc_debug("there is no folder.");
+ }
+ else {
+ media_svc_error("error when _media_svc_get_folder_id_by_foldername. err = [%d]", ret);
+ }
+ return ret;
+ }
+
+ _strncpy_safe(folder_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE+1);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return ret;
+}
+
+int _media_svc_append_folder(sqlite3 *handle, media_svc_storage_type_e storage_type,
+ const char *folder_id, const char *path_name, const char *folder_name, int modified_date)
+{
+ int err = -1;
+
+ char *sql = sqlite3_mprintf("INSERT INTO %s (folder_uuid, path, name, storage_type, modified_time) values (%Q, %Q, %Q, '%d', '%d'); ",
+ MEDIA_SVC_DB_TABLE_FOLDER, folder_id, path_name, folder_name, storage_type, modified_date);
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("failed to insert folder");
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_update_folder_modified_time_by_folder_uuid(sqlite3 *handle, const char *folder_uuid, const char *folder_path, bool stack_query)
+{
+ int err = -1;
+ int modified_time = 0;
+
+ modified_time = _media_svc_get_file_time(folder_path);
+
+ char *sql = sqlite3_mprintf("UPDATE %s SET modified_time=%d WHERE folder_uuid=%Q;", MEDIA_SVC_DB_TABLE_FOLDER, modified_time, folder_uuid);
+
+ if(!stack_query) {
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("failed to update folder");
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+ } else {
+ _media_svc_sql_query_add(&g_media_svc_move_item_query_list, &sql);
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, const char *path, media_svc_storage_type_e storage_type, char *folder_id)
+{
+ char *path_name = NULL;
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ path_name = g_path_get_dirname(path);
+
+ ret = _media_svc_get_folder_id_by_foldername(handle, path_name, folder_id);
+
+ if(ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
+ char *folder_name = NULL;
+ int folder_modified_date = 0;
+ char *folder_uuid = _media_info_generate_uuid();
+ if(folder_uuid == NULL ) {
+ media_svc_error("Invalid UUID");
+ SAFE_FREE(path_name);
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ folder_name = g_path_get_basename(path_name);
+ folder_modified_date = _media_svc_get_file_time(path_name);
+
+ ret = _media_svc_append_folder(handle, storage_type, folder_uuid, path_name, folder_name, folder_modified_date);
+ SAFE_FREE(folder_name);
+ _strncpy_safe(folder_id, folder_uuid, MEDIA_SVC_UUID_SIZE+1);
+ }
+
+ SAFE_FREE(path_name);
+
+ return ret;
+}
+
+int _media_svc_update_folder_table(sqlite3 *handle)
+{
+ int err = -1;
+ char *sql = NULL;
+
+ sql = sqlite3_mprintf("DELETE FROM %s WHERE folder_uuid IN (SELECT folder_uuid FROM %s WHERE folder_uuid NOT IN (SELECT folder_uuid FROM %s))",
+ MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_TABLE_FOLDER, MEDIA_SVC_DB_TABLE_MEDIA);
+
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("failed to delete folder item");
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
diff --git a/src/common/media-svc-media.c b/src/common/media-svc-media.c
new file mode 100755
index 0000000..d0ef0d6
--- /dev/null
+++ b/src/common/media-svc-media.c
@@ -0,0 +1,667 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <string.h>
+#include "media-svc-media.h"
+#include "media-svc-media-folder.h"
+#include "media-svc-error.h"
+#include "media-svc-debug.h"
+#include "media-svc-util.h"
+#include "media-svc-db-utils.h"
+
+typedef struct{
+ char thumbnail_path[MEDIA_SVC_PATHNAME_SIZE];
+}media_svc_thumbnailpath_s;
+
+static __thread GList *g_media_svc_item_validity_query_list = NULL;
+static __thread GList *g_media_svc_insert_item_query_list = NULL;
+__thread GList *g_media_svc_move_item_query_list = NULL;
+
+static int __media_svc_count_invalid_records_with_thumbnail(sqlite3 *handle, media_svc_storage_type_e storage_type, int *count);
+static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, media_svc_storage_type_e storage_type,
+ int count, media_svc_thumbnailpath_s * thumb_path);
+static int __media_svc_count_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *folder_path, int *count);
+static int __media_svc_get_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *folder_path,
+ int count, media_svc_thumbnailpath_s * thumb_path);
+
+static int __media_svc_count_invalid_records_with_thumbnail(sqlite3 *handle, media_svc_storage_type_e storage_type, int *count)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE validity=0 AND storage_type=%d AND thumbnail_path IS NOT NULL",
+ MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("error when __media_svc_count_invalid_records_with_thumbnail. err = [%d]", ret);
+ return ret;
+ }
+
+ *count = sqlite3_column_int(sql_stmt, 0);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MEDIA_INFO_ERROR_NONE;
+
+}
+
+static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, media_svc_storage_type_e storage_type,
+ int count, media_svc_thumbnailpath_s * thumb_path)
+{
+ int err = -1;
+ int idx = 0;
+ sqlite3_stmt *sql_stmt = NULL;
+
+ char *sql = sqlite3_mprintf("select thumbnail_path from %s WHERE validity=0 AND storage_type=%d AND thumbnail_path IS NOT NULL",
+ MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
+
+ media_svc_debug("[SQL query] : %s", sql);
+
+ err = sqlite3_prepare_v2(handle, sql, -1, &sql_stmt, NULL);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("prepare error [%s]", sqlite3_errmsg(handle));
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
+ _strncpy_safe(thumb_path[idx].thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(thumb_path[idx]));
+ //media_svc_debug("thumb_path[%d]=[%s]", idx, thumb_path[idx].thumbnail_path);
+ idx++;
+ }
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+static int __media_svc_count_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *folder_path, int *count)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE validity=0 AND path LIKE '%q/%%' AND thumbnail_path IS NOT NULL",
+ MEDIA_SVC_DB_TABLE_MEDIA, folder_path);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("error when __media_svc_count_invalid_folder_records_with_thumbnail. err = [%d]", ret);
+ return ret;
+ }
+
+ *count = sqlite3_column_int(sql_stmt, 0);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MEDIA_INFO_ERROR_NONE;
+
+}
+
+static int __media_svc_get_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *folder_path,
+ int count, media_svc_thumbnailpath_s * thumb_path)
+{
+ int err = -1;
+ int idx = 0;
+ sqlite3_stmt *sql_stmt = NULL;
+
+ char *sql = sqlite3_mprintf("select thumbnail_path from %s WHERE validity=0 AND path LIKE '%q/%%' AND thumbnail_path IS NOT NULL",
+ MEDIA_SVC_DB_TABLE_MEDIA, folder_path);
+
+ media_svc_debug("[SQL query] : %s", sql);
+
+ err = sqlite3_prepare_v2(handle, sql, -1, &sql_stmt, NULL);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("prepare error [%s]", sqlite3_errmsg(handle));
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
+ _strncpy_safe(thumb_path[idx].thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(thumb_path[idx]));
+ idx++;
+ }
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_count_record_with_path(sqlite3 *handle, const char *path, int *count)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+
+ char *sql = sqlite3_mprintf("SELECT count(*) FROM %s WHERE path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ *count = sqlite3_column_int(sql_stmt, 0);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, bool stack_query)
+{
+ media_svc_debug("");
+ int err = -1;
+
+ char * db_fields = "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, folder_uuid, \
+ thumbnail_path, title, album_id, album, artist, genre, composer, year, recorded_date, copyright, track_num, description,\
+ bitrate, samplerate, channel, duration, longitude, latitude, altitude, width, height, datetaken, orientation,\
+ rating, is_drm, storage_type";
+
+ /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
+ /* This code will be removed when sqlite3_mprintf works clearly */
+ char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
+ sqlite3_free(test_sql);
+
+ char *sql = sqlite3_mprintf("INSERT INTO %s (%s) VALUES (%Q, %Q, %Q, %d, %Q, %lld, %d, %d, %Q, \
+ %Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, \
+ %d, %d, %d, %d, %.2f, %.2f, %.2f, %d, %d, %Q, %d, \
+ %d, %d, %d);",
+ MEDIA_SVC_DB_TABLE_MEDIA, db_fields,
+ content_info->media_uuid,
+ content_info->path,
+ content_info->file_name,
+ content_info->media_type,
+ content_info->mime_type,
+ content_info->size,
+ content_info->added_time,
+ content_info->modified_time,
+ content_info->folder_uuid,
+ content_info->thumbnail_path, //
+ content_info->media_meta.title,
+ content_info->album_id,
+ content_info->media_meta.album,
+ content_info->media_meta.artist,
+ content_info->media_meta.genre,
+ content_info->media_meta.composer,
+ content_info->media_meta.year,
+ content_info->media_meta.recorded_date,
+ content_info->media_meta.copyright,
+ content_info->media_meta.track_num,
+ content_info->media_meta.description, //
+ content_info->media_meta.bitrate,
+ content_info->media_meta.samplerate,
+ content_info->media_meta.channel,
+ content_info->media_meta.duration,
+ content_info->media_meta.longitude,
+ content_info->media_meta.latitude,
+ content_info->media_meta.altitude,
+ content_info->media_meta.width,
+ content_info->media_meta.height,
+ content_info->media_meta.datetaken,
+ content_info->media_meta.orientation,
+ content_info->media_meta.rating,
+ content_info->is_drm,
+ content_info->storage_type);
+
+ if(!stack_query) {
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("failed to insert item");
+
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+ } else {
+ media_svc_debug("query : %s", sql);
+ _media_svc_sql_query_add(&g_media_svc_insert_item_query_list, &sql);
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info)
+{
+ int err = -1;
+
+ /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
+ /* This code will be removed when sqlite3_mprintf works clearly */
+ char *test_sql = sqlite3_mprintf("%f, %f, %f", content_info->media_meta.longitude, content_info->media_meta.latitude, content_info->media_meta.altitude);
+ sqlite3_free(test_sql);
+
+ char *sql = sqlite3_mprintf("UPDATE %s SET \
+ size=%lld, modified_time=%d, thumbnail_path=%Q, title=%Q, album_id=%d, album=%Q, artist=%Q, genre=%Q, \
+ composer=%Q, year=%Q, recorded_date=%Q, copyright=%Q, track_num=%Q, description=%Q, \
+ bitrate=%d, samplerate=%d, channel=%d, duration=%d, longitude=%f, latitude=%f, altitude=%f, width=%d, height=%d, datetaken=%Q, \
+ orientation=%d WHERE path=%Q",
+ MEDIA_SVC_DB_TABLE_MEDIA,
+ content_info->size,
+ content_info->modified_time,
+ content_info->thumbnail_path,
+ content_info->media_meta.title,
+ content_info->album_id,
+ content_info->media_meta.album,
+ content_info->media_meta.artist,
+ content_info->media_meta.genre,
+ content_info->media_meta.composer,
+ content_info->media_meta.year,
+ content_info->media_meta.recorded_date,
+ content_info->media_meta.copyright,
+ content_info->media_meta.track_num,
+ content_info->media_meta.description,
+ content_info->media_meta.bitrate,
+ content_info->media_meta.samplerate,
+ content_info->media_meta.channel,
+ content_info->media_meta.duration,
+ content_info->media_meta.longitude,
+ content_info->media_meta.latitude,
+ content_info->media_meta.altitude,
+ content_info->media_meta.width,
+ content_info->media_meta.height,
+ content_info->media_meta.datetaken,
+ content_info->media_meta.orientation,
+ content_info->path
+ );
+
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("failed to update item");
+
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, char *thumbnail_path)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+
+ char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM %s WHERE path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ if(ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
+ media_svc_debug("there is no thumbnail.");
+ }
+ else {
+ media_svc_error("error when _media_svc_get_thumbnail_path_by_path. err = [%d]", ret);
+ }
+ return ret;
+ }
+
+ _strncpy_safe(thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_PATHNAME_SIZE);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *path, int *media_type)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+
+ char *sql = sqlite3_mprintf("SELECT media_type FROM %s WHERE path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("error when _media_svc_get_media_type_by_path. err = [%d]", ret);
+ return ret;
+ }
+
+ *media_type = sqlite3_column_int(sql_stmt, 0);
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_delete_item_by_path(sqlite3 *handle, const char *path)
+{
+ int err = -1;
+ char *sql = sqlite3_mprintf("DELETE FROM %s WHERE validity=1 AND path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path);
+
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("It failed to delete item (%d)", err);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_truncate_table(sqlite3 *handle, media_svc_storage_type_e storage_type)
+{
+ int err = -1;
+ char *sql = sqlite3_mprintf("DELETE FROM %s WHERE storage_type=%d", MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
+
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("It failed to truncate table (%d)", err);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+
+}
+
+int _media_svc_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e storage_type)
+{
+ int idx = 0;
+ media_svc_thumbnailpath_s *thumbpath_record = NULL;
+ int err = -1;
+ int invalid_count = 0;
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ ret = __media_svc_count_invalid_records_with_thumbnail(handle, storage_type, &invalid_count);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ media_svc_debug("invalid count: %d\n", invalid_count);
+
+ if (invalid_count > 0) {
+ thumbpath_record = (media_svc_thumbnailpath_s *)calloc( invalid_count, sizeof(media_svc_thumbnailpath_s));
+ if (thumbpath_record == NULL) {
+ media_svc_error("fail to memory allocation");
+ return MEDIA_INFO_ERROR_OUT_OF_MEMORY;
+ }
+
+ ret = __media_svc_get_invalid_records_with_thumbnail(handle, storage_type, invalid_count, thumbpath_record);
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("error when get thumbnail record");
+ SAFE_FREE(thumbpath_record);
+ return ret;
+ }
+ } else {
+ media_svc_debug("There is no item with thumbnail");
+ }
+
+ char *sql = sqlite3_mprintf("DELETE FROM %s WHERE validity = 0 AND storage_type=%d", MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("To delete invalid items is failed(%d)", err);
+ SAFE_FREE(thumbpath_record);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ /*Delete thumbnails*/
+ for (idx = 0; idx < invalid_count; idx++) {
+ if (strlen(thumbpath_record[idx].thumbnail_path) > 0) {
+ if (_media_svc_remove_file(thumbpath_record[idx].thumbnail_path) == FALSE) {
+ media_svc_error("fail to remove thumbnail file.");
+ //SAFE_FREE(thumbpath_record);
+ //return MEDIA_INFO_ERROR_INTERNAL;
+ }
+ }
+ }
+
+ SAFE_FREE(thumbpath_record);
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *folder_path)
+{
+ int idx = 0;
+ media_svc_thumbnailpath_s *thumbpath_record = NULL;
+ int err = -1;
+ int invalid_count = 0;
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ ret = __media_svc_count_invalid_folder_records_with_thumbnail(handle, folder_path, &invalid_count);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ media_svc_debug("invalid count: %d\n", invalid_count);
+
+ if (invalid_count > 0) {
+ thumbpath_record = (media_svc_thumbnailpath_s *)calloc( invalid_count, sizeof(media_svc_thumbnailpath_s));
+ if (thumbpath_record == NULL) {
+ media_svc_error("fail to memory allocation");
+ return MEDIA_INFO_ERROR_OUT_OF_MEMORY;
+ }
+
+ ret = __media_svc_get_invalid_folder_records_with_thumbnail(handle, folder_path, invalid_count, thumbpath_record);
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("error when get thumbnail record");
+ SAFE_FREE(thumbpath_record);
+ return ret;
+ }
+ } else {
+ media_svc_debug("There is no item with thumbnail");
+ }
+
+ char *sql = sqlite3_mprintf("DELETE FROM %s WHERE validity = 0 AND path LIKE '%q/%%'", MEDIA_SVC_DB_TABLE_MEDIA, folder_path);
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("To delete invalid items is failed(%d)", err);
+ SAFE_FREE(thumbpath_record);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ /*Delete thumbnails*/
+ for (idx = 0; idx < invalid_count; idx++) {
+ if (strlen(thumbpath_record[idx].thumbnail_path) > 0) {
+ if (_media_svc_remove_file(thumbpath_record[idx].thumbnail_path) == FALSE) {
+ media_svc_error("fail to remove thumbnail file [%s].", thumbpath_record[idx].thumbnail_path);
+ //SAFE_FREE(thumbpath_record);
+ //return MEDIA_INFO_ERROR_INTERNAL;
+ }
+ }
+ }
+
+ SAFE_FREE(thumbpath_record);
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+
+int _media_svc_update_item_validity(sqlite3 *handle, const char *path, int validity, bool stack_query)
+{
+ int err = -1;
+
+ char *sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE path= '%q'", MEDIA_SVC_DB_TABLE_MEDIA, validity, path);
+
+ if(!stack_query) {
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("To update item as valid is failed(%d)", err);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+ } else {
+ _media_svc_sql_query_add(&g_media_svc_item_validity_query_list, &sql);
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *path, const char *thumb_path)
+{
+ int err = -1;
+
+ char *sql = sqlite3_mprintf("UPDATE %s SET thumbnail_path=%Q WHERE path= %Q", MEDIA_SVC_DB_TABLE_MEDIA, thumb_path, path);
+
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("To update thumb path failed(%d)", err);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_update_storage_item_validity(sqlite3 *handle, media_svc_storage_type_e storage_type, int validity)
+{
+ int err = -1;
+ char *sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE storage_type=%d", MEDIA_SVC_DB_TABLE_MEDIA, validity, storage_type);
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("To update item as valid is failed(%d)", err);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity)
+{
+ int err = -1;
+ int ret = MEDIA_INFO_ERROR_NONE;
+ char *sql = NULL;
+ char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
+ sqlite3_stmt *sql_stmt = NULL;
+
+ /*Get folder ID*/
+ sql = sqlite3_mprintf("SELECT folder_uuid FROM %s WHERE path='%q'", MEDIA_SVC_DB_TABLE_FOLDER, folder_path);
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("error when get folder_id. err = [%d]", ret);
+ return ret;
+ }
+
+ _strncpy_safe(folder_uuid, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE+1);
+ SQLITE3_FINALIZE(sql_stmt);
+
+ /*Update folder item validity*/
+ sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE folder_uuid='%q'", MEDIA_SVC_DB_TABLE_MEDIA, validity, folder_uuid);
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("To update folder item as valid is failed(%d)", err);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_update_recursive_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity)
+{
+ int err = -1;
+
+ /*Update folder item validity*/
+ char *sql = sqlite3_mprintf("UPDATE %s SET validity=%d WHERE path LIKE '%q/%%'", MEDIA_SVC_DB_TABLE_MEDIA, validity, folder_path);
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("To update recursive folder item validity is failed(%d)", err);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_update_item_by_path(sqlite3 *handle, const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path,
+ const char *file_name, int modified_time, const char *folder_uuid, const char *thumb_path, bool stack_query)
+{
+ /* update path, filename, modified_time, folder_uuid, thumbnail_path, */
+ /* played_count, last_played_time, last_played_position, favourite, storaget_type*/
+
+ int err = -1;
+ char *sql = NULL;
+
+ if(thumb_path != NULL) {
+ sql = sqlite3_mprintf("UPDATE %s SET \
+ path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, thumbnail_path=%Q, storage_type=%d, \
+ played_count=0, last_played_time=0, last_played_position=0 \
+ WHERE path=%Q",
+ MEDIA_SVC_DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_uuid, thumb_path, dest_storage, src_path);
+ } else {
+ sql = sqlite3_mprintf("UPDATE %s SET \
+ path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, storage_type=%d, \
+ played_count=0, last_played_time=0, last_played_position=0 \
+ WHERE path=%Q",
+ MEDIA_SVC_DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_uuid, dest_storage, src_path);
+ }
+
+ if(!stack_query) {
+ err = _media_svc_sql_query(handle, sql);
+ sqlite3_free(sql);
+ if (err != SQLITE_OK) {
+ media_svc_error("It failed to update metadata (%d)", err);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+ } else {
+ _media_svc_sql_query_add(&g_media_svc_move_item_query_list, &sql);
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_list_query_do(sqlite3 *handle, media_svc_query_type_e query_type)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ ret = _media_svc_sql_begin_trans(handle);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ if (query_type == MEDIA_SVC_QUERY_SET_ITEM_VALIDITY)
+ ret = _media_svc_sql_query_list(handle, &g_media_svc_item_validity_query_list);
+ else if (query_type == MEDIA_SVC_QUERY_MOVE_ITEM)
+ ret = _media_svc_sql_query_list(handle, &g_media_svc_move_item_query_list);
+ else if (query_type == MEDIA_SVC_QUERY_INSERT_ITEM)
+ ret = _media_svc_sql_query_list(handle, &g_media_svc_insert_item_query_list);
+ else
+ ret = MEDIA_INFO_ERROR_INVALID_PARAMETER;
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("_media_svc_list_query_do failed. start rollback");
+ _media_svc_sql_rollback_trans(handle);
+ return ret;
+ }
+
+ ret = _media_svc_sql_end_trans(handle);
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback\n");
+ _media_svc_sql_rollback_trans(handle);
+ return ret;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_get_media_id_by_path(sqlite3 *handle, const char *path, char *media_uuid, int max_length)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3_stmt *sql_stmt = NULL;
+ char *sql = sqlite3_mprintf("SELECT media_uuid FROM %s WHERE validity=1 AND path='%q'",
+ MEDIA_SVC_DB_TABLE_MEDIA, path);
+
+ ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("error when __media_svc_count_invalid_records_with_thumbnail. err = [%d]", ret);
+ return ret;
+ }
+
+ strncpy(media_uuid, (const char*)sqlite3_column_text(sql_stmt, 0), max_length);
+ media_uuid[max_length - 1] = '\0';
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ return MEDIA_INFO_ERROR_NONE;
+
+}
diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c
new file mode 100755
index 0000000..a6160b6
--- /dev/null
+++ b/src/common/media-svc-util.c
@@ -0,0 +1,1953 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+#include <sys/vfs.h>
+#include <glib/gstdio.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <dirent.h>
+#include <ctype.h>
+#include <errno.h>
+#include <drm_client.h>
+#include <mm_file.h>
+#include <mm_error.h>
+#include <libexif/exif-data.h>
+#include <media-thumbnail.h>
+#include <media-util.h>
+#include "uuid.h"
+#include "media-svc-util.h"
+#include "media-svc-error.h"
+#include "media-svc-debug.h"
+#include "media-svc-env.h"
+#include "media-svc-hash.h"
+#include "media-svc-album.h"
+
+
+#define MEDIA_SVC_FILE_EXT_LEN_MAX 6 /**< Maximum file ext lenth*/
+
+typedef enum {
+ MEDIA_SVC_EXTRACTED_FIELD_NONE = 0x00000001,
+ MEDIA_SVC_EXTRACTED_FIELD_TITLE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 1,
+ MEDIA_SVC_EXTRACTED_FIELD_DESC = MEDIA_SVC_EXTRACTED_FIELD_NONE << 2,
+ MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT = MEDIA_SVC_EXTRACTED_FIELD_NONE << 3,
+ MEDIA_SVC_EXTRACTED_FIELD_AUTHOR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 4,
+ MEDIA_SVC_EXTRACTED_FIELD_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 5,
+ MEDIA_SVC_EXTRACTED_FIELD_GENRE = MEDIA_SVC_EXTRACTED_FIELD_NONE << 6,
+ MEDIA_SVC_EXTRACTED_FIELD_ALBUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 7,
+ MEDIA_SVC_EXTRACTED_FIELD_TRACKNUM = MEDIA_SVC_EXTRACTED_FIELD_NONE << 8,
+ MEDIA_SVC_EXTRACTED_FIELD_YEAR = MEDIA_SVC_EXTRACTED_FIELD_NONE << 9,
+ MEDIA_SVC_EXTRACTED_FIELD_CATEGORY = MEDIA_SVC_EXTRACTED_FIELD_NONE << 10,
+} media_svc_extracted_field_e;
+
+#if 0
+static char *__year_2_str(int year);
+
+static char *__year_2_str(int year)
+{
+ static char ret[MEDIA_SVC_METADATA_LEN_MAX];
+
+ if (year == -1 || year == 0) {
+ _strncpy_safe(ret, MEDIA_SVC_TAG_UNKNOWN, MEDIA_SVC_METADATA_LEN_MAX);
+ } else {
+ snprintf(ret, MEDIA_SVC_METADATA_LEN_MAX - 1, "%d", year);
+ }
+ return ret;
+}
+#endif
+
+char *_media_info_generate_uuid(void)
+{
+ uuid_t uuid_value;
+ static char uuid_unparsed[50];
+
+ uuid_generate(uuid_value);
+ uuid_unparse(uuid_value, uuid_unparsed);
+
+ //media_svc_debug("UUID : %s", uuid_unparsed);
+ return uuid_unparsed;
+}
+
+void _strncpy_safe(char *x_dst, const char *x_src, int max_len)
+{
+ if (!x_src || strlen(x_src) == 0) {
+ media_svc_error("x_src is NULL");
+ return;
+ }
+
+ if (max_len < 1) {
+ media_svc_error("length is Wrong");
+ return;
+ }
+
+ strncpy(x_dst, x_src, max_len-1);
+ x_dst[max_len-1] = '\0';
+}
+
+int __media_svc_malloc_and_strncpy(char **dst, const char *src)
+{
+ int len = 0;
+
+ if (!STRING_VALID(src)) {
+ media_svc_error("invalid src");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ SAFE_FREE(*dst);
+
+ len = strlen(src) + 1;
+ *dst = malloc(len);
+
+ if (*dst == NULL) {
+ media_svc_error("malloc failed");
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ strncpy(*dst, src, len);
+ char *p = *dst;
+ p[len - 1] = '\0';
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+static void __media_svc_split_to_double(char *input, double *arr, int *num)
+{
+ char tmp_arr[255] = { 0, };
+ int len = strlen(input);
+ int i = 0, idx = 0, tmp_idx = 0;
+ int is_prev_space = 0;
+
+ for (;;) {
+ if (input[len - 1] == ' ') {
+ len--;
+ } else {
+ break;
+ }
+ }
+
+ for (i = 0; i < len; i++) {
+ if (idx > 2) {
+ break;
+ }
+
+ if (input[i] == ' ') {
+ if (is_prev_space == 1) {
+ continue;
+ }
+ if (idx <= 2) {
+ arr[idx++] = atof(tmp_arr);
+ }
+ tmp_idx = 0;
+ is_prev_space = 1;
+ continue;
+ }
+
+ tmp_arr[tmp_idx] = input[i];
+ tmp_arr[++tmp_idx] = '\0';
+ is_prev_space = 0;
+ }
+
+ if (i == len) {
+ if (idx <= 2) {
+ arr[idx++] = atof(tmp_arr);
+ }
+ *num = idx;
+ return;
+ } else {
+ *num = idx--;
+ return;
+ }
+}
+
+static int __media_svc_get_exif_info(ExifData *ed,
+ char *buf,
+ int *i_value,
+ double *d_value,
+ int ifdtype,
+ long tagtype)
+{
+ ExifEntry *entry;
+ ExifIfd ifd;
+ ExifTag tag;
+
+ if (ed == NULL) {
+ //media_svc_debug("ExifData is NULL");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ ifd = ifdtype;
+ tag = tagtype;
+
+ entry = exif_data_get_entry(ed, tag);
+ if (entry) {
+ /* Get the contents of the tag in human-readable form */
+ if (tag == EXIF_TAG_ORIENTATION ||
+ tag == EXIF_TAG_PIXEL_X_DIMENSION ||
+ tag == EXIF_TAG_PIXEL_Y_DIMENSION) {
+
+ if (i_value == NULL) {
+ media_svc_error("i_value is NULL");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ ExifByteOrder mByteOrder = exif_data_get_byte_order(ed);
+ short exif_value = exif_get_short(entry->data, mByteOrder);
+ //media_svc_debug("%s : %d", exif_tag_get_name_in_ifd(tag,ifd), exif_value);
+ *i_value = (int)exif_value;
+
+ } else if (tag == EXIF_TAG_GPS_LATITUDE || tag == EXIF_TAG_GPS_LONGITUDE || tag == EXIF_TAG_GPS_ALTITUDE) {
+
+ if (d_value == NULL) {
+ media_svc_error("d_value is NULL");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ /* Get the contents of the tag in human-readable form */
+ char gps_buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
+ exif_entry_get_value(entry, gps_buf, sizeof(gps_buf));
+ gps_buf[strlen(gps_buf)] = '\0';
+
+ //media_svc_debug("%s: %s\n", exif_tag_get_name_in_ifd(tag, ifd), gps_buf);
+
+ double tmp_arr[3] = { 0.0, 0.0, 0.0 };
+ int count = 0;
+
+ __media_svc_split_to_double(gps_buf, tmp_arr, &count);
+ if (count != 3) {
+ media_svc_error("Value is invalid");
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ *d_value = tmp_arr[0] + tmp_arr[1] / 60 + tmp_arr[2] / 3600;
+ //media_svc_debug("GPS value is %f", *d_value);
+ } else {
+
+ if (buf == NULL) {
+ media_svc_error("buf is NULL");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ exif_entry_get_value(entry, buf, MEDIA_SVC_METADATA_LEN_MAX);
+ buf[strlen(buf)] = '\0';
+
+ if (*buf) {
+ media_svc_debug("%s: %s\n", exif_tag_get_name_in_ifd(tag, ifd), buf);
+ }
+ }
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+unsigned int _media_svc_get_current_time(void)
+{
+ struct timeval t;
+ unsigned int tval = 0;
+ gettimeofday(&t, NULL);
+
+ tval = t.tv_sec*1000000L + t.tv_usec;
+
+ return tval/1000;
+}
+
+int _media_svc_check_escape_char(char ch)
+{
+ int i;
+ char escape_char[3] = {'%', '_' ,'#'};
+
+ for (i = 0; i < 3; i++) {
+ if (ch == escape_char[i]) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+char *_media_svc_escape_str(char *input, int len)
+{
+ int i = 0;
+ int j = 0;
+ char *result = NULL;
+
+ result = (char*)malloc(len * 2 * sizeof(char) + 1);
+ if (result == NULL) {
+ return NULL;
+ }
+
+ for (i = 0; i < len; i++, j++) {
+ if (input[i] == '\0') break;
+
+ if (_media_svc_check_escape_char(input[i])) {
+ result[j] = '#';
+ result[++j] = input[i];
+ } else {
+ result[j] = input[i];
+ }
+ }
+
+ result[j] = '\0';
+
+ return result;
+}
+
+int _media_svc_rename_file( const char *old_name, const char *new_name)
+{
+ if((old_name == NULL) || (new_name == NULL))
+ {
+ media_svc_error("invalid file name");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ if (rename(old_name, new_name) < 0) {
+ media_svc_error("Old : [%s] New : [%s] errno : [%s]", old_name, new_name, strerror(errno));
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+bool _media_svc_remove_file(const char *path)
+{
+ int result = -1;
+
+ result = remove(path);
+ if (result == 0) {
+ media_svc_debug("success to remove file");
+ return TRUE;
+ } else {
+ media_svc_error("fail to remove file result errno = %s", strerror(errno));
+ return FALSE;
+ }
+}
+
+int _media_svc_remove_all_files_in_dir(const char *dir_path)
+{
+ struct dirent *entry = NULL;
+ struct stat st;
+ char filename[MEDIA_SVC_PATHNAME_SIZE] = {0};
+ DIR *dir = NULL;
+
+ dir = opendir(dir_path);
+ if (dir == NULL) {
+ media_svc_error("%s is not exist", dir_path);
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ while ((entry = readdir(dir)) != NULL) {
+ if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
+ continue;
+ }
+ snprintf(filename, sizeof(filename), "%s/%s", dir_path, entry->d_name);
+
+ if (stat(filename, &st) != 0) {
+ continue;
+ }
+ if (S_ISDIR(st.st_mode)) {
+ continue;
+ }
+ if (unlink(filename) != 0) {
+ media_svc_error("failed to remove : %s", filename);
+ closedir(dir);
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+ }
+
+ closedir(dir);
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+char *_media_svc_get_title_from_filepath (const char *path)
+{
+ char *filename = NULL;
+ char *title = NULL;
+ char *ext = NULL;
+ int filename_len = -1;
+ int new_title_len = -1;
+
+ if (!path) {
+ media_svc_error("path is NULL");
+ return NULL;
+ }
+
+ filename = g_path_get_basename(path);
+ if (!STRING_VALID(filename)) {
+ media_svc_error("wrong file name");
+ SAFE_FREE(filename);
+ return NULL;
+ }
+
+ filename_len = strlen(filename);
+
+ ext = g_strrstr(filename, ".");
+ if (!ext) {
+ media_svc_error("there is no file extention");
+ return filename;
+ }
+
+ new_title_len = filename_len - strlen(ext);
+ if (new_title_len < 1) {
+ media_svc_error("title length is zero");
+ SAFE_FREE(filename);
+ return NULL;
+ }
+
+ title = g_strndup(filename, new_title_len < MEDIA_SVC_PATHNAME_SIZE ? new_title_len : MEDIA_SVC_PATHNAME_SIZE-1);
+
+ SAFE_FREE(filename);
+
+ media_svc_debug("extract title is [%s]", title);
+
+ return title;
+}
+
+int _media_svc_save_image(void *image, int size, char *image_path)
+{
+ media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
+
+ if (!image) {
+ media_svc_error("invalid image..");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ struct statfs fs;
+ if (-1 == statfs(MEDIA_SVC_THUMB_PATH_PREFIX, &fs)) {
+ media_svc_error("error in statfs");
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ long bsize_kbytes = fs.f_bsize >> 10;
+
+ if ((bsize_kbytes * fs.f_bavail) < 1024) {
+ media_svc_error("not enought space...");
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ FILE *fp = NULL;
+ int nwrite = -1;
+ if (image != NULL && size > 0) {
+ fp = fopen(image_path, "w");
+
+ if (fp == NULL) {
+ media_svc_error("failed to open file");
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ nwrite = fwrite(image, 1, size, fp);
+ if (nwrite != size) {
+ media_svc_error("failed to write thumbnail");
+ fclose(fp);
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+ fclose(fp);
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format)
+{
+ char savename[MEDIA_SVC_PATHNAME_SIZE] = {0};
+ char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0};
+ char *thumb_dir = NULL;
+ char hash[255 + 1];
+ char *thumbfile_ext = NULL;
+
+ thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? MEDIA_SVC_THUMB_INTERNAL_PATH : MEDIA_SVC_THUMB_EXTERNAL_PATH;
+
+ memset(file_ext, 0, sizeof(file_ext));
+ if (!_media_svc_get_file_ext(pathname, file_ext)) {
+ media_svc_error("get file ext fail");
+ }
+
+ int err = -1;
+ err = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
+ if (err < 0) {
+ media_svc_error("mb_svc_generate_hash_code failed : %d", err);
+ return FALSE;
+ }
+
+ //media_svc_debug("img format is [%s]", img_format);
+
+ if((strstr(img_format, "jpeg") != NULL) ||(strstr(img_format, "jpg") != NULL) ||(strstr(img_format, "JPG") != NULL)) {
+ thumbfile_ext = "jpg";
+ } else if((strstr(img_format, "png") != NULL) ||(strstr(img_format, "PNG") != NULL)) {
+ thumbfile_ext = "png";
+ } else if((strstr(img_format, "gif") != NULL) ||(strstr(img_format, "GIF") != NULL)) {
+ thumbfile_ext = "gif";
+ } else if((strstr(img_format, "bmp") != NULL) ||(strstr(img_format, "BMP") != NULL)) {
+ thumbfile_ext = "bmp";
+ } else {
+ media_svc_error("Not proper img format");
+ return FALSE;
+ }
+
+ snprintf(savename, sizeof(savename), "%s/.%s-%s.%s", thumb_dir, file_ext, hash, thumbfile_ext);
+ _strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
+ //media_svc_debug("thumb_path is [%s]", thumb_path);
+
+ return TRUE;
+}
+
+bool _media_svc_get_file_ext(const char *file_path, char *file_ext)
+{
+ int i = 0;
+
+ for (i = strlen(file_path); i >= 0; i--) {
+ if (file_path[i] == '.') {
+ _strncpy_safe(file_ext, &file_path[i+1], MEDIA_SVC_FILE_EXT_LEN_MAX);
+ return true;
+ }
+
+ if (file_path[i] == '/') {
+ return false;
+ }
+ }
+ return false;
+}
+
+int _media_svc_get_file_time(const char *full_path)
+{
+ struct stat statbuf;
+ int fd = 0;
+
+ memset(&statbuf, 0, sizeof(struct stat));
+ fd = stat(full_path, &statbuf);
+ if (fd == -1) {
+ media_svc_error("stat(%s) fails.", full_path);
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ return statbuf.st_mtime;
+}
+
+int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_storage_type_e storage_type,
+ const char *path, const char *mime_type, media_svc_media_type_e media_type, bool refresh)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ char * media_uuid = NULL;
+ char * file_name = NULL;
+ struct stat st;
+ drm_bool_type_e drm_type;
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->path, path);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
+
+ memset(&st, 0, sizeof(struct stat));
+ if (stat(path, &st) == 0) {
+ content_info->modified_time = st.st_mtime;
+ content_info->size = st.st_size;
+ //media_svc_debug("Modified time : [%d] Size : [%lld]", content_info->modified_time, content_info->size);
+ } else {
+ media_svc_error("stat failed : %s", strerror(errno));
+ }
+
+ /* Set default GPS value before extracting meta information */
+ content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+
+ /* Set default value before extracting meta information */
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
+
+ /* refresh is TRUE when file modified. so only modified_time and size are changed*/
+ if(refresh) {
+ media_svc_debug("refresh");
+ return MEDIA_INFO_ERROR_NONE;
+ }
+
+ content_info->media_type = media_type;
+ content_info->storage_type = storage_type;
+ time(&content_info->added_time);
+
+ media_uuid = _media_info_generate_uuid();
+ media_svc_retvm_if(media_uuid == NULL, MEDIA_INFO_ERROR_INTERNAL, "Invalid UUID");
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_uuid, media_uuid);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->mime_type, mime_type);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
+
+ file_name = g_path_get_basename(path);
+ ret = __media_svc_malloc_and_strncpy(&content_info->file_name, file_name);
+ SAFE_FREE(file_name);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, content_info);
+
+ ret = drm_is_drm_file(content_info->path, &drm_type);
+ if (ret < 0) {
+ media_svc_error("drm_is_drm_file falied : %d", ret);
+ drm_type = DRM_FALSE;
+ }
+
+ content_info->is_drm = drm_type;
+
+ content_info->played_count = 0;
+ content_info->last_played_time= 0;
+ content_info->last_played_position= 0;
+ content_info->favourate= 0;
+ content_info->media_meta.rating = 0;
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
+{
+ if (content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE) {
+ media_svc_error("content_info == NULL || media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ char buf[MEDIA_SVC_METADATA_LEN_MAX + 1] = { '\0' };
+ char description_buf[MEDIA_SVC_METADATA_DESCRIPTION_MAX + 1] = { '\0' };
+ memset(buf, 0x00, sizeof(buf));
+ memset(description_buf, 0x00, sizeof(description_buf));
+
+ int ret = MEDIA_INFO_ERROR_NONE;
+ double value = 0.0;
+ int orient_value = 0;
+ int exif_width = 0;
+ int exif_height = 0;
+ ExifData *ed = NULL;
+
+ char *path = content_info->path;
+ if (path == NULL) {
+ media_svc_error("path is NULL");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ /* Load an ExifData object from an EXIF file */
+ ed = exif_data_new_from_file(path);
+
+ if (!ed) {
+ media_svc_debug("There is no exif data in [ %s ]", path);
+ }
+
+ if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_GPS_LATITUDE_REF) == MEDIA_INFO_ERROR_NONE) {
+ if (strlen(buf) != 0) {
+ if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LATITUDE) == MEDIA_INFO_ERROR_NONE) {
+
+ if (strcmp(buf, "S") == 0) {
+ value = -1 * value;
+ }
+
+ content_info->media_meta.latitude = value;
+ } else {
+ content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ }
+ } else {
+ content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ }
+ } else {
+ content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ }
+
+ memset(buf, 0x00, sizeof(buf));
+
+ if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_GPS_LONGITUDE_REF) == MEDIA_INFO_ERROR_NONE) {
+ if (strlen(buf) != 0) {
+ if (__media_svc_get_exif_info(ed, NULL, NULL, &value, EXIF_IFD_GPS, EXIF_TAG_GPS_LONGITUDE) == MEDIA_INFO_ERROR_NONE) {
+ if (strcmp(buf, "W") == 0) {
+ value = -1 * value;
+ }
+ content_info->media_meta.longitude = value;
+ } else {
+ content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ }
+ } else {
+ content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ }
+ } else {
+ content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ }
+
+ memset(buf, 0x00, sizeof(buf));
+
+ if (__media_svc_get_exif_info(ed, description_buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_IMAGE_DESCRIPTION) == MEDIA_INFO_ERROR_NONE) {
+ if (strlen(description_buf) == 0) {
+ //media_svc_debug("Use 'No description'");
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_error("strcpy error");
+ } else {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, description_buf);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ }
+ } else {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, MEDIA_SVC_TAG_UNKNOWN);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ }
+
+ memset(buf, 0x00, sizeof(buf));
+
+ if (__media_svc_get_exif_info(ed, buf, NULL, NULL, EXIF_IFD_0, EXIF_TAG_DATE_TIME) == MEDIA_INFO_ERROR_NONE) {
+ if (strlen(buf) == 0) {
+ //media_svc_debug("time is NULL");
+ } else {
+ //media_svc_debug("time is %s", buf);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.datetaken, buf);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ }
+ }
+
+ /* Get orientation value from exif. */
+ if (__media_svc_get_exif_info(ed, NULL, &orient_value, NULL, EXIF_IFD_0, EXIF_TAG_ORIENTATION) == MEDIA_INFO_ERROR_NONE) {
+ if (orient_value >= NOT_AVAILABLE && orient_value <= ROT_270) {
+ content_info->media_meta.orientation = orient_value;
+ } else {
+ content_info->media_meta.orientation = 0;
+ }
+ } else {
+ content_info->media_meta.orientation = 0;
+ }
+
+ /* Get width value from exif. */
+ if (__media_svc_get_exif_info(ed, NULL, &exif_width, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_X_DIMENSION) == MEDIA_INFO_ERROR_NONE) {
+ if (exif_width > 0) {
+ content_info->media_meta.width = exif_width;
+ } else {
+ content_info->media_meta.width = 0;
+ }
+ } else {
+ content_info->media_meta.width = 0;
+ }
+
+ /* Get height value from exif. */
+ if (__media_svc_get_exif_info(ed, NULL, &exif_height, NULL, EXIF_IFD_EXIF, EXIF_TAG_PIXEL_Y_DIMENSION) == MEDIA_INFO_ERROR_NONE) {
+ if (exif_height > 0) {
+ content_info->media_meta.height = exif_height;
+ } else {
+ content_info->media_meta.height = 0;
+ }
+ } else {
+ content_info->media_meta.height = 0;
+ }
+
+ if (ed != NULL) exif_data_unref(ed);
+#if 0
+ /* Extracting thumbnail */
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
+ int width = 0;
+ int height = 0;
+
+ ret = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height);
+ if (ret < 0) {
+ media_svc_error("thumbnail_request_from_db failed: %d", ret);
+ } else {
+ //media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
+ }
+
+ content_info->media_meta.width = width;
+ content_info->media_meta.height = height;
+
+ if (STRING_VALID(thumb_path))
+ ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
+ else
+ content_info->thumbnail_path = NULL;
+
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+#endif
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type)
+{
+ MMHandleType content = 0;
+ MMHandleType tag = 0;
+ char *p = NULL;
+ void *image = NULL;
+ int size = -1;
+ int extracted_field = MEDIA_SVC_EXTRACTED_FIELD_NONE;
+ int mmf_error = MM_ERROR_NONE;
+ bool thumb_extracted_from_drm = FALSE;
+ char *err_attr_name = NULL;
+ char *title = NULL;
+ bool extract_thumbnail = FALSE;
+ bool append_album = FALSE;
+ int album_id = 0;
+ double gps_value = 0.0;
+ int ret = MEDIA_INFO_ERROR_NONE;
+ drm_bool_type_e drm_type;
+ char *path = content_info->path;
+
+ ret = drm_is_drm_file(path, &drm_type);
+ if (ret < 0) {
+ media_svc_error("drm_is_drm_file falied : %d", ret);
+ drm_type = DRM_FALSE;
+ }
+
+ /*To do - code for DRM content*/
+ if (drm_type) {
+ bool invalid_file = FALSE;
+ drm_file_type_e drm_file_type;
+ drm_permission_type_e drm_perm_type = DRM_PERMISSION_TYPE_PLAY;
+ drm_content_info_s contentInfo;
+ drm_license_status_e license_status;
+ memset(&contentInfo, 0x00, sizeof(drm_content_info_s));
+
+ ret = drm_get_file_type(path, &drm_file_type);
+ if (ret < 0) {
+ media_svc_error("drm_get_file_type falied : %d", ret);
+ drm_file_type = DRM_TYPE_UNDEFINED;
+ invalid_file = TRUE;
+ }
+
+ ret = drm_get_content_info(path, &contentInfo);
+ if (ret != DRM_RETURN_SUCCESS) {
+ media_svc_error("drm_get_content_info() fails. : %d", ret);
+ invalid_file = TRUE;
+ }
+
+ ret = drm_get_license_status(path, drm_perm_type, &license_status);
+ if (ret != DRM_RETURN_SUCCESS) {
+ media_svc_error("drm_get_license_status() fails. : %d", ret);
+ invalid_file = TRUE;
+ }
+
+ if ((!invalid_file) && (license_status != DRM_LICENSE_STATUS_VALID)) {
+ invalid_file = TRUE;
+ if (drm_file_type == DRM_TYPE_OMA_V1) {
+
+ if (strlen(contentInfo.title) > 0) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, contentInfo.title);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
+ }
+
+ if (strlen(contentInfo.description) > 0) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, contentInfo.description);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
+ }
+ } else if (drm_file_type == DRM_TYPE_OMA_V2) {
+ if (strlen(contentInfo.title) > 0) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, contentInfo.title);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
+ }
+
+ if (strlen(contentInfo.description) > 0) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, contentInfo.description);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
+ }
+
+ if (strlen(contentInfo.copyright) > 0) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, contentInfo.copyright);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT;
+ }
+
+ if (strlen(contentInfo.author) > 0) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, contentInfo.author);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, contentInfo.author);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_ARTIST;
+ }
+ }
+ }
+
+ if (invalid_file) {
+ if (!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) {
+ title = _media_svc_get_title_from_filepath(path);
+ if (title) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
+ SAFE_FREE(title);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ } else {
+ media_svc_error("Can't extract title from filepath [%s]", content_info->path);
+ }
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+ }
+ }
+
+#if 0
+ if (drm_svc_is_drm_file(content_info->path)) {
+ bool invalid_file = FALSE;
+
+ DRM_FILE_TYPE type = drm_svc_get_drm_type(content_info->path);
+
+ if (type == DRM_FILE_TYPE_OMA) {
+ drm_dcf_header_t header_info;
+ memset(&header_info, 0, sizeof(drm_dcf_header_t));
+ media_svc_debug("drm type is OMA");
+
+ if (drm_svc_get_dcf_header_info(content_info->path, &header_info) != DRM_RESULT_SUCCESS) {
+ media_svc_debug("cannot get dcf header info. just get the title");
+ title = _media_svc_get_title_from_filepath(content_info->path);
+ if (title) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
+ SAFE_FREE(title);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
+ } else {
+ media_svc_error("Can't extract title from filepath [%s]", content_info->path);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ }
+
+/*
+ _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
+ _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
+ _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
+ _strncpy_safe(content_info->media_meta.author, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.author));
+ _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
+*/
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ return MEDIA_INFO_ERROR_NONE;
+ }
+
+ if (drm_svc_has_valid_ro(content_info->path, DRM_PERMISSION_PLAY) != DRM_RESULT_SUCCESS) {
+ media_svc_debug("no valid ro. can't extract meta data");
+ invalid_file = TRUE;
+ }
+
+ if (header_info.version == DRM_OMA_DRMV1_RIGHTS) {
+ media_svc_debug("DRM V1");
+ if (invalid_file) {
+
+ if (strlen(header_info.headerUnion.headerV1.contentName) > 0) {
+
+ //_strncpy_safe(content_info->media_meta.title, header_info.headerUnion.headerV1.contentName, sizeof(content_info->media_meta.title));
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, header_info.headerUnion.headerV1.contentName);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
+ media_svc_debug("extract title from DCF");
+ }
+
+ if (strlen(header_info.headerUnion.headerV1.contentDescription) > 0) {
+ //_strncpy_safe(content_info->media_meta.description, header_info.headerUnion.headerV1.contentDescription, sizeof(content_info->media_meta.description));
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, header_info.headerUnion.headerV1.contentDescription);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
+ media_svc_debug("extract description from DCF");
+ }
+ }
+ } else if (header_info.version == DRM_OMA_DRMV2_RIGHTS) {
+ drm_user_data_common_t metadata;
+ int type_index = -1;
+
+ media_svc_debug("DRM V2");
+
+ if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_TITLE, &metadata) == DRM_RESULT_SUCCESS) {
+ //_strncpy_safe(content_info->media_meta.title, metadata.subBox.title.str, sizeof(content_info->media_meta.title));
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, metadata.subBox.title.str);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
+ media_svc_debug("extract title from odf");
+ }
+
+ if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_DESCRIPTION, &metadata) == DRM_RESULT_SUCCESS) {
+ //_strncpy_safe(content_info->media_meta.description, metadata.subBox.desc.str, sizeof(content_info->media_meta.description));
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, metadata.subBox.desc.str);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_DESC;
+ }
+
+ if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_COPYRIGHT, &metadata) == DRM_RESULT_SUCCESS) {
+ //_strncpy_safe(content_info->media_meta.copyright, metadata.subBox.copyright.str, sizeof(content_info->media_meta.copyright));
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, metadata.subBox.copyright.str);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT;
+ }
+
+ if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_AUTHOR, &metadata) == DRM_RESULT_SUCCESS) {
+ //_strncpy_safe(content_info->media_meta.composer, metadata.subBox.author.str, sizeof(content_info->media_meta.composer));
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, metadata.subBox.author.str);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
+ }
+
+ if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_PERFORMER, &metadata) == DRM_RESULT_SUCCESS) {
+ //_strncpy_safe(content_info->media_meta.artist, metadata.subBox.performer.str, sizeof(content_info->media_meta.artist));
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, metadata.subBox.performer.str);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_ARTIST;
+ }
+
+ if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_GENRE, &metadata) == DRM_RESULT_SUCCESS) {
+ //_strncpy_safe(content_info->media_meta.genre, metadata.subBox.genre.str, sizeof(content_info->media_meta.genre));
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, metadata.subBox.genre.str);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ media_svc_debug("genre : %s", content_info->media_meta.genre);
+ if ((strcasecmp("Ringtone", metadata.subBox.genre.str) == 0) | (strcasecmp("Alert tone", metadata.subBox.genre.str) == 0)) {
+ content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
+ }
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_GENRE;
+ }
+
+ if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_ALBUM, &metadata) == DRM_RESULT_SUCCESS) {
+ //_strncpy_safe(content_info->media_meta.album, metadata.subBox.album.albumTitle, sizeof(content_info->media_meta.album));
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, metadata.subBox.album.albumTitle);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_ALBUM;
+
+ char track_num[MEDIA_SVC_METADATA_LEN_MAX] = {0,};
+ snprintf(track_num, sizeof(track_num), "%d", metadata.subBox.album.trackNum);
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, track_num);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ //snprintf(content_info->media_meta.track_num, MEDIA_SVC_METADATA_LEN_MAX, "%d", metadata.subBox.album.trackNum);
+ }
+
+ if (drm_svc_get_user_data_box_info(content_info->path, DRM_UDTA_RECODINGYEAR, &metadata) == DRM_RESULT_SUCCESS) {
+ //_strncpy_safe(content_info->media_meta.year, __year_2_str(metadata.subBox.recodingYear.recodingYear), sizeof(content_info->media_meta.year));
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, __year_2_str(metadata.subBox.recodingYear.recodingYear));
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_YEAR;
+ }
+
+ if (drm_svc_get_index_of_relative_contents(content_info->path, DRM_CONTENTS_INDEX_ALBUMJACKET, &type_index) == DRM_RESULT_SUCCESS) {
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE+1] = {0};
+
+ if (drm_svc_make_multipart_drm_full_path(content_info->path, type_index, MEDIA_SVC_PATHNAME_SIZE, thumb_path) == DRM_TRUE) {
+
+ DRM_FILE_HANDLE hFile = DRM_HANDLE_NULL;
+
+ media_svc_debug("drm image path : %s", thumb_path);
+
+ if (drm_svc_open_file(thumb_path, DRM_PERMISSION_ANY, &hFile) == DRM_RESULT_SUCCESS) {
+ int thumb_size = 0;
+
+ if (drm_svc_seek_file(hFile, 0, DRM_SEEK_END) != DRM_RESULT_SUCCESS) {
+ goto DRM_SEEK_ERROR;
+ }
+ thumb_size = drm_svc_tell_file(hFile);
+
+ if (drm_svc_seek_file(hFile, 0, DRM_SEEK_SET) != DRM_RESULT_SUCCESS) {
+ goto DRM_SEEK_ERROR;
+ }
+ /* remove thumbnail extract routine in db creating time.
+ media_svc_debug("drm thumb size : %d", thumb_size);
+ if (thumb_size > 0) {
+ unsigned int readSize = 0;
+
+ thumb_buffer = malloc(thumb_size);
+ if (drm_svc_read_file(hFile, thumb_buffer,thumb_size, &readSize) != DRM_RESULT_SUCCESS) {
+ SAFE_FREE(thumb_buffer);
+ goto DRM_SEEK_ERROR;
+ }
+
+ __save_thumbnail(thumb_buffer, readSize, 1, content_info);
+ SAFE_FREE(thumb_buffer);
+ thumb_extracted_from_drm = TRUE;
+ }
+ */
+ DRM_SEEK_ERROR:
+ drm_svc_free_dcf_header_info(&header_info);
+ drm_svc_close_file(hFile);
+ }
+ }
+ }
+ } else {
+ media_svc_debug("unsupported drm format");
+ drm_svc_free_dcf_header_info(&header_info);
+ title = _media_svc_get_title_from_filepath(content_info->path);
+ if (title) {
+ //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
+ SAFE_FREE(title);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ } else {
+ media_svc_error("Can't extract title from filepath [%s]", content_info->path);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ }
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+/*
+ _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
+ _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
+ _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
+ _strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
+ _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
+*/
+ return MEDIA_INFO_ERROR_NONE;
+ }
+
+ if (invalid_file == TRUE) {
+ if (!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) {
+ title = _media_svc_get_title_from_filepath(content_info->path);
+ if (title) {
+ //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
+ SAFE_FREE(title);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
+ } else {
+ media_svc_error("Can't extract title from filepath");
+ drm_svc_free_dcf_header_info(&header_info);
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+/*
+ _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
+ _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
+ _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
+ _strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
+ _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
+*/
+ }
+
+ drm_svc_free_dcf_header_info(&header_info);
+ return MEDIA_INFO_ERROR_NONE;
+ }
+ } else if (type == DRM_FILE_TYPE_PLAYREADY) {
+ media_svc_debug("drm type is PLAYREADY");
+ if (drm_svc_has_valid_ro(content_info->path, DRM_PERMISSION_PLAY) != DRM_RESULT_SUCCESS) {
+ media_svc_debug("no valid ro. can't extract meta data");
+ title = _media_svc_get_title_from_filepath(content_info->path);
+ if (title) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
+ SAFE_FREE(title);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
+ } else {
+ media_svc_error("Can't extract title from filepath [%s]", content_info->path);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ }
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+/*
+ _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
+ _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
+ _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
+ _strncpy_safe(content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.composer));
+ _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
+*/
+
+ return MEDIA_INFO_ERROR_NONE;
+ }
+ } else {
+ media_svc_error("Not supported DRM type");
+ title = _media_svc_get_title_from_filepath(content_info->path);
+ if (title) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
+ SAFE_FREE(title);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ //_strncpy_safe(content_info->media_meta.title, title, sizeof(content_info->media_meta.title));
+ } else {
+ media_svc_error("Can't extract title from filepath [%s]", content_info->path);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ }
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN);
+ media_svc_retv_del_if(ret < 0, ret, content_info);
+/*
+ _strncpy_safe(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.album));
+ _strncpy_safe(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.artist));
+ _strncpy_safe(content_info->media_meta.genre, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.genre));
+ _strncpy_safe(content_info->media_meta.author, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.author));
+ _strncpy_safe(content_info->media_meta.year, MEDIA_SVC_TAG_UNKNOWN, sizeof(content_info->media_meta.year));
+*/
+ return MEDIA_INFO_ERROR_NONE;
+ }
+ }
+#endif
+ /*Get Content attribute ===========*/
+ mmf_error = mm_file_create_content_attrs(&content, content_info->path);
+ if (mmf_error == MM_ERROR_NONE) {
+ /*Common attribute*/
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_DURATION, &content_info->media_meta.duration, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get duration attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("duration : %d", content_info->media_meta.duration);
+ }
+
+ /*Sound/Music attribute*/
+ if((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) || (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &content_info->media_meta.bitrate, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("bit rate : %d", content_info->media_meta.bitrate);
+ }
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_SAMPLERATE, &content_info->media_meta.samplerate, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get sample rate attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("sample rate : %d", content_info->media_meta.samplerate);
+ }
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_CHANNELS, &content_info->media_meta.channel, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get audio channels attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("channel : %d", content_info->media_meta.channel);
+ }
+ }else if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { /*Video attribute*/
+ int audio_bitrate = 0;
+ int video_bitrate = 0;
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_AUDIO_BITRATE, &audio_bitrate, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("audio bit rate : %d", audio_bitrate);
+ }
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_BITRATE, &video_bitrate, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get audio bitrate attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("video bit rate : %d", video_bitrate);
+ }
+
+ content_info->media_meta.bitrate = audio_bitrate + video_bitrate;
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_WIDTH, &content_info->media_meta.width, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get video width attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("width : %d", content_info->media_meta.width);
+ }
+
+ mmf_error = mm_file_get_attrs(content, &err_attr_name, MM_FILE_CONTENT_VIDEO_HEIGHT, &content_info->media_meta.height, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ SAFE_FREE(err_attr_name);
+ media_svc_debug("fail to get video height attr - err(%x)", mmf_error);
+ } else {
+ //media_svc_debug("height : %d", content_info->media_meta.height);
+ }
+
+ } else {
+ media_svc_error("Not support type");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ mmf_error = mm_file_destroy_content_attrs(content);
+ if (mmf_error != MM_ERROR_NONE) {
+ media_svc_error("fail to free content attr - err(%x)", mmf_error);
+ }
+ } else {
+ media_svc_error("error in mm_file_create_content_attrs [%d]", mmf_error);
+ }
+
+ /*Get Content Tag attribute ===========*/
+ mmf_error = mm_file_create_tag_attrs(&tag, content_info->path);
+
+ if (mmf_error == MM_ERROR_NONE) {
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALBUM, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ALBUM)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.album, p);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+
+ //media_svc_debug("album[%d] : %s", size, content_info->media_meta.album);
+ } else {
+ SAFE_FREE(err_attr_name);
+ //media_svc_debug("album - unknown");
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTIST, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_ARTIST)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.artist, p);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ //media_svc_debug("artist[%d] : %s", size, content_info->media_meta.artist);
+ } else {
+ SAFE_FREE(err_attr_name);
+ //media_svc_debug("artist - unknown");
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_GENRE, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_GENRE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.genre, p);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+
+ //media_svc_debug("genre : %s", content_info->media_meta.genre);
+ if ((strcasecmp("Ringtone", p) == 0) | (strcasecmp("Alert tone", p) == 0)) {
+ content_info->media_type = MEDIA_SVC_MEDIA_TYPE_SOUND;
+ }
+ } else {
+ SAFE_FREE(err_attr_name);
+ //media_svc_debug("genre - unknown");
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TITLE, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_TITLE)) && (mmf_error == MM_ERROR_NONE) && (size > 0)/* && (!isspace(*p))*/) {
+ if(!isspace(*p)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_TITLE;
+ //media_svc_debug("extract title from content : %s", content_info->media_meta.title);
+ //media_svc_debug("^^^^^^^^^^^^^^^ path = %s, title = %s, size = %d ^^^^^^^^^^^^^^", content_info->path, content_info->media_meta.title, size);
+ }
+ else {
+ int idx = 0;
+
+ for(idx = 0; idx < size; idx++) {
+ if(isspace(*p)) {
+ media_svc_debug("SPACE [%s]", p);
+ p++;
+ continue;
+ } else {
+ media_svc_debug("Not SPACE [%s]", p);
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, p);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ break;
+ }
+ }
+
+ if(idx == size)
+ {
+ media_svc_debug("Can't extract title. All string is space");
+ title = _media_svc_get_title_from_filepath(content_info->path);
+ if (title) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ SAFE_FREE(title);
+ } else {
+ media_svc_error("Can't extract title from filepath [%s]", content_info->path);
+ }
+ }
+ }
+ } else {
+ SAFE_FREE(err_attr_name);
+ title = _media_svc_get_title_from_filepath(content_info->path);
+ if (title) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ SAFE_FREE(title);
+ } else {
+ media_svc_error("Can't extract title from filepath [%s]", content_info->path);
+ }
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DESCRIPTION, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.description, p);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ //media_svc_debug("desc : %s", content_info->media_meta.description);
+ } else {
+ SAFE_FREE(err_attr_name);
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RECDATE, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_DESC)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.recorded_date, p);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ //media_svc_debug("Recorded date : %s", content_info->media_meta.recorded_date);
+ } else {
+ SAFE_FREE(err_attr_name);
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_AUTHOR, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_AUTHOR)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.composer, p);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
+ //media_svc_debug("extract composer from content : %s", content_info->media_meta.composer);
+ } else {
+ //media_svc_debug("composer - unknown");
+ SAFE_FREE(err_attr_name);
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_COPYRIGHT, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_COPYRIGHT)) && (mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.copyright, p);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ extracted_field |= MEDIA_SVC_EXTRACTED_FIELD_AUTHOR;
+ //media_svc_debug("extract copyright from content : %s", content_info->media_meta.copyright);
+ } else {
+ //media_svc_debug("copyright - unknown");
+ SAFE_FREE(err_attr_name);
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_TRACK_NUM, &p, &size, NULL);
+ if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.track_num, p);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ } else {
+ SAFE_FREE(err_attr_name);
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_DATE, &p, &size, NULL);
+ if ((!(extracted_field & MEDIA_SVC_EXTRACTED_FIELD_YEAR)) && (mmf_error == MM_ERROR_NONE) && (size == 4)) {
+ int year = 0;
+ if((p != NULL) && (sscanf( p, "%d", &year))) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.year, p);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ } else {
+ media_svc_debug("Wrong Year Information [%s]", p);
+ }
+ } else {
+ SAFE_FREE(err_attr_name);
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_RATING, &p, &size, NULL);
+ if ((mmf_error == MM_ERROR_NONE) && (size > 0)) {
+ content_info->media_meta.rating = atoi(p);
+ } else {
+ SAFE_FREE(err_attr_name);
+ content_info->media_meta.rating = 0;
+ }
+
+ /*Initialize album_id to 0. below code will set the album_id*/
+ content_info->album_id = album_id;
+#if 0
+ /* extract thumbnail image */
+ if(strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) {
+ if(strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) {
+
+ ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
+ media_svc_debug("album does not exist. So start to make album art");
+ extract_thumbnail = TRUE;
+ append_album = TRUE;
+ } else {
+ extract_thumbnail = FALSE;
+ append_album = FALSE;
+ }
+ } else {
+ media_svc_debug("album already exists. don't need to make album art");
+ content_info->album_id = album_id;
+ ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
+ media_svc_retv_del_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret, content_info);
+ extract_thumbnail = FALSE;
+ append_album = FALSE;
+ }
+ } else {
+ ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
+ media_svc_debug("Unknown artist album does not exist.");
+ extract_thumbnail = TRUE;
+ append_album = TRUE;
+ } else {
+ extract_thumbnail = FALSE;
+ append_album = FALSE;
+ }
+ } else {
+ media_svc_debug("Unknown artist album already exists.");
+
+ content_info->album_id = album_id;
+ extract_thumbnail = TRUE;
+ append_album = FALSE;
+ }
+ }
+ } else {
+ extract_thumbnail = TRUE;
+ append_album = FALSE;
+ }
+#else
+ ret = _media_svc_get_album_id(handle, content_info->media_meta.album, content_info->media_meta.artist, &album_id);
+
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ if (ret == MEDIA_INFO_ERROR_DATABASE_NO_RECORD) {
+ media_svc_debug("album does not exist. So start to make album art");
+ extract_thumbnail = TRUE;
+ append_album = TRUE;
+ } else {
+ extract_thumbnail = FALSE;
+ append_album = FALSE;
+ }
+ } else {
+ content_info->album_id = album_id;
+ append_album = FALSE;
+
+ if((!strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) ||
+ (!strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN)))) {
+
+ media_svc_debug("Unknown album or artist already exists. Extract thumbnail for Unknown.");
+ extract_thumbnail = TRUE;
+ } else {
+
+ media_svc_debug("album already exists. don't need to make album art");
+ ret = _media_svc_get_album_art_by_album_id(handle, album_id, &content_info->thumbnail_path);
+ media_svc_retv_del_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret, content_info);
+ extract_thumbnail = FALSE;
+ }
+ }
+#endif
+
+ if ((!thumb_extracted_from_drm) && (extract_thumbnail == TRUE)) {
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK, &image, &size, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ media_svc_error("fail to get tag artwork - err(%x)", mmf_error);
+ SAFE_FREE(err_attr_name);
+ } else {
+ //media_svc_debug("artwork size1 [%d]", size);
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_SIZE, &size, NULL);
+ if (mmf_error != MM_ERROR_NONE) {
+ media_svc_error("fail to get artwork size - err(%x)", mmf_error);
+ SAFE_FREE(err_attr_name);
+ } else {
+ //media_svc_debug("artwork size2 [%d]", size);
+ }
+ if (image != NULL && size > 0) {
+ bool result = FALSE;
+ int ret = MEDIA_INFO_ERROR_NONE;
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = "\0";
+ int artwork_mime_size = -1;
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL);
+ if ((mmf_error == MM_ERROR_NONE) && (artwork_mime_size > 0)) {
+ result = _media_svc_get_thumbnail_path(content_info->storage_type, thumb_path, content_info->path, p);
+ if (result == FALSE) {
+ media_svc_error("Fail to Get Thumbnail Path");
+ }
+ } else {
+ SAFE_FREE(err_attr_name);
+ }
+
+ if(strlen(thumb_path) > 0)
+ {
+ ret = _media_svc_save_image(image, size, thumb_path);
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("Fail to Save Thumbnail Image");
+ }
+ else {
+ ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ }
+ }
+ }
+ }
+
+ if(append_album == TRUE) {
+
+ if((strncmp(content_info->media_meta.album, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))) &&
+ (strncmp(content_info->media_meta.artist, MEDIA_SVC_TAG_UNKNOWN, strlen(MEDIA_SVC_TAG_UNKNOWN))))
+ ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, content_info->thumbnail_path, &album_id);
+ else
+ ret = _media_svc_append_album(handle, content_info->media_meta.album, content_info->media_meta.artist, NULL, &album_id);
+
+ content_info->album_id = album_id;
+ }
+
+ if(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LONGITUDE, &gps_value, NULL);
+ if (mmf_error == MM_ERROR_NONE) {
+ if (gps_value == 0.0)
+ content_info->media_meta.longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ else
+ content_info->media_meta.longitude = gps_value;
+ } else {
+ SAFE_FREE(err_attr_name);
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_LATIDUE, &gps_value, NULL);
+ if (mmf_error == MM_ERROR_NONE) {
+ if (gps_value == 0.0)
+ content_info->media_meta.latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ else
+ content_info->media_meta.latitude = gps_value;
+ } else {
+ SAFE_FREE(err_attr_name);
+ }
+
+ mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ALTIDUE, &gps_value, NULL);
+ if (mmf_error == MM_ERROR_NONE) {
+ if (gps_value == 0.0)
+ content_info->media_meta.altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
+ else
+ content_info->media_meta.altitude = gps_value;
+ } else {
+ SAFE_FREE(err_attr_name);
+ }
+#if 0
+ //if ((!thumb_extracted_from_drm) && (extract_thumbnail == TRUE))
+ {
+ /* Extracting thumbnail */
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
+ int width = 0;
+ int height = 0;
+
+ ret = thumbnail_request_from_db_with_size(content_info->path, thumb_path, sizeof(thumb_path), &width, &height);
+ if (ret < 0) {
+ media_svc_error("thumbnail_request_from_db failed: %d", ret);
+ } else {
+ //media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
+ }
+
+ ret = __media_svc_malloc_and_strncpy(&content_info->thumbnail_path, thumb_path);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+
+ if (content_info->media_meta.width <= 0) content_info->media_meta.width = width;
+ if (content_info->media_meta.height <= 0) content_info->media_meta.height = height;
+ }
+#endif
+ }
+
+ mmf_error = mm_file_destroy_tag_attrs(tag);
+ if (mmf_error != MM_ERROR_NONE) {
+ media_svc_error("fail to free tag attr - err(%x)", mmf_error);
+ }
+ } else {
+ /* in case of file size 0, MMFW Can't parsting tag info but add it to Music DB. */
+ char *title = NULL;
+ media_svc_error("no tag information");
+
+ title = _media_svc_get_title_from_filepath(content_info->path);
+ if (title) {
+ ret = __media_svc_malloc_and_strncpy(&content_info->media_meta.title, title);
+ if(ret != MEDIA_INFO_ERROR_NONE)
+ media_svc_error("strcpy error");
+ SAFE_FREE(title);
+ } else {
+ media_svc_error("Can't extract title from filepath [%s]", content_info->path);
+ }
+
+ content_info->album_id = album_id;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
+{
+ media_svc_retm_if(content_info == NULL, "content info is NULL");
+
+ /* Delete media_svc_content_info_s */
+ SAFE_FREE(content_info->media_uuid);
+ SAFE_FREE(content_info->path);
+ SAFE_FREE(content_info->file_name);
+ SAFE_FREE(content_info->mime_type);
+ SAFE_FREE(content_info->folder_uuid);
+ SAFE_FREE(content_info->thumbnail_path);
+
+ /* Delete media_svc_content_meta_s */
+ SAFE_FREE(content_info->media_meta.title);
+ SAFE_FREE(content_info->media_meta.album);
+ SAFE_FREE(content_info->media_meta.artist);
+ SAFE_FREE(content_info->media_meta.genre);
+ SAFE_FREE(content_info->media_meta.composer);
+ SAFE_FREE(content_info->media_meta.year);
+ SAFE_FREE(content_info->media_meta.recorded_date);
+ SAFE_FREE(content_info->media_meta.copyright);
+ SAFE_FREE(content_info->media_meta.track_num);
+ SAFE_FREE(content_info->media_meta.description);
+ SAFE_FREE(content_info->media_meta.datetaken);
+
+ return;
+}
+
+int _media_svc_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type)
+{
+ if(STRING_VALID(path))
+ {
+ if(strncmp(path, MEDIA_SVC_PATH_PHONE, strlen(MEDIA_SVC_PATH_PHONE)) == 0)
+ {
+ *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
+ }
+ else if(strncmp (path, MEDIA_SVC_PATH_MMC, strlen(MEDIA_SVC_PATH_MMC)) == 0)
+ {
+ *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
+ }
+ }
+ else
+ {
+ media_svc_error("INVALID parameter");
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+char *_media_svc_replace_path(char *s, const char *olds, const char *news)
+{
+ char *result, *sr;
+ size_t i, count = 0;
+ size_t oldlen = strlen(olds); if (oldlen < 1) return s;
+ size_t newlen = strlen(news);
+
+ if (newlen != oldlen) {
+ for (i = 0; s[i] != '\0';) {
+ if (memcmp(&s[i], olds, oldlen) == 0) count++, i += oldlen;
+ else i++;
+ }
+ } else i = strlen(s);
+
+
+ result = (char *) calloc(1, i + 1 + count * (newlen - oldlen));
+ if (result == NULL) return NULL;
+
+ sr = result;
+ while (*s) {
+ if (memcmp(s, olds, oldlen) == 0) {
+ memcpy(sr, news, newlen);
+ sr += newlen;
+ s += oldlen;
+ } else *sr++ = *s++;
+ }
+
+ *sr = '\0';
+
+ return result;
+}
+
+int _media_svc_error_convert(int error)
+{
+ media_svc_debug("error : [%d]", error);
+
+ if(error == MS_MEDIA_ERR_NONE) /*Error None*/
+ return MEDIA_INFO_ERROR_NONE;
+ else if(error == MS_MEDIA_ERR_DB_CONNECT_FAIL) /*DB Connect Fail*/
+ return MEDIA_INFO_ERROR_DATABASE_CONNECT;
+ else if(error == MS_MEDIA_ERR_DB_DISCONNECT_FAIL) /*DB Disconnect Fail*/
+ return MEDIA_INFO_ERROR_DATABASE_DISCONNECT;
+ else if(error == MS_MEDIA_ERR_SOCKET_CONN) /*Socket Connect Fail*/
+ return MEDIA_INFO_ERROR_SOCKET_CONN;
+ else if(error == MS_MEDIA_ERR_INVALID_PARAMETER || error == MS_MEDIA_ERR_INVALID_PATH)
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+
+ return MEDIA_INFO_ERROR_INTERNAL;
+}
+
+
+bool _media_svc_is_drm_file(const char *path)
+{
+ int ret;
+ drm_bool_type_e is_drm_file = DRM_UNKNOWN;
+
+ ret = drm_is_drm_file(path,&is_drm_file);
+ if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file)
+ return TRUE;
+
+ return FALSE;
+}
+
+int _media_svc_get_mime_in_drm_info(const char *path, char *mime)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ drm_content_info_s contentInfo;
+
+ if (path == NULL || mime == NULL)
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+
+ memset(&contentInfo,0x0,sizeof(drm_content_info_s));
+ ret = drm_get_content_info(path, &contentInfo);
+ if (ret != DRM_RETURN_SUCCESS) {
+ media_svc_error("drm_svc_get_content_info() fails. ");
+ return MEDIA_INFO_ERROR_INVALID_MEDIA;
+ }
+
+ strncpy(mime, contentInfo.mime_type, MEDIA_SVC_METADATA_LEN_MAX);
+ media_svc_debug("DRM contentType : %s", contentInfo.mime_type);
+ //media_svc_debug("DRM mime : %s", mime);
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int _media_svc_get_content_type_from_mime(const char * path, const char * mimetype, int * category)
+{
+ int i = 0;
+ int err = 0;
+
+ *category = MEDIA_SVC_CATEGORY_UNKNOWN;
+
+ //media_svc_debug("mime type : %s", mimetype);
+
+ /*categorize from mimetype */
+ for (i = 0; i < CONTENT_TYPE_NUM; i++) {
+ if (strstr(mimetype, content_category[i].content_type) != NULL) {
+ *category = (*category | content_category[i].category_by_mime);
+ break;
+ }
+ }
+
+ /*in application type, exitst sound file ex) x-smafs */
+ if (*category & MEDIA_SVC_CATEGORY_ETC) {
+ int prefix_len = strlen(content_category[0].content_type);
+
+ for (i = 0; i < SOUND_MIME_NUM; i++) {
+ if (strstr(mimetype + prefix_len, sound_mime_table[i]) != NULL) {
+ *category ^= MEDIA_SVC_CATEGORY_ETC;
+ *category |= MEDIA_SVC_CATEGORY_SOUND;
+ break;
+ }
+ }
+ }
+
+ /*check music file in soun files. */
+ if (*category & MEDIA_SVC_CATEGORY_SOUND) {
+ int prefix_len = strlen(content_category[0].content_type) + 1;
+
+ //MS_DBG("mime_type : %s", mimetype + prefix_len);
+
+ for (i = 0; i < MUSIC_MIME_NUM; i++) {
+ if (strcmp(mimetype + prefix_len, music_mime_table[i]) == 0) {
+ *category ^= MEDIA_SVC_CATEGORY_SOUND;
+ *category |= MEDIA_SVC_CATEGORY_MUSIC;
+ break;
+ }
+ }
+ } else if (*category & MEDIA_SVC_CATEGORY_VIDEO) {
+ /*some video files don't have video stream. in this case it is categorize as music. */
+ char *ext;
+ /*"3gp" and "mp4" must check video stream and then categorize in directly. */
+ ext = strrchr(path, '.');
+ if (ext != NULL) {
+ if ((strncasecmp(ext, _3GP_FILE, 4) == 0) || (strncasecmp(ext, _MP4_FILE, 5) == 0)) {
+ int audio = 0;
+ int video = 0;
+
+ err = mm_file_get_stream_info(path, &audio, &video);
+ if (err == 0) {
+ if (audio > 0 && video == 0) {
+ *category ^= MEDIA_SVC_CATEGORY_VIDEO;
+ *category |= MEDIA_SVC_CATEGORY_MUSIC;
+ }
+ }
+ }
+ }
+ }
+
+ //media_svc_debug("category_from_ext : %d", *category);
+
+ return err;
+}
diff --git a/src/common/media-svc.c b/src/common/media-svc.c
new file mode 100755
index 0000000..1dcebb9
--- /dev/null
+++ b/src/common/media-svc.c
@@ -0,0 +1,1084 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <string.h>
+#include <aul/aul.h>
+#include <media-util.h>
+#include "media-svc.h"
+#include "media-svc-media.h"
+#include "media-svc-debug.h"
+#include "media-svc-util.h"
+#include "media-svc-db-utils.h"
+#include "media-svc-media-folder.h"
+#include "media-svc-album.h"
+
+
+static __thread int g_media_svc_item_validity_data_cnt = 1;
+static __thread int g_media_svc_item_validity_cur_data_cnt = 0;
+
+static __thread int g_media_svc_move_item_data_cnt = 1;
+static __thread int g_media_svc_move_item_cur_data_cnt = 0;
+
+static __thread int g_media_svc_insert_item_data_cnt = 1;
+static __thread int g_media_svc_insert_item_cur_data_cnt = 0;
+
+
+
+
+int media_svc_connect(MediaSvcHandle **handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ MediaDBHandle *db_handle = NULL;
+
+ media_svc_debug_func();
+
+#if 1 //Use libmedia_utils API
+ ret = media_db_connect(&db_handle);
+ if(ret != MS_MEDIA_ERR_NONE)
+ return _media_svc_error_convert(ret);
+
+#else
+ sqlite3 * db_handle = NULL;
+
+ ret = _media_svc_connect_db_with_handle(&db_handle);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+#endif
+
+ *handle = db_handle;
+ return MEDIA_INFO_ERROR_NONE;
+
+}
+
+int media_svc_disconnect(MediaSvcHandle *handle)
+{
+ MediaDBHandle * db_handle = (MediaDBHandle *)handle;
+
+ media_svc_debug_func();
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+
+#if 1 //Use libmedia_utils API
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ ret = media_db_disconnect(db_handle);
+ return _media_svc_error_convert(ret);
+#else
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ return _media_svc_disconnect_db_with_handle(db_handle);
+#endif
+}
+
+int media_svc_create_table(MediaSvcHandle *handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug_func();
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+
+ /*create media table*/
+ ret = _media_svc_create_media_table(handle);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /*create folder table*/
+ ret = _media_svc_create_folder_table(handle);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /*create playlist table*/
+ ret = _media_svc_create_playlist_table(handle);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /* create album table*/
+ ret = _media_svc_create_album_table(handle);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /*create tag table*/
+ ret = _media_svc_create_tag_table(handle);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /*create bookmark table*/
+ ret = _media_svc_create_bookmark_table(handle);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+#if 0 /*unify media and custom table*/
+ /*create custom table*/
+ ret = _media_svc_create_custom_table(handle);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+#endif
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int media_svc_get_storage_type(const char *path, media_svc_storage_type_e *storage_type)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ media_svc_storage_type_e type;
+
+ ret = _media_svc_get_store_type_by_path(path, &type);
+ media_svc_retvm_if(ret < MEDIA_INFO_ERROR_NONE, ret, "_media_svc_get_store_type_by_path failed : %d", ret);
+
+ *storage_type = type;
+
+ return ret;
+}
+
+int media_svc_get_mime_type(const char *path, char *mimetype)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ if (path == NULL)
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+
+ /* In case of drm file. */
+ if (_media_svc_is_drm_file(path)) {
+ ret = _media_svc_get_mime_in_drm_info(path, mimetype);
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("Fail to get mime");
+ return ret;
+ }
+ } else {
+ /*in case of normal files */
+ if (aul_get_mime_from_file(path, mimetype, 255) < 0) {
+ media_svc_error("aul_get_mime_from_file fail");
+ return MEDIA_INFO_ERROR_INVALID_MEDIA;
+ }
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int media_svc_get_media_type(const char *path, const char *mime_type, media_svc_media_type_e *media_type)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ int category = 0;
+
+ media_svc_media_type_e type;
+
+ ret = _media_svc_get_content_type_from_mime(path, mime_type, &category);
+ if (ret < 0) {
+ media_svc_error("_media_svc_get_content_type_from_mime failed : %d", ret);
+ }
+
+ if (category & MEDIA_SVC_CATEGORY_SOUND) type = MEDIA_SVC_MEDIA_TYPE_SOUND;
+ else if (category & MEDIA_SVC_CATEGORY_MUSIC) type = MEDIA_SVC_MEDIA_TYPE_MUSIC;
+ else if (category & MEDIA_SVC_CATEGORY_IMAGE) type = MEDIA_SVC_MEDIA_TYPE_IMAGE;
+ else if (category & MEDIA_SVC_CATEGORY_VIDEO) type = MEDIA_SVC_MEDIA_TYPE_VIDEO;
+ else type = MEDIA_SVC_MEDIA_TYPE_OTHER;
+
+ *media_type = type;
+
+ return ret;
+}
+
+int media_svc_check_item_exist_by_path(MediaSvcHandle *handle, const char *path)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+ int count = -1;
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "Path is NULL");
+
+ ret = _media_svc_count_record_with_path(db_handle, path, &count);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ if(count > 0) {
+ media_svc_debug("item is exist in database");
+ return MEDIA_INFO_ERROR_NONE;
+ } else {
+ media_svc_debug("item is not exist in database");
+ return MEDIA_INFO_ERROR_DATABASE_NO_RECORD;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int media_svc_insert_item_begin(MediaSvcHandle *handle, int data_cnt)
+{
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug("Transaction data count : [%d]", data_cnt);
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(data_cnt < 1, MEDIA_INFO_ERROR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
+
+ g_media_svc_insert_item_data_cnt = data_cnt;
+ g_media_svc_insert_item_cur_data_cnt = 0;
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int media_svc_insert_item_end(MediaSvcHandle *handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug_func();
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+
+ if (g_media_svc_insert_item_cur_data_cnt > 0) {
+
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM);
+ }
+
+ g_media_svc_insert_item_data_cnt = 1;
+ g_media_svc_insert_item_cur_data_cnt = 0;
+
+ return ret;
+}
+
+int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e storage_type,
+ const char *path, const char *mime_type, media_svc_media_type_e media_type)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+ char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
+ media_svc_retvm_if(!STRING_VALID(mime_type), MEDIA_INFO_ERROR_INVALID_PARAMETER, "mime_type is NULL");
+
+ if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
+ media_svc_error("storage type is incorrect[%d]", storage_type);
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
+ media_svc_error("invalid media_type condition[%d]", media_type);
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ media_svc_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, media_type);
+
+ media_svc_content_info_s content_info;
+ memset(&content_info, 0, sizeof(media_svc_content_info_s));
+
+ /*Set media info*/
+ ret = _media_svc_set_media_info(&content_info, storage_type, path, mime_type, media_type, FALSE);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ if(media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
+ /*Do nothing.*/
+ } else if(media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
+ ret = _media_svc_extract_image_metadata(&content_info, media_type);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+ } else {
+ ret = _media_svc_extract_media_metadata(handle, &content_info, media_type);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+ }
+
+ /*Set or Get folder id*/
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, path, storage_type, folder_uuid);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
+
+ if (g_media_svc_insert_item_data_cnt == 1) {
+
+ ret = _media_svc_insert_item_with_data(db_handle, &content_info, FALSE);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
+
+ } else if(g_media_svc_insert_item_cur_data_cnt < (g_media_svc_insert_item_data_cnt - 1)) {
+
+ ret = _media_svc_insert_item_with_data(db_handle, &content_info, TRUE);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
+
+ g_media_svc_insert_item_cur_data_cnt ++;
+
+ } else if (g_media_svc_insert_item_cur_data_cnt == (g_media_svc_insert_item_data_cnt - 1)) {
+
+ ret = _media_svc_insert_item_with_data(db_handle, &content_info, TRUE);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
+
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
+
+ g_media_svc_insert_item_cur_data_cnt = 0;
+
+ } else {
+ media_svc_error("Error in media_svc_insert_item_bulk");
+ _media_svc_destroy_content_info(&content_info);
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ _media_svc_destroy_content_info(&content_info);
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_type_e storage_type,
+ const char *path, const char *mime_type, media_svc_media_type_e media_type)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+ char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
+ media_svc_retvm_if(!STRING_VALID(mime_type), MEDIA_INFO_ERROR_INVALID_PARAMETER, "mime_type is NULL");
+
+ if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
+ media_svc_error("storage type is incorrect[%d]", storage_type);
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
+ media_svc_error("invalid media_type condition[%d]", media_type);
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ media_svc_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, media_type);
+
+ media_svc_content_info_s content_info;
+ memset(&content_info, 0, sizeof(media_svc_content_info_s));
+
+ /*Set media info*/
+ ret = _media_svc_set_media_info(&content_info, storage_type, path, mime_type, media_type, FALSE);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ if(media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
+ /*Do nothing.*/
+ } else if(media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
+ ret = _media_svc_extract_image_metadata(&content_info, media_type);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+ } else {
+ ret = _media_svc_extract_media_metadata(handle, &content_info, media_type);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+ }
+
+ /*Set or Get folder id*/
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, path, storage_type, folder_uuid);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
+#if 1
+ /* Extracting thumbnail */
+ if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
+ int width = 0;
+ int height = 0;
+
+ ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height);
+ if (ret < 0) {
+ media_svc_error("thumbnail_request_from_db failed: %d", ret);
+ } else {
+ media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
+ }
+
+ if (content_info.media_meta.width <= 0)
+ content_info.media_meta.width = width;
+
+ if (content_info.media_meta.height <= 0)
+ content_info.media_meta.height = height;
+
+ ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
+ }
+#endif
+ ret = _media_svc_insert_item_with_data(db_handle, &content_info, FALSE);
+
+ _media_svc_destroy_content_info(&content_info);
+ return ret;
+}
+
+int media_svc_insert_folder(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
+
+ if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
+ media_svc_error("storage type is incorrect[%d]", storage_type);
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ media_svc_debug("storage[%d], folder_path[%s]", storage_type, path);
+
+ /*Get folder info*/
+ char *folder_name = NULL;
+ int folder_modified_date = 0;
+ char *folder_uuid = _media_info_generate_uuid();
+ if(folder_uuid == NULL ) {
+ media_svc_error("Invalid UUID");
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ folder_name = g_path_get_basename(path);
+ folder_modified_date = _media_svc_get_file_time(path);
+
+ ret = _media_svc_append_folder(handle, storage_type, folder_uuid, path, folder_name, folder_modified_date);
+ SAFE_FREE(folder_name);
+
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("_media_svc_append_folder error [%d]", ret);
+ return ret;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int media_svc_move_item_begin(MediaSvcHandle *handle, int data_cnt)
+{
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug("Transaction data count : [%d]", data_cnt);
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(data_cnt < 1, MEDIA_INFO_ERROR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
+
+ g_media_svc_move_item_data_cnt = data_cnt;
+ g_media_svc_move_item_cur_data_cnt = 0;
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int media_svc_move_item_end(MediaSvcHandle *handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug_func();
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+
+ if (g_media_svc_move_item_cur_data_cnt > 0) {
+
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_MOVE_ITEM);
+ }
+
+ /*clean up old folder path*/
+ ret = _media_svc_update_folder_table(handle);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ g_media_svc_move_item_data_cnt = 1;
+ g_media_svc_move_item_cur_data_cnt = 0;
+
+ return ret;
+}
+
+int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_storage, const char *src_path,
+ media_svc_storage_type_e dest_storage, const char *dest_path)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+ char *file_name = NULL;
+ char *folder_path = NULL;
+ int modified_time = 0;
+ char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
+ char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0,};
+ char new_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0,};
+ int media_type = -1;
+
+ media_svc_debug_func();
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(src_path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "src_path is NULL");
+ media_svc_retvm_if(!STRING_VALID(dest_path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "dest_path is NULL");
+
+ if ((src_storage != MEDIA_SVC_STORAGE_INTERNAL) && (src_storage != MEDIA_SVC_STORAGE_EXTERNAL)) {
+ media_svc_error("src_storage type is incorrect[%d]", src_storage);
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+ if ((dest_storage != MEDIA_SVC_STORAGE_INTERNAL) && (dest_storage != MEDIA_SVC_STORAGE_EXTERNAL)) {
+ media_svc_error("dest_storage type is incorrect[%d]", dest_storage);
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ /*check and update folder*/
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, dest_path, dest_storage, folder_uuid);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /*get filename*/
+ file_name = g_path_get_basename(dest_path);
+
+ /*get modified_time*/
+ modified_time = _media_svc_get_file_time(dest_path);
+
+ /*get thumbnail_path to update. only for Imgae and Video items. Audio share album_art(thumbnail)*/
+ ret = _media_svc_get_media_type_by_path(handle, src_path, &media_type);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
+ /*get old thumbnail_path*/
+ ret = _media_svc_get_thumbnail_path_by_path(handle, src_path, old_thumb_path);
+ media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret);
+
+ _media_svc_get_thumbnail_path(dest_storage, new_thumb_path, dest_path, THUMB_EXT);
+ }
+
+ if (g_media_svc_move_item_data_cnt == 1) {
+
+ /*update item*/
+ if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
+ ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, FALSE);
+ } else {
+ ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, FALSE);
+ }
+ SAFE_FREE(file_name);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /*update folder modified_time*/
+ folder_path = g_path_get_dirname(dest_path);
+ ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, FALSE);
+ SAFE_FREE(folder_path);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ ret = _media_svc_update_folder_table(handle);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ } else if (g_media_svc_move_item_cur_data_cnt < (g_media_svc_move_item_data_cnt - 1)) {
+
+ /*update item*/
+ if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
+ ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE);
+ } else {
+ ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE);
+ }
+ SAFE_FREE(file_name);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /*update folder modified_time*/
+ folder_path = g_path_get_dirname(dest_path);
+ ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, TRUE);
+ SAFE_FREE(folder_path);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ g_media_svc_move_item_cur_data_cnt ++;
+
+ } else if (g_media_svc_move_item_cur_data_cnt == (g_media_svc_move_item_data_cnt - 1)) {
+
+ /*update item*/
+ if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
+ ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE);
+ } else {
+ ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE);
+ }
+ SAFE_FREE(file_name);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /*update folder modified_time*/
+ folder_path = g_path_get_dirname(dest_path);
+ ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, TRUE);
+ SAFE_FREE(folder_path);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /*update db*/
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_MOVE_ITEM);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ g_media_svc_move_item_cur_data_cnt = 0;
+
+ } else {
+ media_svc_error("Error in media_svc_move_item");
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ /*rename thumbnail file*/
+ if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
+ if(strlen(old_thumb_path) > 0) {
+ ret = _media_svc_rename_file(old_thumb_path,new_thumb_path);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+ }
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int media_svc_set_item_validity_begin(MediaSvcHandle *handle, int data_cnt)
+{
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug("Transaction data count : [%d]", data_cnt);
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(data_cnt < 1, MEDIA_INFO_ERROR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
+
+ g_media_svc_item_validity_data_cnt = data_cnt;
+ g_media_svc_item_validity_cur_data_cnt = 0;
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int media_svc_set_item_validity_end(MediaSvcHandle *handle)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug_func();
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+
+ if (g_media_svc_item_validity_cur_data_cnt > 0) {
+
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY);
+ }
+
+ g_media_svc_item_validity_data_cnt = 1;
+ g_media_svc_item_validity_cur_data_cnt = 0;
+
+ return ret;
+}
+
+int media_svc_set_item_validity(MediaSvcHandle *handle, const char *path, int validity)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
+
+ media_svc_debug("path=[%s], validity=[%d]", path, validity);
+
+ if (g_media_svc_item_validity_data_cnt == 1) {
+
+ return _media_svc_update_item_validity(db_handle, path, validity, FALSE);
+
+ } else if (g_media_svc_item_validity_cur_data_cnt < (g_media_svc_item_validity_data_cnt - 1)) {
+
+ ret = _media_svc_update_item_validity(db_handle, path, validity, TRUE);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ g_media_svc_item_validity_cur_data_cnt ++;
+
+ } else if (g_media_svc_item_validity_cur_data_cnt == (g_media_svc_item_validity_data_cnt - 1)) {
+
+ ret = _media_svc_update_item_validity(db_handle, path, validity, TRUE);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ g_media_svc_item_validity_cur_data_cnt = 0;
+
+ } else {
+
+ media_svc_error("Error in media_svc_set_item_validity");
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *path)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0,};
+
+ media_svc_debug_func();
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
+
+ /*Get thumbnail path to delete*/
+ ret = _media_svc_get_thumbnail_path_by_path(db_handle, path, thumb_path);
+ media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret);
+
+ /*Delete item*/
+ ret = _media_svc_delete_item_by_path(db_handle, path);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /*Delete thumbnail*/
+ if (strlen(thumb_path) > 0) {
+ if (_media_svc_remove_file(thumb_path) == FALSE) {
+ media_svc_error("fail to remove thumbnail file.");
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int media_svc_delete_all_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+ char * dirpath = NULL;
+
+ media_svc_debug("media_svc_delete_all_items_in_storage [%d]", storage_type);
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+
+ if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
+ media_svc_error("storage type is incorrect[%d]", storage_type);
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = _media_svc_truncate_table(db_handle, storage_type);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ dirpath = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? MEDIA_SVC_THUMB_INTERNAL_PATH : MEDIA_SVC_THUMB_EXTERNAL_PATH;
+
+ /* remove thumbnails */
+ ret = _media_svc_remove_all_files_in_dir(dirpath);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int media_svc_delete_invalid_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type)
+{
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug_func();
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+
+ if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
+ media_svc_error("storage type is incorrect[%d]", storage_type);
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ /*Delete from DB and remove thumbnail files*/
+ return _media_svc_delete_invalid_items(db_handle, storage_type);
+}
+
+int media_svc_delete_invalid_items_in_folder(MediaSvcHandle *handle, const char *folder_path)
+{
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_debug_func();
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+
+ /*Delete from DB and remove thumbnail files*/
+ return _media_svc_delete_invalid_folder_items(db_handle, folder_path);
+}
+
+int media_svc_set_all_storage_items_validity(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, int validity)
+{
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+
+ if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
+ media_svc_error("storage type is incorrect[%d]", storage_type);
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ return _media_svc_update_storage_item_validity(db_handle, storage_type, validity);
+}
+
+int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *folder_path, int validity, int recursive)
+{
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(folder_path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "folder_path is NULL");
+
+ if(recursive)
+ return _media_svc_update_recursive_folder_item_validity(db_handle, folder_path, validity);
+ else
+ return _media_svc_update_folder_item_validity(db_handle, folder_path, validity);
+}
+
+int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e storage_type,
+ const char *path, media_svc_media_type_e media_type)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+ sqlite3 * db_handle = (sqlite3 *)handle;
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "path is NULL");
+
+ if ((storage_type != MEDIA_SVC_STORAGE_INTERNAL) && (storage_type != MEDIA_SVC_STORAGE_EXTERNAL)) {
+ media_svc_error("storage type is incorrect[%d]", storage_type);
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ if ((media_type < MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type > MEDIA_SVC_MEDIA_TYPE_OTHER)) {
+ media_svc_error("invalid media_type condition[%d]", media_type);
+ return MEDIA_INFO_ERROR_INVALID_PARAMETER;
+ }
+
+ media_svc_debug("storage[%d], path[%s], media_type[%d]", storage_type, path, media_type);
+
+ media_svc_content_info_s content_info;
+ memset(&content_info, 0, sizeof(media_svc_content_info_s));
+
+ /*Set media info*/
+ ret = _media_svc_set_media_info(&content_info, storage_type, path, NULL, media_type, TRUE);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /* Initialize thumbnail information to remake thumbnail. */
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1];
+ ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ if (g_file_test(thumb_path, G_FILE_TEST_EXISTS)) {
+ ret = _media_svc_remove_file(thumb_path);
+ media_svc_retv_if(ret != TRUE, ret);
+ }
+
+ ret = _media_svc_update_thumbnail_path(handle, path, NULL);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ if(media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
+ /*Do nothing.*/
+ } else if(media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
+ ret = _media_svc_extract_image_metadata(&content_info, media_type);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+ } else {
+ ret = _media_svc_extract_media_metadata(handle, &content_info, media_type);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+ }
+#if 1
+ /* Extracting thumbnail */
+ if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
+ char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
+ int width = 0;
+ int height = 0;
+
+ ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height);
+ if (ret < 0) {
+ media_svc_error("thumbnail_request_from_db failed: %d", ret);
+ } else {
+ media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
+ }
+
+ if (content_info.media_meta.width <= 0)
+ content_info.media_meta.width = width;
+
+ if (content_info.media_meta.height <= 0)
+ content_info.media_meta.height = height;
+
+ ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
+ media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
+ }
+#endif
+ ret = _media_svc_update_item_with_data(db_handle, &content_info);
+
+ _media_svc_destroy_content_info(&content_info);
+
+ return ret;
+}
+
+int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const char *dst_path)
+{
+ sqlite3 * db_handle = (sqlite3 *)handle;
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
+ media_svc_retvm_if(src_path == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "src_path is NULL");
+ media_svc_retvm_if(dst_path == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "dst_path is NULL");
+
+ media_svc_debug("Src path : %s, Dst Path : %s", src_path, dst_path);
+
+ ret = _media_svc_sql_begin_trans(handle);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /* Update all folder record's path, which are matched by old parent path */
+ char *update_folder_path_sql = NULL;
+ char src_path_slash[MEDIA_SVC_PATHNAME_SIZE + 1];
+ char dst_path_slash[MEDIA_SVC_PATHNAME_SIZE + 1];
+
+ snprintf(src_path_slash, sizeof(src_path_slash), "%s/", src_path);
+ snprintf(dst_path_slash, sizeof(dst_path_slash), "%s/", dst_path);
+
+ update_folder_path_sql = sqlite3_mprintf("UPDATE folder SET path = REPLACE( path, '%q', '%q');", src_path_slash, dst_path_slash);
+
+ //ret = _media_svc_sql_query(handle, update_folder_path_sql);
+ ret = media_db_request_update_db_batch(update_folder_path_sql);
+ sqlite3_free(update_folder_path_sql);
+
+ if (ret != SQLITE_OK) {
+ media_svc_error("failed to update folder path");
+ _media_svc_sql_rollback_trans(handle);
+
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ /* Update all folder record's modified date, which are changed above */
+ char *update_folder_modified_time_sql = NULL;
+ time_t date;
+ time(&date);
+
+ update_folder_modified_time_sql = sqlite3_mprintf("UPDATE folder SET modified_time = %d where path like '%q';", date, dst_path);
+
+ ret = media_db_request_update_db_batch(update_folder_modified_time_sql);
+ //ret = _media_svc_sql_query(handle, update_folder_modified_time_sql);
+ sqlite3_free(update_folder_modified_time_sql);
+
+ if (ret != SQLITE_OK) {
+ media_svc_error("failed to update folder modified time");
+ _media_svc_sql_rollback_trans(handle);
+
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ /* Update all items */
+ char *select_all_sql = NULL;
+ sqlite3_stmt *sql_stmt = NULL;
+ char dst_child_path[MEDIA_SVC_PATHNAME_SIZE + 1];
+
+ snprintf(dst_child_path, sizeof(dst_child_path), "%s/%%", dst_path);
+
+ select_all_sql = sqlite3_mprintf("SELECT media_uuid, path, thumbnail_path, media_type from media where folder_uuid IN ( SELECT folder_uuid FROM folder where path='%q' or path like '%q');", dst_path, dst_child_path);
+
+ media_svc_debug("[SQL query] : %s", select_all_sql);
+
+ ret = sqlite3_prepare_v2(handle, select_all_sql, -1, &sql_stmt, NULL);
+ sqlite3_free((char *)select_all_sql);
+
+ if (ret != SQLITE_OK) {
+ media_svc_error ("prepare error [%s]", sqlite3_errmsg(handle));
+ _media_svc_sql_rollback_trans(handle);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ while (1) {
+ ret = sqlite3_step(sql_stmt);
+ if (ret != SQLITE_ROW) {
+ media_svc_debug("end of iteration");
+ break;
+ }
+
+ char media_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0,};
+ char media_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0,};
+ char media_thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0,};
+ char media_new_thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0,};
+ int media_type;
+ bool no_thumb = FALSE;
+
+ if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0))) {
+ strncpy(media_uuid, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(media_uuid));
+ } else {
+ media_svc_error("media UUID is NULL");
+ return MEDIA_INFO_ERROR_DATABASE_INVALID;
+ }
+
+ if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 1))) {
+ strncpy(media_path, (const char *)sqlite3_column_text(sql_stmt, 1), sizeof(media_path));
+ } else {
+ media_svc_error("media path is NULL");
+ return MEDIA_INFO_ERROR_DATABASE_INVALID;
+ }
+
+ if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 2))) {
+ strncpy(media_thumb_path, (const char *)sqlite3_column_text(sql_stmt, 2), sizeof(media_thumb_path));
+ } else {
+ media_svc_debug("media thumb path doesn't exist in DB");
+ no_thumb = TRUE;
+ }
+
+ media_type = sqlite3_column_int(sql_stmt, 3);
+
+ /* Update path, thumbnail path of this item */
+ char *replaced_path = NULL;
+ replaced_path = _media_svc_replace_path(media_path, src_path, dst_path);
+ if (replaced_path == NULL) {
+ media_svc_error("_media_svc_replace_path failed");
+ SQLITE3_FINALIZE(sql_stmt);
+ _media_svc_sql_rollback_trans(handle);
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ media_svc_debug("New media path : %s", replaced_path);
+ media_svc_storage_type_e storage_type;
+
+ if (!no_thumb) {
+ ret = _media_svc_get_store_type_by_path(replaced_path, &storage_type);
+ if (ret < 0) {
+ media_svc_error("_media_svc_get_store_type_by_path failed : %d", ret);
+ SAFE_FREE(replaced_path);
+ _media_svc_sql_rollback_trans(handle);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ ret = _media_svc_get_thumbnail_path(storage_type, media_new_thumb_path, replaced_path, THUMB_EXT);
+ if (ret < 0) {
+ media_svc_error("_media_svc_get_thumbnail_path failed : %d", ret);
+ SAFE_FREE(replaced_path);
+ SQLITE3_FINALIZE(sql_stmt);
+ _media_svc_sql_rollback_trans(handle);
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+
+ //media_svc_debug("New media thumbnail path : %s", media_new_thumb_path);
+ }
+
+ char *update_item_sql = NULL;
+
+ if (no_thumb) {
+ update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q' WHERE media_uuid='%q'", replaced_path, media_uuid);
+ } else {
+ if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
+ update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", replaced_path, media_new_thumb_path, media_uuid);
+ } else {
+ update_item_sql = sqlite3_mprintf("UPDATE media SET path='%q', thumbnail_path='%q' WHERE media_uuid='%q'", replaced_path, media_thumb_path, media_uuid);
+ }
+ }
+
+ ret = media_db_request_update_db_batch(update_item_sql);
+ //ret = _media_svc_sql_query(handle, update_item_sql);
+ sqlite3_free(update_item_sql);
+ SAFE_FREE(replaced_path);
+
+ if (ret != SQLITE_OK) {
+ media_svc_error("failed to update item");
+ SQLITE3_FINALIZE(sql_stmt);
+ _media_svc_sql_rollback_trans(handle);
+
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ /* Rename thumbnail file of file system */
+ if ((!no_thumb) && (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
+ ret = _media_svc_rename_file(media_thumb_path, media_new_thumb_path);
+ if (ret < 0) {
+ media_svc_error("_media_svc_rename_file failed : %d", ret);
+ SQLITE3_FINALIZE(sql_stmt);
+ _media_svc_sql_rollback_trans(handle);
+
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
+ }
+ }
+
+ SQLITE3_FINALIZE(sql_stmt);
+
+ ret = _media_svc_sql_end_trans(handle);
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback\n");
+ _media_svc_sql_rollback_trans(handle);
+ return ret;
+ }
+
+ return MEDIA_INFO_ERROR_NONE;
+}
+
+int media_svc_request_update_db(const char *db_query)
+{
+ int ret = MEDIA_INFO_ERROR_NONE;
+
+ media_svc_retvm_if(!STRING_VALID(db_query), MEDIA_INFO_ERROR_INVALID_PARAMETER, "db_query is NULL");
+
+ ret = _media_svc_request_update_db(db_query);
+
+ return _media_svc_error_convert(ret);
+}
diff --git a/src/include/common/media-svc-album.h b/src/include/common/media-svc-album.h
new file mode 100755
index 0000000..09fe97b
--- /dev/null
+++ b/src/include/common/media-svc-album.h
@@ -0,0 +1,32 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _MEDIA_SVC_ALBUM_H_
+#define _MEDIA_SVC_ALBUM_H_
+
+#include <sqlite3.h>
+
+int _media_svc_get_album_id(sqlite3 *handle, const char *album, const char *artist, int * album_id);
+int _media_svc_get_album_art_by_album_id(sqlite3 *handle, int album_id, char **album_art);
+int _media_svc_append_album(sqlite3 *handle, const char *album, const char *artist, const char *album_art, int * album_id);
+
+
+#endif /*_MEDIA_SVC_ALBUM_H_*/
diff --git a/src/include/common/media-svc-db-utils.h b/src/include/common/media-svc-db-utils.h
new file mode 100755
index 0000000..8493a64
--- /dev/null
+++ b/src/include/common/media-svc-db-utils.h
@@ -0,0 +1,50 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+#ifndef _MEDIA_SVC_DB_UTILS_H_
+#define _MEDIA_SVC_DB_UTILS_H_
+
+#include <sqlite3.h>
+#include <glib.h>
+
+#define SQLITE3_FINALIZE(x) if(x != NULL) {sqlite3_finalize(x);}
+
+int _media_svc_connect_db_with_handle(sqlite3 **db_handle);
+int _media_svc_disconnect_db_with_handle(sqlite3 *db_handle);
+int _media_svc_create_media_table(sqlite3 *db_handle);
+int _media_svc_create_folder_table(sqlite3 *db_handle);
+int _media_svc_create_playlist_table(sqlite3 *db_handle);
+int _media_svc_create_album_table(sqlite3 *db_handle);
+int _media_svc_create_tag_table(sqlite3 *db_handle);
+int _media_svc_create_bookmark_table(sqlite3 *db_handle);
+int _media_svc_create_custom_table(sqlite3 *db_handle);
+int _media_svc_request_update_db(const char *sql_str);
+int _media_svc_sql_query(sqlite3 *db_handle, const char *sql_str);
+int _media_svc_sql_prepare_to_step(sqlite3 *handle, const char *sql_str, sqlite3_stmt** stmt);
+int _media_svc_sql_begin_trans(sqlite3 *handle);
+int _media_svc_sql_end_trans(sqlite3 *handle);
+int _media_svc_sql_rollback_trans(sqlite3 *handle);
+int _media_svc_sql_query_list(sqlite3 *handle, GList **query_list);
+void _media_svc_sql_query_add(GList **query_list, char **query);
+void _media_svc_sql_query_release(GList **query_list);
+
+#endif /*_MEDIA_SVC_DB_UTILS_H_*/
diff --git a/src/include/common/media-svc-debug.h b/src/include/common/media-svc-debug.h
new file mode 100755
index 0000000..857f130
--- /dev/null
+++ b/src/include/common/media-svc-debug.h
@@ -0,0 +1,96 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+#ifndef _MEDIA_SVC_DEBUG_H_
+#define _MEDIA_SVC_DEBUG_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <dlog.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "MEDIA_SERVICE"
+
+#define media_svc_debug(fmt, arg...) do { \
+ LOGD(" "fmt"", ##arg); \
+ } while (0)
+
+#define media_svc_error(fmt, arg...) do { \
+ LOGE(" "fmt"", ##arg); \
+ } while (0)
+
+#define media_svc_debug_func() do { \
+ LOGD(""); \
+ } while (0)
+
+#define media_svc_retm_if(expr, fmt, arg...) do { \
+ if(expr) { \
+ LOGE(" "fmt"", ##arg); \
+ return; \
+ } \
+ } while (0)
+#define media_svc_retv_if(expr, val) do { \
+ if(expr) { \
+ LOGE(""); \
+ return (val); \
+ } \
+ } while (0)
+#define media_svc_retvm_if(expr, val, fmt, arg...) do { \
+ if(expr) { \
+ LOGE(" "fmt"", ##arg); \
+ return (val); \
+ } \
+ } while (0)
+
+#define media_svc_retv_del_if(expr, val, p_str) do { \
+ if(expr) { \
+ LOGE(""); \
+ _media_svc_destroy_content_info(p_str); \
+ return (val); \
+ } \
+ } while (0)
+
+#ifdef _USE_LOG_FILE_
+void mediainfo_init_file_debug();
+void mediainfo_close_file_debug();
+FILE* get_fp();
+#define mediainfo_file_dbg(fmt,arg...) fprintf( get_fp(), "[%s: %d] [%s]" fmt "\n", __FILE__, __LINE__, __FUNCTION__, ##arg)
+
+#endif
+
+
+#ifdef _PERFORMANCE_CHECK_
+long
+mediainfo_get_debug_time(void);
+void
+mediainfo_reset_debug_time(void);
+void
+mediainfo_print_debug_time(char* time_string);
+void
+mediainfo_print_debug_time_ex(long start, long end, const char* func_name, char* time_string);
+#endif
+
+#endif /*_MEDIA_SVC_DEBUG_H_*/
diff --git a/src/include/common/media-svc-env.h b/src/include/common/media-svc-env.h
new file mode 100755
index 0000000..3de5b73
--- /dev/null
+++ b/src/include/common/media-svc-env.h
@@ -0,0 +1,204 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+#ifndef _MEDIA_SVC_ENV_H_
+#define _MEDIA_SVC_ENV_H_
+
+#include <time.h>
+#include <media-util.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * DB information
+ */
+
+#define MEDIA_SVC_DB_NAME MEDIA_DB_NAME /**< media db name*/
+
+/**
+ * DB table information
+ */
+
+#define MEDIA_SVC_DB_TABLE_MEDIA "media" /**< media table*/
+#define MEDIA_SVC_DB_TABLE_FOLDER "folder" /**< media_folder table*/
+#define MEDIA_SVC_DB_TABLE_PLAYLIST "playlist" /**< playlist table*/
+#define MEDIA_SVC_DB_TABLE_PLAYLIST_MAP "playlist_map" /**< playlist_map table*/
+#define MEDIA_SVC_DB_TABLE_ALBUM "album" /**< album table*/
+#define MEDIA_SVC_DB_TABLE_TAG "tag" /**< tag table*/
+#define MEDIA_SVC_DB_TABLE_TAG_MAP "tag_map" /**< tag_map table*/
+#define MEDIA_SVC_DB_TABLE_BOOKMARK "bookmark" /**< bookmark table*/
+#define MEDIA_SVC_DB_TABLE_CUSTOM "custom" /**< custom table*/
+
+
+#define MEDIA_SVC_METADATA_LEN_MAX 128 /**< Length of metadata*/
+#define MEDIA_SVC_METADATA_DESCRIPTION_MAX 512 /**< Length of description*/
+#define MEDIA_SVC_PATHNAME_SIZE 4096 /**< Length of Path name. */
+#define MEDIA_SVC_UUID_SIZE 36 /**< Length of UUID*/
+
+#define MEDIA_SVC_TAG_UNKNOWN "Unknown"
+#define MEDIA_SVC_MEDIA_PATH MEDIA_DATA_PATH /**< Media path*/
+#define MEDIA_SVC_THUMB_PATH_PREFIX MEDIA_SVC_MEDIA_PATH"/.thumb" /**< Thumbnail path prefix*/
+#define MEDIA_SVC_THUMB_INTERNAL_PATH MEDIA_SVC_THUMB_PATH_PREFIX"/phone" /**< Phone thumbnail path*/
+#define MEDIA_SVC_THUMB_EXTERNAL_PATH MEDIA_SVC_THUMB_PATH_PREFIX"/mmc" /**< MMC thumbnail path*/
+
+#define MEDIA_SVC_DEFAULT_GPS_VALUE -200 /**< Default GPS Value*/
+#define THUMB_EXT "jpg"
+
+#define MEDIA_SVC_PATH_PHONE MEDIA_ROOT_PATH_INTERNAL
+#define MEDIA_SVC_PATH_MMC MEDIA_ROOT_PATH_SDCARD
+
+enum Exif_Orientation {
+ NOT_AVAILABLE=0,
+ NORMAL =1,
+ HFLIP =2,
+ ROT_180 =3,
+ VFLIP =4,
+ TRANSPOSE =5,
+ ROT_90 =6,
+ TRANSVERSE =7,
+ ROT_270 =8
+};
+
+#if 0
+/**
+ * Media meta data information
+ */
+typedef struct {
+ char title[MEDIA_SVC_METADATA_LEN_MAX]; /**< track title*/
+ char album[MEDIA_SVC_METADATA_LEN_MAX]; /**< album name*/
+ char artist[MEDIA_SVC_METADATA_LEN_MAX]; /**< artist name*/
+ char genre[MEDIA_SVC_METADATA_LEN_MAX]; /**< genre of track*/
+ char author[MEDIA_SVC_METADATA_LEN_MAX]; /**< author name*/
+ char year[MEDIA_SVC_METADATA_LEN_MAX]; /**< author name*/
+ char recorded_date[MEDIA_SVC_METADATA_LEN_MAX]; /**< recorded date*/
+ char copyright[MEDIA_SVC_METADATA_LEN_MAX]; /**< copyright*/
+ char track_num[MEDIA_SVC_METADATA_LEN_MAX]; /**< track number*/
+ char description[MEDIA_SVC_METADATA_DESCRIPTION_MAX]; /**< description*/
+ int bitrate; /**< bitrate*/
+ int samplerate; /**< samplerate*/
+ int channel; /**< channel*/
+ int duration; /**< duration*/
+ float longitude; /**< longitude*/
+ float latitude; /**< latitude*/
+ float altitude; /**< altitude*/
+ int width; /**< width*/
+ int height; /**< height*/
+ char datetaken[MEDIA_SVC_METADATA_LEN_MAX]; /**< datetaken*/
+ char timetaken[MEDIA_SVC_METADATA_LEN_MAX]; /**< timetaken*/
+ int orientation; /**< orientation*/
+ int rating; /**< user defined rating */
+} media_svc_content_meta_s;
+
+
+/**
+ * Media data information
+ */
+typedef struct {
+ char media_uuid[MEDIA_SVC_UUID_SIZE+1]; /**< Unique ID of item */
+ char path[MEDIA_SVC_PATHNAME_SIZE]; /**< Full path and file name of media file */
+ char file_name[MEDIA_SVC_PATHNAME_SIZE]; /**< Full path and file name of media file */
+ int media_type; /**< Type of media file : internal/external */
+ char mime_type[MEDIA_SVC_PATHNAME_SIZE]; /**< Full path and file name of media file */
+ int size;
+ int added_time; /**< added time */
+ int modified_time; /**< modified time */
+ char folder_uuid[MEDIA_SVC_UUID_SIZE+1]; /**< Unique ID of folder */
+ int album_id; /**< Unique ID of album */
+ char thumbnail_path[MEDIA_SVC_PATHNAME_SIZE]; /**< Thumbnail image file path */
+ int played_count; /**< played count */
+ int last_played_time; /**< last played time */
+ int last_played_position;
+ int favourate; /**< favourate. o or 1 */
+ int hiding; /**< hiding. o or 1 */
+ int is_drm; /**< is_drm. o or 1 */
+ int storage_type; /**< Storage of media file : internal/external */
+ media_svc_content_meta_s media_meta; /**< meta data structure for audio files */
+} media_svc_content_info_s;
+#else
+/**
+ * Media meta data information
+ */
+typedef struct {
+ char * title; /**< track title*/
+ char * album; /**< album name*/
+ char * artist; /**< artist name*/
+ char * genre; /**< genre of track*/
+ char * composer; /**< composer name*/
+ char * year; /**< year*/
+ char * recorded_date; /**< recorded date*/
+ char * copyright; /**< copyright*/
+ char * track_num; /**< track number*/
+ char * description; /**< description*/
+ int bitrate; /**< bitrate*/
+ int samplerate; /**< samplerate*/
+ int channel; /**< channel*/
+ int duration; /**< duration*/
+ float longitude; /**< longitude*/
+ float latitude; /**< latitude*/
+ float altitude; /**< altitude*/
+ int width; /**< width*/
+ int height; /**< height*/
+ char * datetaken; /**< datetaken*/
+ int orientation; /**< orientation*/
+ int rating; /**< user defined rating */
+} media_svc_content_meta_s;
+
+
+/**
+ * Media data information
+ */
+typedef struct {
+ char * media_uuid; /**< Unique ID of item */
+ char * path; /**< Full path of media file */
+ char * file_name; /**< File name of media file. Display name */
+ int media_type; /**< Type of media file : internal/external */
+ char * mime_type; /**< Full path and file name of media file */
+ unsigned long long size; /**< size */
+ time_t added_time; /**< added time, time_t */
+ time_t modified_time; /**< modified time, time_t */
+ char * folder_uuid; /**< Unique ID of folder */
+ int album_id; /**< Unique ID of album */
+ char * thumbnail_path; /**< Thumbnail image file path */
+ int played_count; /**< played count */
+ int last_played_time; /**< last played time */
+ int last_played_position; /**< last played position */
+ int favourate; /**< favourate. o or 1 */
+ int is_drm; /**< is_drm. o or 1 */
+ int storage_type; /**< Storage of media file : internal/external */
+ media_svc_content_meta_s media_meta; /**< meta data structure for audio files */
+} media_svc_content_info_s;
+#endif
+
+typedef enum{
+ MEDIA_SVC_QUERY_INSERT_ITEM,
+ MEDIA_SVC_QUERY_SET_ITEM_VALIDITY,
+ MEDIA_SVC_QUERY_MOVE_ITEM,
+} media_svc_query_type_e;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_MEDIA_SVC_ENV_H_*/
diff --git a/src/include/common/media-svc-media-folder.h b/src/include/common/media-svc-media-folder.h
new file mode 100755
index 0000000..3b9897a
--- /dev/null
+++ b/src/include/common/media-svc-media-folder.h
@@ -0,0 +1,35 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _MEDIA_SVC_MEDIA_FOLDER_H_
+#define _MEDIA_SVC_MEDIA_FOLDER_H_
+
+#include <sqlite3.h>
+#include <stdbool.h>
+#include "media-svc-types.h"
+
+int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *folder_name, char *folder_id);
+int _media_svc_append_folder(sqlite3 *handle, media_svc_storage_type_e storage_type, const char *folder_id, const char *path_name, const char *folder_name, int modified_date);
+int _media_svc_update_folder_modified_time_by_folder_uuid(sqlite3 *handle, const char *folder_uuid, const char *folder_path, bool stack_query);
+int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, const char *path, media_svc_storage_type_e storage_type, char *folder_id);
+int _media_svc_update_folder_table(sqlite3 *handle);
+
+#endif /*_MEDIA_SVC_MEDIA_FOLDER_H_*/
diff --git a/src/include/common/media-svc-media.h b/src/include/common/media-svc-media.h
new file mode 100755
index 0000000..1d83735
--- /dev/null
+++ b/src/include/common/media-svc-media.h
@@ -0,0 +1,48 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef _MEDIA_SVC_MEDIA_H_
+#define _MEDIA_SVC_MEDIA_H_
+
+#include <sqlite3.h>
+#include <stdbool.h>
+#include "media-svc-types.h"
+#include "media-svc-env.h"
+
+int _media_svc_count_record_with_path(sqlite3 *handle, const char *path, int *count);
+int _media_svc_insert_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info, bool stack_query);
+int _media_svc_update_item_with_data(sqlite3 *handle, media_svc_content_info_s *content_info);
+int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, char *thumbnail_path);
+int _media_svc_get_media_type_by_path(sqlite3 *handle, const char *path, int *media_type);
+int _media_svc_delete_item_by_path(sqlite3 *handle, const char *path);
+int _media_svc_truncate_table(sqlite3 *handle, media_svc_storage_type_e storage_type);
+int _media_svc_delete_invalid_items(sqlite3 *handle, media_svc_storage_type_e storage_type);
+int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *folder_path);
+int _media_svc_update_storage_item_validity(sqlite3 *handle, media_svc_storage_type_e storage_type, int validity);
+int _media_svc_update_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity);
+int _media_svc_update_recursive_folder_item_validity(sqlite3 *handle, const char *folder_path, int validity);
+int _media_svc_update_item_validity(sqlite3 *handle, const char *path, int validity, bool stack_query);
+int _media_svc_update_item_by_path(sqlite3 *handle, const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path, const char *file_name, int modified_time, const char *folder_uuid, const char *thumb_path, bool stack_query);
+int _media_svc_list_query_do(sqlite3 *handle, media_svc_query_type_e query_type);
+int _media_svc_get_media_id_by_path(sqlite3 *handle, const char *path, char *media_uuid, int max_length);
+int _media_svc_update_thumbnail_path(sqlite3 *handle, const char *path, const char *thumb_path);
+
+#endif /*_MEDIA_SVC_MEDIA_H_*/
diff --git a/src/include/common/media-svc-util.h b/src/include/common/media-svc-util.h
new file mode 100755
index 0000000..cd1f80f
--- /dev/null
+++ b/src/include/common/media-svc-util.h
@@ -0,0 +1,146 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+
+#ifndef _MEDIA_SVC_UTIL_H_
+#define _MEDIA_SVC_UTIL_H_
+
+#include <string.h>
+#include <stdbool.h>
+#include <sqlite3.h>
+#include "media-svc-types.h"
+#include "media-svc-env.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef FALSE
+#define FALSE 0
+#endif
+#ifndef TRUE
+#define TRUE 1
+#endif
+
+#define SAFE_FREE(src) { if(src) {free(src); src = NULL;}}
+#define STRING_VALID(str) \
+ ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
+
+char *_media_info_generate_uuid(void);
+char *_media_svc_escape_str(char *input, int len);
+void _strncpy_safe(char *x_dst, const char *x_src, int max_len);
+unsigned int _media_svc_get_current_time(void);
+int _media_svc_rename_file( const char *old_name, const char *new_name);
+bool _media_svc_remove_file(const char *path);
+int _media_svc_remove_all_files_in_dir(const char *dir_path);
+char *_media_svc_get_title_from_filepath (const char *path);
+int _media_svc_save_image(void *image, int size, char *image_path);
+bool _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format);
+bool _media_svc_get_file_ext(const char *file_path, char *file_ext);
+int _media_svc_get_file_time(const char *full_path);
+int _media_svc_set_media_info(media_svc_content_info_s *content_info, media_svc_storage_type_e storage_type, const char *path, const char *mime_type, media_svc_media_type_e media_type, bool refresh);
+int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info, media_svc_media_type_e media_type);
+int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type);
+int __media_svc_malloc_and_strncpy(char **dst, const char *src);
+void _media_svc_destroy_content_info(media_svc_content_info_s *content_info);
+int _media_svc_get_store_type_by_path(const char *path, media_svc_storage_type_e *storage_type);
+char *_media_svc_replace_path(char *s, const char *olds, const char *news);
+
+int _media_svc_error_convert(int error);
+
+/* Define data structures for media type and mime type */
+#define MEDIA_SVC_CATEGORY_UNKNOWN 0x00000000 /**< Default */
+#define MEDIA_SVC_CATEGORY_ETC 0x00000001 /**< ETC category */
+#define MEDIA_SVC_CATEGORY_IMAGE 0x00000002 /**< Image category */
+#define MEDIA_SVC_CATEGORY_VIDEO 0x00000004 /**< Video category */
+#define MEDIA_SVC_CATEGORY_MUSIC 0x00000008 /**< Music category */
+#define MEDIA_SVC_CATEGORY_SOUND 0x00000010 /**< Sound category */
+
+#define CONTENT_TYPE_NUM 4
+#define MUSIC_MIME_NUM 29
+#define SOUND_MIME_NUM 1
+#define MIME_TYPE_LENGTH 255
+#define MIME_LENGTH 50
+#define _3GP_FILE ".3gp"
+#define _MP4_FILE ".mp4"
+
+typedef struct {
+ char content_type[15];
+ int category_by_mime;
+} _media_svc_content_table_s;
+
+static const _media_svc_content_table_s content_category[CONTENT_TYPE_NUM] = {
+ {"audio", MEDIA_SVC_CATEGORY_SOUND},
+ {"image", MEDIA_SVC_CATEGORY_IMAGE},
+ {"video", MEDIA_SVC_CATEGORY_VIDEO},
+ {"application", MEDIA_SVC_CATEGORY_ETC},
+};
+
+static const char music_mime_table[MUSIC_MIME_NUM][MIME_LENGTH] = {
+ /*known mime types of normal files*/
+ "mpeg",
+ "ogg",
+ "x-ms-wma",
+ "x-flac",
+ "mp4",
+ /* known mime types of drm files*/
+ "mp3",
+ "x-mp3", /*alias of audio/mpeg*/
+ "x-mpeg", /*alias of audio/mpeg*/
+ "3gpp",
+ "x-ogg", /*alias of audio/ogg*/
+ "vnd.ms-playready.media.pya:*.pya", /*playready*/
+ "wma",
+ "aac",
+ "x-m4a", /*alias of audio/mp4*/
+ /* below mimes are rare*/
+ "x-vorbis+ogg",
+ "x-flac+ogg",
+ "x-matroska",
+ "ac3",
+ "mp2",
+ "x-ape",
+ "x-ms-asx",
+ "vnd.rn-realaudio",
+
+ "x-vorbis", /*alias of audio/x-vorbis+ogg*/
+ "vorbis", /*alias of audio/x-vorbis+ogg*/
+ "x-oggflac",
+ "x-mp2", /*alias of audio/mp2*/
+ "x-pn-realaudio", /*alias of audio/vnd.rn-realaudio*/
+ "vnd.m-realaudio", /*alias of audio/vnd.rn-realaudio*/
+ "x-wav",
+};
+
+static const char sound_mime_table[SOUND_MIME_NUM][MIME_LENGTH] = {
+ "x-smaf",
+};
+
+bool _media_svc_is_drm_file(const char *path);
+int _media_svc_get_mime_in_drm_info(const char *path, char *mime);
+int _media_svc_get_content_type_from_mime(const char * path, const char * mimetype, int * category);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /*_MEDIA_SVC_UTIL_H_*/
diff --git a/test/plugin/Makefile b/test/plugin/Makefile
new file mode 100644
index 0000000..94e3a27
--- /dev/null
+++ b/test/plugin/Makefile
@@ -0,0 +1,14 @@
+CC =gcc
+LIBS = libmedia-service
+
+OBJS = media_svc_plugin_test.o
+SRCS = media_svc_plugin_test.c
+TARGET = plugin_test
+
+TARGET : $(OBJS)
+ $(CC) -o $(TARGET) $(OBJS) -ldl `pkg-config $(LIBS) --cflags --libs` -g
+$(OBJS) : $(SRCS)
+ $(CC) -c $(SRCS) -I../../include -L../../cmake_build_tmp `pkg-config $(LIBS) --cflags --libs` -g
+clean :
+ rm $(TARGET)
+ rm $(OBJS)
diff --git a/test/plugin/media_svc_plugin_test.c b/test/plugin/media_svc_plugin_test.c
new file mode 100755
index 0000000..eb4023f
--- /dev/null
+++ b/test/plugin/media_svc_plugin_test.c
@@ -0,0 +1,234 @@
+/*
+ * libmedia-service
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+#include <media-svc.h>
+
+#define PLUGIN_SO_FILE_NAME "/usr/lib/libmedia-content-plugin.so"
+void *funcHandle = NULL;
+
+static void msg_print(int line, char *msg);
+
+int (*svc_check_item) (const char *file_path, const char * mime_type, char ** err_msg);
+int (*svc_connect) (void ** handle, char ** err_msg);
+int (*svc_disconnect) (void * handle, char ** err_msg);
+int (*svc_check_item_exist) (void* handle, const char *file_path, int storage_type, char ** err_msg);
+int (*svc_insert_item_immediately) (void* handle, const char *file_path, int storage_type, const char * mime_type, char ** err_msg);
+int (*svc_set_folder_item_validity) (void * handle, const char * folder_path, int validity, int recursive, char ** err_msg);
+int (*svc_delete_all_invalid_items_in_folder) (void * handle, const char *folder_path, char ** err_msg);
+
+int __load_functions()
+{
+ msg_print(__LINE__, "__load_functions");
+
+ funcHandle = dlopen (PLUGIN_SO_FILE_NAME, RTLD_LAZY);
+ if (!funcHandle) {
+ fprintf (stderr,"error: %s\n", dlerror());
+ }
+
+ svc_check_item = dlsym (funcHandle, "check_item");
+ svc_connect = dlsym (funcHandle, "connect");
+ svc_disconnect = dlsym (funcHandle, "disconnect");
+ svc_check_item_exist = dlsym (funcHandle, "check_item_exist");
+ svc_insert_item_immediately = dlsym (funcHandle, "insert_item_immediately");
+ svc_set_folder_item_validity = dlsym (funcHandle, "set_folder_item_validity");
+ svc_delete_all_invalid_items_in_folder = dlsym (funcHandle, "delete_all_invalid_items_in_folder");
+
+ if ( !svc_check_item ||
+ !svc_connect ||
+ !svc_disconnect ||
+ !svc_insert_item_immediately ||
+ !svc_set_folder_item_validity ||
+ !svc_delete_all_invalid_items_in_folder ||
+ !svc_check_item_exist) {
+ fprintf(stderr,"error: %s\n", dlerror());
+ return -1;
+ }
+
+ return 0;
+}
+
+int __unload_functions(void)
+{
+ msg_print(__LINE__, "__unload_functions");
+
+ if (funcHandle)
+ {
+ dlclose (funcHandle);
+ }
+
+ return 0;
+}
+
+int main()
+{
+ int ret = 0;
+ MediaSvcHandle * db_handle = NULL;
+ char * err_msg = NULL;
+ char path[1024] = {0,};
+ char type[1024] = {0,};
+
+ ret = __load_functions();
+ if(ret < 0) {
+ msg_print(__LINE__, "__load_functions error");
+ return -1;
+ } else {
+ msg_print(__LINE__, "__load_functions success");
+ }
+
+ //check_item ================================================
+ ret = svc_check_item("/opt/usr/media/Music/Over the horizon.mp3", "audio/mpeg", &err_msg);
+ if(ret < 0) {
+ msg_print(__LINE__, "svc_check_item error");
+ if(err_msg != NULL) {
+ printf("err_msg[%s]\n", err_msg);
+ free(err_msg);
+ err_msg = NULL;
+ }
+ __unload_functions();
+ return -1;
+ } else {
+ msg_print(__LINE__, "svc_check_item success");
+ }
+
+ //db open ==================================================
+ ret = svc_connect(&db_handle, &err_msg);
+ if(ret < 0) {
+ msg_print(__LINE__, "svc_connect error");
+ if(err_msg != NULL) {
+ printf("err_msg[%s]\n", err_msg);
+ free(err_msg);
+ err_msg = NULL;
+ }
+ __unload_functions();
+ return -1;
+ } else {
+ msg_print(__LINE__, "svc_connect success");
+ }
+
+#if 1
+ ret = media_svc_create_table(db_handle);
+ if (ret < 0) {
+ msg_print(__LINE__, "table already exists");
+ } else {
+ msg_print(__LINE__, "table create success");
+ }
+#endif
+
+#if 1
+ while (1) {
+
+ printf("Enter path and mimetype ( ex. /opt/usr/media/a.jpg image ) : ");
+ scanf("%s %s", path, type);
+
+ //check_item_exist ============================================
+ ret = svc_check_item_exist(db_handle, path, 0, &err_msg);
+ if(ret < 0) {
+ msg_print(__LINE__, "svc_check_item_exist error");
+ if(err_msg != NULL) {
+ printf("err_msg[%s]\n", err_msg);
+ free(err_msg);
+ err_msg = NULL;
+ }
+ //__unload_functions();
+ //return -1;
+ } else {
+ msg_print(__LINE__, "svc_check_item_exist success");
+ }
+
+ // svc_check_item_exist ============================================
+ ret = svc_insert_item_immediately(db_handle, path, 0, type, &err_msg);
+ if(ret < 0) {
+ msg_print(__LINE__, "svc_insert_item_immediately error");
+ if(err_msg != NULL) {
+ printf("err_msg[%s]\n", err_msg);
+ free(err_msg);
+ err_msg = NULL;
+ }
+ //__unload_functions();
+ //return -1;
+ } else {
+ msg_print(__LINE__, "svc_insert_item_immediately success");
+ }
+ } // End of While
+
+ ret = media_svc_insert_folder(db_handle, 0, path);
+ if(ret < 0) {
+ msg_print(__LINE__, "media_svc_insert_folder error ");
+ } else {
+ msg_print(__LINE__, "media_svc_insert_folder success");
+ }
+#endif
+
+ //folder test ==================================================
+ char *folder_path = "/opt/usr/media/Sounds";
+ ret = svc_set_folder_item_validity(db_handle, folder_path, 0, 1, &err_msg);
+ if(ret < 0) {
+ msg_print(__LINE__, "svc_set_folder_item_validity error");
+ if(err_msg != NULL) {
+ printf("err_msg[%s]\n", err_msg);
+ free(err_msg);
+ err_msg = NULL;
+ }
+ } else {
+ msg_print(__LINE__, "svc_insert_item_immediately success");
+ }
+
+ ret = svc_delete_all_invalid_items_in_folder(db_handle, folder_path, &err_msg);
+ if(ret < 0) {
+ msg_print(__LINE__, "svc_delete_all_invalid_items_in_folder error");
+ if(err_msg != NULL) {
+ printf("err_msg[%s]\n", err_msg);
+ free(err_msg);
+ err_msg = NULL;
+ }
+ } else {
+ msg_print(__LINE__, "svc_insert_item_immediately success");
+ }
+
+ //db close ==================================================
+ ret = svc_disconnect(db_handle, &err_msg);
+ if(ret < 0) {
+ msg_print(__LINE__, "svc_disconnect error");
+ if(err_msg != NULL) {
+ printf("err_msg[%s]\n", err_msg);
+ free(err_msg);
+ err_msg = NULL;
+ }
+ __unload_functions();
+ return -1;
+ } else {
+ msg_print(__LINE__, "svc_disconnect success");
+ }
+
+ __unload_functions();
+
+ return 0;
+}
+
+
+static void msg_print(int line, char *msg)
+{
+ fprintf(stderr, "[%d]%s\n", line, msg);
+}
+
diff --git a/uuid/clear.c b/uuid/clear.c
new file mode 100644
index 0000000..2d91fee
--- /dev/null
+++ b/uuid/clear.c
@@ -0,0 +1,43 @@
+/*
+ * clear.c -- Clear a UUID
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * 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, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 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 not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#include "string.h"
+
+#include "uuidP.h"
+
+void uuid_clear(uuid_t uu)
+{
+ memset(uu, 0, 16);
+}
+
diff --git a/uuid/compare.c b/uuid/compare.c
new file mode 100644
index 0000000..f28a726
--- /dev/null
+++ b/uuid/compare.c
@@ -0,0 +1,55 @@
+/*
+ * compare.c --- compare whether or not two UUID's are the same
+ *
+ * Returns 0 if the two UUID's are different, and 1 if they are the same.
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * 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, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 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 not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#include "uuidP.h"
+#include <string.h>
+
+#define UUCMP(u1,u2) if (u1 != u2) return((u1 < u2) ? -1 : 1);
+
+int uuid_compare(const uuid_t uu1, const uuid_t uu2)
+{
+ struct uuid uuid1, uuid2;
+
+ uuid_unpack(uu1, &uuid1);
+ uuid_unpack(uu2, &uuid2);
+
+ UUCMP(uuid1.time_low, uuid2.time_low);
+ UUCMP(uuid1.time_mid, uuid2.time_mid);
+ UUCMP(uuid1.time_hi_and_version, uuid2.time_hi_and_version);
+ UUCMP(uuid1.clock_seq, uuid2.clock_seq);
+ return memcmp(uuid1.node, uuid2.node, 6);
+}
+
diff --git a/uuid/copy.c b/uuid/copy.c
new file mode 100644
index 0000000..ead33aa
--- /dev/null
+++ b/uuid/copy.c
@@ -0,0 +1,45 @@
+/*
+ * copy.c --- copy UUIDs
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * 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, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 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 not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#include "uuidP.h"
+
+void uuid_copy(uuid_t dst, const uuid_t src)
+{
+ unsigned char *cp1;
+ const unsigned char *cp2;
+ int i;
+
+ for (i=0, cp1 = dst, cp2 = src; i < 16; i++)
+ *cp1++ = *cp2++;
+}
diff --git a/uuid/gen_uuid.c b/uuid/gen_uuid.c
new file mode 100644
index 0000000..48a7f4a
--- /dev/null
+++ b/uuid/gen_uuid.c
@@ -0,0 +1,672 @@
+/*
+ * gen_uuid.c --- generate a DCE-compatible uuid
+ *
+ * Copyright (C) 1996, 1997, 1998, 1999 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * 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, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 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 not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+/*
+ * Force inclusion of SVID stuff since we need it if we're compiling in
+ * gcc-wall wall mode
+ */
+#define _SVID_SOURCE
+
+#ifdef _WIN32
+#define _WIN32_WINNT 0x0500
+#include <windows.h>
+#define UUID MYUUID
+#endif
+#include <stdio.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#include <sys/wait.h>
+#include <sys/stat.h>
+#ifdef HAVE_SYS_FILE_H
+#include <sys/file.h>
+#endif
+#ifdef HAVE_SYS_IOCTL_H
+#include <sys/ioctl.h>
+#endif
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+#ifdef HAVE_SYS_SOCKIO_H
+#include <sys/sockio.h>
+#endif
+#ifdef HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_NET_IF_DL_H
+#include <net/if_dl.h>
+#endif
+#if defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)
+#include <sys/syscall.h>
+#endif
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
+
+#include "uuidP.h"
+#include "uuidd.h"
+
+#ifdef HAVE_SRANDOM
+#define srand(x) srandom(x)
+#define rand() random()
+#endif
+
+#ifdef TLS
+#define THREAD_LOCAL static TLS
+#else
+#define THREAD_LOCAL static
+#endif
+
+#if defined(__linux__) && defined(__NR_gettid) && defined(HAVE_JRAND48)
+#define DO_JRAND_MIX
+THREAD_LOCAL unsigned short jrand_seed[3];
+#endif
+
+#ifdef _WIN32
+static void gettimeofday (struct timeval *tv, void *dummy)
+{
+ FILETIME ftime;
+ uint64_t n;
+
+ GetSystemTimeAsFileTime (&ftime);
+ n = (((uint64_t) ftime.dwHighDateTime << 32)
+ + (uint64_t) ftime.dwLowDateTime);
+ if (n) {
+ n /= 10;
+ n -= ((369 * 365 + 89) * (uint64_t) 86400) * 1000000;
+ }
+
+ tv->tv_sec = n / 1000000;
+ tv->tv_usec = n % 1000000;
+}
+
+static int getuid (void)
+{
+ return 1;
+}
+#endif
+
+static int get_random_fd(void)
+{
+ struct timeval tv;
+ static int fd = -2;
+ int i;
+
+ if (fd == -2) {
+ gettimeofday(&tv, 0);
+#ifndef _WIN32
+ fd = open("/dev/urandom", O_RDONLY);
+ if (fd == -1)
+ fd = open("/dev/random", O_RDONLY | O_NONBLOCK);
+ if (fd >= 0) {
+ i = fcntl(fd, F_GETFD);
+ if (i >= 0)
+ fcntl(fd, F_SETFD, i | FD_CLOEXEC);
+ }
+#endif
+ srand((getpid() << 16) ^ getuid() ^ tv.tv_sec ^ tv.tv_usec);
+#ifdef DO_JRAND_MIX
+ jrand_seed[0] = getpid() ^ (tv.tv_sec & 0xFFFF);
+ jrand_seed[1] = getppid() ^ (tv.tv_usec & 0xFFFF);
+ jrand_seed[2] = (tv.tv_sec ^ tv.tv_usec) >> 16;
+#endif
+ }
+ /* Crank the random number generator a few times */
+ gettimeofday(&tv, 0);
+ for (i = (tv.tv_sec ^ tv.tv_usec) & 0x1F; i > 0; i--)
+ rand();
+ return fd;
+}
+
+
+/*
+ * Generate a series of random bytes. Use /dev/urandom if possible,
+ * and if not, use srandom/random.
+ */
+static void get_random_bytes(void *buf, int nbytes)
+{
+ int i, n = nbytes, fd = get_random_fd();
+ int lose_counter = 0;
+ unsigned char *cp = (unsigned char *) buf;
+#ifdef DO_JRAND_MIX
+ unsigned short tmp_seed[3];
+#endif
+
+ if (fd >= 0) {
+ while (n > 0) {
+ i = read(fd, cp, n);
+ if (i <= 0) {
+ if (lose_counter++ > 16)
+ break;
+ continue;
+ }
+ n -= i;
+ cp += i;
+ lose_counter = 0;
+ }
+ }
+
+ /*
+ * We do this all the time, but this is the only source of
+ * randomness if /dev/random/urandom is out to lunch.
+ */
+ for (cp = buf, i = 0; i < nbytes; i++)
+ *cp++ ^= (rand() >> 7) & 0xFF;
+#ifdef DO_JRAND_MIX
+ memcpy(tmp_seed, jrand_seed, sizeof(tmp_seed));
+ jrand_seed[2] = jrand_seed[2] ^ syscall(__NR_gettid);
+ for (cp = buf, i = 0; i < nbytes; i++)
+ *cp++ ^= (jrand48(tmp_seed) >> 7) & 0xFF;
+ memcpy(jrand_seed, tmp_seed,
+ sizeof(jrand_seed)-sizeof(unsigned short));
+#endif
+
+ return;
+}
+
+/*
+ * Get the ethernet hardware address, if we can find it...
+ *
+ * XXX for a windows version, probably should use GetAdaptersInfo:
+ * http://www.codeguru.com/cpp/i-n/network/networkinformation/article.php/c5451
+ * commenting out get_node_id just to get gen_uuid to compile under windows
+ * is not the right way to go!
+ */
+static int get_node_id(unsigned char *node_id)
+{
+#ifdef HAVE_NET_IF_H
+ int sd;
+ struct ifreq ifr, *ifrp;
+ struct ifconf ifc;
+ char buf[1024];
+ int n, i;
+ unsigned char *a;
+#ifdef HAVE_NET_IF_DL_H
+ struct sockaddr_dl *sdlp;
+#endif
+
+/*
+ * BSD 4.4 defines the size of an ifreq to be
+ * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len
+ * However, under earlier systems, sa_len isn't present, so the size is
+ * just sizeof(struct ifreq)
+ */
+#ifdef HAVE_SA_LEN
+#ifndef max
+#define max(a,b) ((a) > (b) ? (a) : (b))
+#endif
+#define ifreq_size(i) max(sizeof(struct ifreq),\
+ sizeof((i).ifr_name)+(i).ifr_addr.sa_len)
+#else
+#define ifreq_size(i) sizeof(struct ifreq)
+#endif /* HAVE_SA_LEN*/
+
+ sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
+ if (sd < 0) {
+ return -1;
+ }
+ memset(buf, 0, sizeof(buf));
+ ifc.ifc_len = sizeof(buf);
+ ifc.ifc_buf = buf;
+ if (ioctl (sd, SIOCGIFCONF, (char *)&ifc) < 0) {
+ close(sd);
+ return -1;
+ }
+ n = ifc.ifc_len;
+ for (i = 0; i < n; i+= ifreq_size(*ifrp) ) {
+ ifrp = (struct ifreq *)((char *) ifc.ifc_buf+i);
+ strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ);
+#ifdef SIOCGIFHWADDR
+ if (ioctl(sd, SIOCGIFHWADDR, &ifr) < 0)
+ continue;
+ a = (unsigned char *) &ifr.ifr_hwaddr.sa_data;
+#else
+#ifdef SIOCGENADDR
+ if (ioctl(sd, SIOCGENADDR, &ifr) < 0)
+ continue;
+ a = (unsigned char *) ifr.ifr_enaddr;
+#else
+#ifdef HAVE_NET_IF_DL_H
+ sdlp = (struct sockaddr_dl *) &ifrp->ifr_addr;
+ if ((sdlp->sdl_family != AF_LINK) || (sdlp->sdl_alen != 6))
+ continue;
+ a = (unsigned char *) &sdlp->sdl_data[sdlp->sdl_nlen];
+#else
+ /*
+ * XXX we don't have a way of getting the hardware
+ * address
+ */
+ close(sd);
+ return 0;
+#endif /* HAVE_NET_IF_DL_H */
+#endif /* SIOCGENADDR */
+#endif /* SIOCGIFHWADDR */
+ if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])
+ continue;
+ if (node_id) {
+ memcpy(node_id, a, 6);
+ close(sd);
+ return 1;
+ }
+ }
+ close(sd);
+#endif
+ return 0;
+}
+
+/* Assume that the gettimeofday() has microsecond granularity */
+#define MAX_ADJUSTMENT 10
+
+static int get_clock(uint32_t *clock_high, uint32_t *clock_low,
+ uint16_t *ret_clock_seq, int *num)
+{
+ THREAD_LOCAL int adjustment = 0;
+ THREAD_LOCAL struct timeval last = {0, 0};
+ THREAD_LOCAL int state_fd = -2;
+ THREAD_LOCAL FILE *state_f;
+ THREAD_LOCAL uint16_t clock_seq;
+ struct timeval tv;
+ struct flock fl;
+ uint64_t clock_reg;
+ mode_t save_umask;
+ int len;
+
+ if (state_fd == -2) {
+ save_umask = umask(0);
+ state_fd = open("/var/lib/libuuid/clock.txt",
+ O_RDWR|O_CREAT, 0660);
+ (void) umask(save_umask);
+ state_f = fdopen(state_fd, "r+");
+ if (!state_f) {
+ close(state_fd);
+ state_fd = -1;
+ }
+ }
+ fl.l_type = F_WRLCK;
+ fl.l_whence = SEEK_SET;
+ fl.l_start = 0;
+ fl.l_len = 0;
+ fl.l_pid = 0;
+ if (state_fd >= 0) {
+ rewind(state_f);
+ while (fcntl(state_fd, F_SETLKW, &fl) < 0) {
+ if ((errno == EAGAIN) || (errno == EINTR))
+ continue;
+ fclose(state_f);
+ close(state_fd);
+ state_fd = -1;
+ break;
+ }
+ }
+ if (state_fd >= 0) {
+ unsigned int cl;
+ unsigned long tv1, tv2;
+ int a;
+
+ if (fscanf(state_f, "clock: %04x tv: %lu %lu adj: %d\n",
+ &cl, &tv1, &tv2, &a) == 4) {
+ clock_seq = cl & 0x3FFF;
+ last.tv_sec = tv1;
+ last.tv_usec = tv2;
+ adjustment = a;
+ }
+ }
+
+ if ((last.tv_sec == 0) && (last.tv_usec == 0)) {
+ get_random_bytes(&clock_seq, sizeof(clock_seq));
+ clock_seq &= 0x3FFF;
+ gettimeofday(&last, 0);
+ last.tv_sec--;
+ }
+
+try_again:
+ gettimeofday(&tv, 0);
+ if ((tv.tv_sec < last.tv_sec) ||
+ ((tv.tv_sec == last.tv_sec) &&
+ (tv.tv_usec < last.tv_usec))) {
+ clock_seq = (clock_seq+1) & 0x3FFF;
+ adjustment = 0;
+ last = tv;
+ } else if ((tv.tv_sec == last.tv_sec) &&
+ (tv.tv_usec == last.tv_usec)) {
+ if (adjustment >= MAX_ADJUSTMENT)
+ goto try_again;
+ adjustment++;
+ } else {
+ adjustment = 0;
+ last = tv;
+ }
+
+ clock_reg = tv.tv_usec*10 + adjustment;
+ clock_reg += ((uint64_t) tv.tv_sec)*10000000;
+ clock_reg += (((uint64_t) 0x01B21DD2) << 32) + 0x13814000;
+
+ if (num && (*num > 1)) {
+ adjustment += *num - 1;
+ last.tv_usec += adjustment / 10;
+ adjustment = adjustment % 10;
+ last.tv_sec += last.tv_usec / 1000000;
+ last.tv_usec = last.tv_usec % 1000000;
+ }
+
+ if (state_fd > 0) {
+ rewind(state_f);
+ len = fprintf(state_f,
+ "clock: %04x tv: %016lu %08lu adj: %08d\n",
+ clock_seq, last.tv_sec, last.tv_usec, adjustment);
+ fflush(state_f);
+ if (ftruncate(state_fd, len) < 0) {
+ fprintf(state_f, " \n");
+ fflush(state_f);
+ }
+ rewind(state_f);
+ fl.l_type = F_UNLCK;
+ fcntl(state_fd, F_SETLK, &fl);
+ }
+
+ *clock_high = clock_reg >> 32;
+ *clock_low = clock_reg;
+ *ret_clock_seq = clock_seq;
+ return 0;
+}
+
+#if defined(USE_UUIDD) && defined(HAVE_SYS_UN_H)
+static ssize_t read_all(int fd, char *buf, size_t count)
+{
+ ssize_t ret;
+ ssize_t c = 0;
+ int tries = 0;
+
+ memset(buf, 0, count);
+ while (count > 0) {
+ ret = read(fd, buf, count);
+ if (ret <= 0) {
+ if ((errno == EAGAIN || errno == EINTR || ret == 0) &&
+ (tries++ < 5))
+ continue;
+ return c ? c : -1;
+ }
+ if (ret > 0)
+ tries = 0;
+ count -= ret;
+ buf += ret;
+ c += ret;
+ }
+ return c;
+}
+
+/*
+ * Close all file descriptors
+ */
+#define HAVE_GETDTABLESIZE 1
+static void close_all_fds(void)
+{
+ int i, max;
+
+#if defined(HAVE_SYSCONF) && defined(_SC_OPEN_MAX)
+ max = sysconf(_SC_OPEN_MAX);
+#elif defined(HAVE_GETDTABLESIZE)
+ max = getdtablesize();
+#elif defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
+ struct rlimit rl;
+
+ getrlimit(RLIMIT_NOFILE, &rl);
+ max = rl.rlim_cur;
+#else
+ max = OPEN_MAX;
+#endif
+
+ for (i=0; i < max; i++) {
+ close(i);
+ if (i <= 2)
+ open("/dev/null", O_RDWR);
+ }
+}
+#endif
+
+/*
+ * Try using the uuidd daemon to generate the UUID
+ *
+ * Returns 0 on success, non-zero on failure.
+ */
+static int get_uuid_via_daemon(int op, uuid_t out, int *num)
+{
+#if defined(USE_UUIDD) && defined(HAVE_SYS_UN_H)
+ char op_buf[64];
+ int op_len;
+ int s;
+ ssize_t ret;
+ int32_t reply_len = 0, expected = 16;
+ struct sockaddr_un srv_addr;
+ struct stat st;
+ pid_t pid;
+ static const char *uuidd_path = UUIDD_PATH;
+ static int access_ret = -2;
+ static int start_attempts = 0;
+
+ if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
+ return -1;
+
+ srv_addr.sun_family = AF_UNIX;
+ strcpy(srv_addr.sun_path, UUIDD_SOCKET_PATH);
+
+ if (connect(s, (const struct sockaddr *) &srv_addr,
+ sizeof(struct sockaddr_un)) < 0) {
+ if (access_ret == -2)
+ access_ret = access(uuidd_path, X_OK);
+ if (access_ret == 0)
+ access_ret = stat(uuidd_path, &st);
+ if (access_ret == 0 && (st.st_mode & (S_ISUID | S_ISGID)) == 0)
+ access_ret = access(UUIDD_DIR, W_OK);
+ if (access_ret == 0 && start_attempts++ < 5) {
+ if ((pid = fork()) == 0) {
+ close_all_fds();
+ execl(uuidd_path, "uuidd", "-qT", "300",
+ (char *) NULL);
+ exit(1);
+ }
+ (void) waitpid(pid, 0, 0);
+ if (connect(s, (const struct sockaddr *) &srv_addr,
+ sizeof(struct sockaddr_un)) < 0)
+ goto fail;
+ } else
+ goto fail;
+ }
+ op_buf[0] = op;
+ op_len = 1;
+ if (op == UUIDD_OP_BULK_TIME_UUID) {
+ memcpy(op_buf+1, num, sizeof(*num));
+ op_len += sizeof(*num);
+ expected += sizeof(*num);
+ }
+
+ ret = write(s, op_buf, op_len);
+ if (ret < 1)
+ goto fail;
+
+ ret = read_all(s, (char *) &reply_len, sizeof(reply_len));
+ if (ret < 0)
+ goto fail;
+
+ if (reply_len != expected)
+ goto fail;
+
+ ret = read_all(s, op_buf, reply_len);
+
+ if (op == UUIDD_OP_BULK_TIME_UUID)
+ memcpy(op_buf+16, num, sizeof(int));
+
+ memcpy(out, op_buf, 16);
+
+ close(s);
+ return ((ret == expected) ? 0 : -1);
+
+fail:
+ close(s);
+#endif
+ return -1;
+}
+
+void uuid__generate_time(uuid_t out, int *num)
+{
+ static unsigned char node_id[6];
+ static int has_init = 0;
+ struct uuid uu;
+ uint32_t clock_mid;
+
+ if (!has_init) {
+ if (get_node_id(node_id) <= 0) {
+ get_random_bytes(node_id, 6);
+ /*
+ * Set multicast bit, to prevent conflicts
+ * with IEEE 802 addresses obtained from
+ * network cards
+ */
+ node_id[0] |= 0x01;
+ }
+ has_init = 1;
+ }
+ get_clock(&clock_mid, &uu.time_low, &uu.clock_seq, num);
+ uu.clock_seq |= 0x8000;
+ uu.time_mid = (uint16_t) clock_mid;
+ uu.time_hi_and_version = ((clock_mid >> 16) & 0x0FFF) | 0x1000;
+ memcpy(uu.node, node_id, 6);
+ uuid_pack(&uu, out);
+}
+
+void uuid_generate_time(uuid_t out)
+{
+#ifdef TLS
+ THREAD_LOCAL int num = 0;
+ THREAD_LOCAL struct uuid uu;
+ THREAD_LOCAL time_t last_time = 0;
+ time_t now;
+
+ if (num > 0) {
+ now = time(0);
+ if (now > last_time+1)
+ num = 0;
+ }
+ if (num <= 0) {
+ num = 1000;
+ if (get_uuid_via_daemon(UUIDD_OP_BULK_TIME_UUID,
+ out, &num) == 0) {
+ last_time = time(0);
+ uuid_unpack(out, &uu);
+ num--;
+ return;
+ }
+ num = 0;
+ }
+ if (num > 0) {
+ uu.time_low++;
+ if (uu.time_low == 0) {
+ uu.time_mid++;
+ if (uu.time_mid == 0)
+ uu.time_hi_and_version++;
+ }
+ num--;
+ uuid_pack(&uu, out);
+ return;
+ }
+#else
+ if (get_uuid_via_daemon(UUIDD_OP_TIME_UUID, out, 0) == 0)
+ return;
+#endif
+
+ uuid__generate_time(out, 0);
+}
+
+
+void uuid__generate_random(uuid_t out, int *num)
+{
+ uuid_t buf;
+ struct uuid uu;
+ int i, n;
+
+ if (!num || !*num)
+ n = 1;
+ else
+ n = *num;
+
+ for (i = 0; i < n; i++) {
+ get_random_bytes(buf, sizeof(buf));
+ uuid_unpack(buf, &uu);
+
+ uu.clock_seq = (uu.clock_seq & 0x3FFF) | 0x8000;
+ uu.time_hi_and_version = (uu.time_hi_and_version & 0x0FFF)
+ | 0x4000;
+ uuid_pack(&uu, out);
+ out += sizeof(uuid_t);
+ }
+}
+
+void uuid_generate_random(uuid_t out)
+{
+ int num = 1;
+ /* No real reason to use the daemon for random uuid's -- yet */
+
+ uuid__generate_random(out, &num);
+}
+
+
+/*
+ * This is the generic front-end to uuid_generate_random and
+ * uuid_generate_time. It uses uuid_generate_random only if
+ * /dev/urandom is available, since otherwise we won't have
+ * high-quality randomness.
+ */
+void uuid_generate(uuid_t out)
+{
+ if (get_random_fd() >= 0)
+ uuid_generate_random(out);
+ else
+ uuid_generate_time(out);
+}
diff --git a/uuid/isnull.c b/uuid/isnull.c
new file mode 100644
index 0000000..931e7e7
--- /dev/null
+++ b/uuid/isnull.c
@@ -0,0 +1,48 @@
+/*
+ * isnull.c --- Check whether or not the UUID is null
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * 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, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 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 not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#include "uuidP.h"
+
+/* Returns 1 if the uuid is the NULL uuid */
+int uuid_is_null(const uuid_t uu)
+{
+ const unsigned char *cp;
+ int i;
+
+ for (i=0, cp = uu; i < 16; i++)
+ if (*cp++)
+ return 0;
+ return 1;
+}
+
diff --git a/uuid/pack.c b/uuid/pack.c
new file mode 100644
index 0000000..097516d
--- /dev/null
+++ b/uuid/pack.c
@@ -0,0 +1,69 @@
+/*
+ * Internal routine for packing UUID's
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * 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, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 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 not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#include <string.h>
+#include "uuidP.h"
+
+void uuid_pack(const struct uuid *uu, uuid_t ptr)
+{
+ uint32_t tmp;
+ unsigned char *out = ptr;
+
+ tmp = uu->time_low;
+ out[3] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[2] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[1] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[0] = (unsigned char) tmp;
+
+ tmp = uu->time_mid;
+ out[5] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[4] = (unsigned char) tmp;
+
+ tmp = uu->time_hi_and_version;
+ out[7] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[6] = (unsigned char) tmp;
+
+ tmp = uu->clock_seq;
+ out[9] = (unsigned char) tmp;
+ tmp >>= 8;
+ out[8] = (unsigned char) tmp;
+
+ memcpy(out+10, uu->node, 6);
+}
+
diff --git a/uuid/parse.c b/uuid/parse.c
new file mode 100644
index 0000000..074383e
--- /dev/null
+++ b/uuid/parse.c
@@ -0,0 +1,79 @@
+/*
+ * parse.c --- UUID parsing
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * 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, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 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 not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <string.h>
+
+#include "uuidP.h"
+
+int uuid_parse(const char *in, uuid_t uu)
+{
+ struct uuid uuid;
+ int i;
+ const char *cp;
+ char buf[3];
+
+ if (strlen(in) != 36)
+ return -1;
+ for (i=0, cp = in; i <= 36; i++,cp++) {
+ if ((i == 8) || (i == 13) || (i == 18) ||
+ (i == 23)) {
+ if (*cp == '-')
+ continue;
+ else
+ return -1;
+ }
+ if (i== 36)
+ if (*cp == 0)
+ continue;
+ if (!isxdigit(*cp))
+ return -1;
+ }
+ uuid.time_low = strtoul(in, NULL, 16);
+ uuid.time_mid = strtoul(in+9, NULL, 16);
+ uuid.time_hi_and_version = strtoul(in+14, NULL, 16);
+ uuid.clock_seq = strtoul(in+19, NULL, 16);
+ cp = in+24;
+ buf[2] = 0;
+ for (i=0; i < 6; i++) {
+ buf[0] = *cp++;
+ buf[1] = *cp++;
+ uuid.node[i] = strtoul(buf, NULL, 16);
+ }
+
+ uuid_pack(&uuid, uu);
+ return 0;
+}
diff --git a/uuid/unpack.c b/uuid/unpack.c
new file mode 100644
index 0000000..beaaff3
--- /dev/null
+++ b/uuid/unpack.c
@@ -0,0 +1,63 @@
+/*
+ * Internal routine for unpacking UUID
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * 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, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 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 not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#include <string.h>
+#include "uuidP.h"
+
+void uuid_unpack(const uuid_t in, struct uuid *uu)
+{
+ const uint8_t *ptr = in;
+ uint32_t tmp;
+
+ tmp = *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ uu->time_low = tmp;
+
+ tmp = *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ uu->time_mid = tmp;
+
+ tmp = *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ uu->time_hi_and_version = tmp;
+
+ tmp = *ptr++;
+ tmp = (tmp << 8) | *ptr++;
+ uu->clock_seq = tmp;
+
+ memcpy(uu->node, ptr, 6);
+}
+
diff --git a/uuid/unparse.c b/uuid/unparse.c
new file mode 100644
index 0000000..a95bbb0
--- /dev/null
+++ b/uuid/unparse.c
@@ -0,0 +1,76 @@
+/*
+ * unparse.c -- convert a UUID to string
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * 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, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 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 not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#include <stdio.h>
+
+#include "uuidP.h"
+
+static const char *fmt_lower =
+ "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
+
+static const char *fmt_upper =
+ "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X";
+
+#ifdef UUID_UNPARSE_DEFAULT_UPPER
+#define FMT_DEFAULT fmt_upper
+#else
+#define FMT_DEFAULT fmt_lower
+#endif
+
+static void uuid_unparse_x(const uuid_t uu, char *out, const char *fmt)
+{
+ struct uuid uuid;
+
+ uuid_unpack(uu, &uuid);
+ sprintf(out, fmt,
+ uuid.time_low, uuid.time_mid, uuid.time_hi_and_version,
+ uuid.clock_seq >> 8, uuid.clock_seq & 0xFF,
+ uuid.node[0], uuid.node[1], uuid.node[2],
+ uuid.node[3], uuid.node[4], uuid.node[5]);
+}
+
+void uuid_unparse_lower(const uuid_t uu, char *out)
+{
+ uuid_unparse_x(uu, out, fmt_lower);
+}
+
+void uuid_unparse_upper(const uuid_t uu, char *out)
+{
+ uuid_unparse_x(uu, out, fmt_upper);
+}
+
+void uuid_unparse(const uuid_t uu, char *out)
+{
+ uuid_unparse_x(uu, out, FMT_DEFAULT);
+}
diff --git a/uuid/uuid.h b/uuid/uuid.h
new file mode 100644
index 0000000..ca846da
--- /dev/null
+++ b/uuid/uuid.h
@@ -0,0 +1,103 @@
+/*
+ * Public include file for the UUID library
+ *
+ * Copyright (C) 1996, 1997, 1998 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * 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, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 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 not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifndef _UUID_UUID_H
+#define _UUID_UUID_H
+
+#include <sys/types.h>
+#ifndef _WIN32
+#include <sys/time.h>
+#endif
+#include <time.h>
+
+typedef unsigned char uuid_t[16];
+
+/* UUID Variant definitions */
+#define UUID_VARIANT_NCS 0
+#define UUID_VARIANT_DCE 1
+#define UUID_VARIANT_MICROSOFT 2
+#define UUID_VARIANT_OTHER 3
+
+/* UUID Type definitions */
+#define UUID_TYPE_DCE_TIME 1
+#define UUID_TYPE_DCE_RANDOM 4
+
+/* Allow UUID constants to be defined */
+#ifdef __GNUC__
+#define UUID_DEFINE(name,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15) \
+ static const uuid_t name __attribute__ ((unused)) = {u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15}
+#else
+#define UUID_DEFINE(name,u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15) \
+ static const uuid_t name = {u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,u10,u11,u12,u13,u14,u15}
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* clear.c */
+void uuid_clear(uuid_t uu);
+
+/* compare.c */
+int uuid_compare(const uuid_t uu1, const uuid_t uu2);
+
+/* copy.c */
+void uuid_copy(uuid_t dst, const uuid_t src);
+
+/* gen_uuid.c */
+void uuid_generate(uuid_t out);
+void uuid_generate_random(uuid_t out);
+void uuid_generate_time(uuid_t out);
+
+/* isnull.c */
+int uuid_is_null(const uuid_t uu);
+
+/* parse.c */
+int uuid_parse(const char *in, uuid_t uu);
+
+/* unparse.c */
+void uuid_unparse(const uuid_t uu, char *out);
+void uuid_unparse_lower(const uuid_t uu, char *out);
+void uuid_unparse_upper(const uuid_t uu, char *out);
+
+/* uuid_time.c */
+time_t uuid_time(const uuid_t uu, struct timeval *ret_tv);
+int uuid_type(const uuid_t uu);
+int uuid_variant(const uuid_t uu);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _UUID_UUID_H */
diff --git a/uuid/uuidP.h b/uuid/uuidP.h
new file mode 100644
index 0000000..86d86c5
--- /dev/null
+++ b/uuid/uuidP.h
@@ -0,0 +1,66 @@
+/*
+ * uuid.h -- private header file for uuids
+ *
+ * Copyright (C) 1996, 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * 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, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 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 not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifdef HAVE_INTTYPES_H
+#include <inttypes.h>
+#else
+#include <uuid/uuid_types.h>
+#endif
+#include <sys/types.h>
+
+#include <uuid/uuid.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+/*
+ * Offset between 15-Oct-1582 and 1-Jan-70
+ */
+#define TIME_OFFSET_HIGH 0x01B21DD2
+#define TIME_OFFSET_LOW 0x13814000
+
+struct uuid {
+ uint32_t time_low;
+ uint16_t time_mid;
+ uint16_t time_hi_and_version;
+ uint16_t clock_seq;
+ uint8_t node[6];
+};
+
+
+/*
+ * prototypes
+ */
+void uuid_pack(const struct uuid *uu, uuid_t ptr);
+void uuid_unpack(const uuid_t in, struct uuid *uu);
diff --git a/uuid/uuid_time.c b/uuid/uuid_time.c
new file mode 100644
index 0000000..f25f5c9
--- /dev/null
+++ b/uuid/uuid_time.c
@@ -0,0 +1,171 @@
+/*
+ * uuid_time.c --- Interpret the time field from a uuid. This program
+ * violates the UUID abstraction barrier by reaching into the guts
+ * of a UUID and interpreting it.
+ *
+ * Copyright (C) 1998, 1999 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * 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, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 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 not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifdef _WIN32
+#define _WIN32_WINNT 0x0500
+#include <windows.h>
+#define UUID MYUUID
+#endif
+
+#include <stdio.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <stdlib.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#include <time.h>
+
+#include "uuidP.h"
+
+time_t uuid_time(const uuid_t uu, struct timeval *ret_tv)
+{
+ struct timeval tv;
+ struct uuid uuid;
+ uint32_t high;
+ uint64_t clock_reg;
+
+ uuid_unpack(uu, &uuid);
+
+ high = uuid.time_mid | ((uuid.time_hi_and_version & 0xFFF) << 16);
+ clock_reg = uuid.time_low | ((uint64_t) high << 32);
+
+ clock_reg -= (((uint64_t) 0x01B21DD2) << 32) + 0x13814000;
+ tv.tv_sec = clock_reg / 10000000;
+ tv.tv_usec = (clock_reg % 10000000) / 10;
+
+ if (ret_tv)
+ *ret_tv = tv;
+
+ return tv.tv_sec;
+}
+
+int uuid_type(const uuid_t uu)
+{
+ struct uuid uuid;
+
+ uuid_unpack(uu, &uuid);
+ return ((uuid.time_hi_and_version >> 12) & 0xF);
+}
+
+int uuid_variant(const uuid_t uu)
+{
+ struct uuid uuid;
+ int var;
+
+ uuid_unpack(uu, &uuid);
+ var = uuid.clock_seq;
+
+ if ((var & 0x8000) == 0)
+ return UUID_VARIANT_NCS;
+ if ((var & 0x4000) == 0)
+ return UUID_VARIANT_DCE;
+ if ((var & 0x2000) == 0)
+ return UUID_VARIANT_MICROSOFT;
+ return UUID_VARIANT_OTHER;
+}
+
+#ifdef DEBUG
+static const char *variant_string(int variant)
+{
+ switch (variant) {
+ case UUID_VARIANT_NCS:
+ return "NCS";
+ case UUID_VARIANT_DCE:
+ return "DCE";
+ case UUID_VARIANT_MICROSOFT:
+ return "Microsoft";
+ default:
+ return "Other";
+ }
+}
+
+
+int
+main(int argc, char **argv)
+{
+ uuid_t buf;
+ time_t time_reg;
+ struct timeval tv;
+ int type, variant;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s uuid\n", argv[0]);
+ exit(1);
+ }
+ if (uuid_parse(argv[1], buf)) {
+ fprintf(stderr, "Invalid UUID: %s\n", argv[1]);
+ exit(1);
+ }
+ variant = uuid_variant(buf);
+ type = uuid_type(buf);
+ time_reg = uuid_time(buf, &tv);
+
+ printf("UUID variant is %d (%s)\n", variant, variant_string(variant));
+ if (variant != UUID_VARIANT_DCE) {
+ printf("Warning: This program only knows how to interpret "
+ "DCE UUIDs.\n\tThe rest of the output is likely "
+ "to be incorrect!!\n");
+ }
+ printf("UUID type is %d", type);
+ switch (type) {
+ case 1:
+ printf(" (time based)\n");
+ break;
+ case 2:
+ printf(" (DCE)\n");
+ break;
+ case 3:
+ printf(" (name-based)\n");
+ break;
+ case 4:
+ printf(" (random)\n");
+ break;
+ default:
+ printf("\n");
+ }
+ if (type != 1) {
+ printf("Warning: not a time-based UUID, so UUID time "
+ "decoding will likely not work!\n");
+ }
+ printf("UUID time is: (%ld, %ld): %s\n", tv.tv_sec, tv.tv_usec,
+ ctime(&time_reg));
+
+ return 0;
+}
+#endif
diff --git a/uuid/uuid_types.h b/uuid/uuid_types.h
new file mode 100644
index 0000000..169a88a
--- /dev/null
+++ b/uuid/uuid_types.h
@@ -0,0 +1,50 @@
+/*
+ * If linux/types.h is already been included, assume it has defined
+ * everything we need. (cross fingers) Other header files may have
+ * also defined the types that we need.
+ */
+#if (!defined(_STDINT_H) && !defined(_UUID_STDINT_H))
+#define _UUID_STDINT_H
+
+typedef unsigned char uint8_t;
+typedef signed char int8_t;
+
+#if (4 == 8)
+typedef int int64_t;
+typedef unsigned int uint64_t;
+#elif (4 == 8)
+typedef long int64_t;
+typedef unsigned long uint64_t;
+#elif (8 == 8)
+#if defined(__GNUC__)
+typedef __signed__ long long int64_t;
+#else
+typedef signed long long int64_t;
+#endif
+typedef unsigned long long uint64_t;
+#endif
+
+#if (4 == 2)
+typedef int int16_t;
+typedef unsigned int uint16_t;
+#elif (2 == 2)
+typedef short int16_t;
+typedef unsigned short uint16_t;
+#else
+ ?==error: undefined 16 bit type
+#endif
+
+#if (4 == 4)
+typedef int int32_t;
+typedef unsigned int uint32_t;
+#elif (4 == 4)
+typedef long int32_t;
+typedef unsigned long uint32_t;
+#elif (2 == 4)
+typedef short int32_t;
+typedef unsigned short uint32_t;
+#else
+ ?== error: undefined 32 bit type
+#endif
+
+#endif
diff --git a/uuid/uuidd.h b/uuid/uuidd.h
new file mode 100644
index 0000000..c71f4b7
--- /dev/null
+++ b/uuid/uuidd.h
@@ -0,0 +1,54 @@
+/*
+ * Definitions used by the uuidd daemon
+ *
+ * Copyright (C) 2007 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * 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, and the entire permission notice in its entirety,
+ * including the disclaimer of warranties.
+ * 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 not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY 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 NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ * %End-Header%
+ */
+
+#ifndef _UUID_UUIDD_H
+#define _UUID_UUIDD_H
+
+#define UUIDD_DIR "/var/lib/libuuid"
+#define UUIDD_SOCKET_PATH UUIDD_DIR "/request"
+#define UUIDD_PIDFILE_PATH UUIDD_DIR "/uuidd.pid"
+#define UUIDD_PATH "/usr/sbin/uuidd"
+
+#define UUIDD_OP_GETPID 0
+#define UUIDD_OP_GET_MAXOP 1
+#define UUIDD_OP_TIME_UUID 2
+#define UUIDD_OP_RANDOM_UUID 3
+#define UUIDD_OP_BULK_TIME_UUID 4
+#define UUIDD_OP_BULK_RANDOM_UUID 5
+#define UUIDD_MAX_OP UUIDD_OP_BULK_RANDOM_UUID
+
+extern void uuid__generate_time(uuid_t out, int *num);
+extern void uuid__generate_random(uuid_t out, int *num);
+
+#endif /* _UUID_UUID_H */