pax_global_header00006660000000000000000000000064115664626760014535gustar00rootroot0000000000000052 comment=781d866bc12eec293007851fe3c300d0f5a301d3 libphone-utils-0.1+git20110523/000077500000000000000000000000001156646267600157305ustar00rootroot00000000000000libphone-utils-0.1+git20110523/AUTHORS000066400000000000000000000000341156646267600167750ustar00rootroot00000000000000Tom Hacohen (tom@stosb.com) libphone-utils-0.1+git20110523/COPYING000066400000000000000000000167251156646267600167760ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. 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 that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU 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 as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. libphone-utils-0.1+git20110523/ChangeLog000066400000000000000000000000001156646267600174700ustar00rootroot00000000000000libphone-utils-0.1+git20110523/INSTALL000066400000000000000000000224501156646267600167640ustar00rootroot00000000000000Installation Instructions ************************* Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This file is free documentation; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. Basic Installation ================== Briefly, the shell commands `./configure; make; make install' should configure, build, and install this package. The following more-detailed instructions are generic; see the `README' file for instructions specific to this package. The `configure' shell script attempts to guess correct values for various system-dependent variables used during compilation. It uses those values to create a `Makefile' in each directory of the package. It may also create one or more `.h' files containing system-dependent definitions. Finally, it creates a shell script `config.status' that you can run in the future to recreate the current configuration, and a file `config.log' containing compiler output (useful mainly for debugging `configure'). It can also use an optional file (typically called `config.cache' and enabled with `--cache-file=config.cache' or simply `-C') that saves the results of its tests to speed up reconfiguring. Caching is disabled by default to prevent problems with accidental use of stale cache files. If you need to do unusual things to compile the package, please try to figure out how `configure' could check whether to do them, and mail diffs or instructions to the address given in the `README' so they can be considered for the next release. If you are using the cache, and at some point `config.cache' contains results you don't want to keep, you may remove or edit it. The file `configure.ac' (or `configure.in') is used to create `configure' by a program called `autoconf'. You need `configure.ac' if you want to change it or regenerate `configure' using a newer version of `autoconf'. The simplest way to compile this package is: 1. `cd' to the directory containing the package's source code and type `./configure' to configure the package for your system. Running `configure' might take a while. While running, it prints some messages telling which features it is checking for. 2. Type `make' to compile the package. 3. Optionally, type `make check' to run any self-tests that come with the package. 4. Type `make install' to install the programs and any data files and documentation. 5. You can remove the program binaries and object files from the source code directory by typing `make clean'. To also remove the files that `configure' created (so you can compile the package for a different kind of computer), type `make distclean'. There is also a `make maintainer-clean' target, but that is intended mainly for the package's developers. If you use it, you may have to get all sorts of other programs in order to regenerate files that came with the distribution. 6. Often, you can also type `make uninstall' to remove the installed files again. Compilers and Options ===================== Some systems require unusual options for compilation or linking that the `configure' script does not know about. Run `./configure --help' for details on some of the pertinent environment variables. You can give `configure' initial values for configuration parameters by setting variables in the command line or in the environment. Here is an example: ./configure CC=c99 CFLAGS=-g LIBS=-lposix *Note Defining Variables::, for more details. Compiling For Multiple Architectures ==================================== You can compile the package for more than one kind of computer at the same time, by placing the object files for each architecture in their own directory. To do this, you can use GNU `make'. `cd' to the directory where you want the object files and executables to go and run the `configure' script. `configure' automatically checks for the source code in the directory that `configure' is in and in `..'. With a non-GNU `make', it is safer to compile the package for one architecture at a time in the source code directory. After you have installed the package for one architecture, use `make distclean' before reconfiguring for another architecture. Installation Names ================== By default, `make install' installs the package's commands under `/usr/local/bin', include files under `/usr/local/include', etc. You can specify an installation prefix other than `/usr/local' by giving `configure' the option `--prefix=PREFIX'. You can specify separate installation prefixes for architecture-specific files and architecture-independent files. If you pass the option `--exec-prefix=PREFIX' to `configure', the package uses PREFIX as the prefix for installing programs and libraries. Documentation and other data files still use the regular prefix. In addition, if you use an unusual directory layout you can give options like `--bindir=DIR' to specify different values for particular kinds of files. Run `configure --help' for a list of the directories you can set and what kinds of files go in them. If the package supports it, you can cause programs to be installed with an extra prefix or suffix on their names by giving `configure' the option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. Optional Features ================= Some packages pay attention to `--enable-FEATURE' options to `configure', where FEATURE indicates an optional part of the package. They may also pay attention to `--with-PACKAGE' options, where PACKAGE is something like `gnu-as' or `x' (for the X Window System). The `README' should mention any `--enable-' and `--with-' options that the package recognizes. For packages that use the X Window System, `configure' can usually find the X include and library files automatically, but if it doesn't, you can use the `configure' options `--x-includes=DIR' and `--x-libraries=DIR' to specify their locations. Specifying the System Type ========================== There may be some features `configure' cannot figure out automatically, but needs to determine by the type of machine the package will run on. Usually, assuming the package is built to be run on the _same_ architectures, `configure' can figure that out, but if it prints a message saying it cannot guess the machine type, give it the `--build=TYPE' option. TYPE can either be a short name for the system type, such as `sun4', or a canonical name which has the form: CPU-COMPANY-SYSTEM where SYSTEM can have one of these forms: OS KERNEL-OS See the file `config.sub' for the possible values of each field. If `config.sub' isn't included in this package, then this package doesn't need to know the machine type. If you are _building_ compiler tools for cross-compiling, you should use the option `--target=TYPE' to select the type of system they will produce code for. If you want to _use_ a cross compiler, that generates code for a platform different from the build platform, you should specify the "host" platform (i.e., that on which the generated programs will eventually be run) with `--host=TYPE'. Sharing Defaults ================ If you want to set default values for `configure' scripts to share, you can create a site shell script called `config.site' that gives default values for variables like `CC', `cache_file', and `prefix'. `configure' looks for `PREFIX/share/config.site' if it exists, then `PREFIX/etc/config.site' if it exists. Or, you can set the `CONFIG_SITE' environment variable to the location of the site script. A warning: not all `configure' scripts look for a site script. Defining Variables ================== Variables not defined in a site shell script can be set in the environment passed to `configure'. However, some packages may run configure again during the build, and the customized values of these variables may be lost. In order to avoid this problem, you should set them in the `configure' command line, using `VAR=value'. For example: ./configure CC=/usr/local2/bin/gcc causes the specified `gcc' to be used as the C compiler (unless it is overridden in the site shell script). Unfortunately, this technique does not work for `CONFIG_SHELL' due to an Autoconf bug. Until the bug is fixed you can use this workaround: CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash `configure' Invocation ====================== `configure' recognizes the following options to control how it operates. `--help' `-h' Print a summary of the options to `configure', and exit. `--version' `-V' Print the version of Autoconf used to generate the `configure' script, and exit. `--cache-file=FILE' Enable the cache: use and save the results of the tests in FILE, traditionally `config.cache'. FILE defaults to `/dev/null' to disable caching. `--config-cache' `-C' Alias for `--cache-file=config.cache'. `--quiet' `--silent' `-q' Do not print messages saying which checks are being made. To suppress all normal output, redirect it to `/dev/null' (any error messages will still be shown). `--srcdir=DIR' Look for the package's source code in directory DIR. Usually `configure' can determine that directory automatically. `configure' also accepts some other, not widely useful, options. Run `configure --help' for more details. libphone-utils-0.1+git20110523/LICENSE000066400000000000000000000167251156646267600167500ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. 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 that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU 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 as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. libphone-utils-0.1+git20110523/Makefile.am000066400000000000000000000004761156646267600177730ustar00rootroot00000000000000SUBDIRS = src data pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libphone-utils.pc ACLOCAL_AMFLAGS = -I m4 MAINTAINERCLEANFILES = \ Makefile.in Makefile aclocal.m4 config.guess \ config.h.in config.sub configure install-sh \ ltconfig ltmain.sh missing mkinstalldirs \ stamp-h.in acconfig.h stamp-h depcomp libphone-utils-0.1+git20110523/NEWS000066400000000000000000000000001156646267600164150ustar00rootroot00000000000000libphone-utils-0.1+git20110523/README000066400000000000000000000000001156646267600165760ustar00rootroot00000000000000libphone-utils-0.1+git20110523/TODO000066400000000000000000000000751156646267600164220ustar00rootroot00000000000000* Make API more solid. * Add filler_chars and more to config libphone-utils-0.1+git20110523/autogen.sh000077500000000000000000000002001156646267600177210ustar00rootroot00000000000000#! /bin/sh autoreconf -v --install || exit 1 glib-gettextize --force --copy || exit 1 ./configure --enable-maintainer-mode "$@" libphone-utils-0.1+git20110523/configure.ac000066400000000000000000000006241156646267600202200ustar00rootroot00000000000000AC_PREREQ(2.53) AC_INIT(libphone-utils, 0.1, http://www.shr-project.org/) AM_INIT_AUTOMAKE() AM_CONFIG_HEADER(config.h) AM_MAINTAINER_MODE AC_GNU_SOURCE AC_ISC_POSIX AC_PROG_CC AC_STDC_HEADERS AC_PROG_LIBTOOL PKG_CHECK_MODULES(GLIB, glib-2.0) EXPAND(SYSCONFDIR, $sysconfdir) AC_OUTPUT([ Makefile data/Makefile src/Makefile src/lib/Makefile src/bin/Makefile src/lib/phone-utils.h libphone-utils.pc ]) libphone-utils-0.1+git20110523/data/000077500000000000000000000000001156646267600166415ustar00rootroot00000000000000libphone-utils-0.1+git20110523/data/Makefile.am000066400000000000000000000001261156646267600206740ustar00rootroot00000000000000MAINTAINERCLEANFILES = Makefile.in dist_sysconf_DATA = phone-utils.conf phoneprefix libphone-utils-0.1+git20110523/data/phone-utils.conf000066400000000000000000000001171156646267600217560ustar00rootroot00000000000000 [local] international_prefix=00 national_prefix=0 country_code=49 area_code=0 libphone-utils-0.1+git20110523/data/phoneprefix000066400000000000000000000154541156646267600211240ustar00rootroot00000000000000#Format: Country_Name = Country_Code, International_Prefix, National_Prefix Afghanistan = 93, 00, 0 Albania = 355, 00, 0 Algeria = 213, 00, 7 American_Samoa = 1684, 011, 1 Andorra = 376, 00, Angola = 244, 00, 0 Anguilla = 1264, 011, 1 Antarctica = 672, , Antigua = 1268, 011, 1 Argentina = 54, 00, 0 Armenia = 374, 00, 8 Aruba = 297, 00, Ascension = 247, 00, Australia = 61, 0011|0015|0018|0019, 0 Australian_External_Territories = 672, 00, 0 Austria = 43, 00, 0 Azerbaijan = 994, 00, 8 Bahamas = 1242, 011, 1 Bahrain = 973, 00, Bangladesh = 880, 00, 0 Barbados = 1246, 011, 1 Barbuda = 1268, 011, 1 Belarus = 375, 810, 8 Belgium = 32, 00, 0 Belize = 501, 00, 0 Benin = 229, 00, Bermuda = 1441, 011, 1 Bhutan = 975, 00, Bolivia = 591, 0010|0011|0012|0013, 010|011|012|013 Bosnia = 387, 00, 0 Herzegovina = 387, 00, 0 Botswana = 267, 00, Brazil = 55, 0014|0015|0021|0023|0031, 014|015|021|023|031|0 British_Virgin_Islands = 1284, 011, 1 Brunei_Darussalam = 673, 00, 0 Bulgaria = 359, 00, 0 Burkina_Faso = 226, 00, Burundi = 257, 00, Cambodia = 855, 001, 0 Cameroon = 237, 00, Canada = 1, 011, 1 Cape_Verde_Islands = 238, 0, Cayman_Islands = 1345, 011, 1 Central_African_Republic = 236, 00, Chad = 235, 15, Chatham_Island_(New_Zealand) = 64, 00, Chile = 56, 00, 0 China = 86, 00, 0 Christmas_Island = 618, 0011, 0 Cocos_Keeling_Islands = 61, 0011, 0 Colombia = 57, 005|007|009, 03|05|07|09 Comoros = 269, 00, Congo = 242, 00, Zaire = 243, 00, Cook_Islands = 682, 00, 00 Costa_Rica = 506, 00, Ivory_Coast = 225 , 00, 0 Croatia = 385, 00, 0 Cuba = 53, 119, 0 Cuba_(Guantanamo_Bay) = 5399, 00, 0 Curacao = 599, 00, Cyprus = 357, 00, Czech_Republic = 420, 00, Denmark = 45, 00, Diego_Garcia = 246, 00, Djibouti = 253, 00, Dominica = 1767, 011, 1 Dominican_Republic = 1809|1829 , 011, 1 East_Timor = 670, 00, Easter_Island = 56, 00, Ecuador = 593 , 00, 0 Egypt = 20, 00, 0 El_Salvador = 503, 00|144, Ellipso(Mobile_Satellite_service) = 8812, 8813, 00 EMSAT_(Mobile_Satellite_service) = 88213, , Equatorial_Guinea = 240, 00, Eritrea = 291, 00, 0 Estonia = 372, 00, 0 Ethiopia = 251, 00, 0 Falkland_Islands_(Malvinas) = 500, 00, Faroe_Islands = 298, 00, Fiji_Islands = 679, 00, Finland = 358, 00|990|994|999, 0 France = 33, 00|40|50|70|90, 0 French_Antilles = 596, 00, French_Guiana = 594, 00, French_Polynesia = 689, 00, Gabonese_Republic = 241, 00, Gambia = 220, 00, Georgia = 995, 810, 8 Germany = 49, 00 , 0 Ghana = 233, 00, Gibraltar = 350, 00, Global_Mobile_Satellite_System_(GMSS) = 881|8810|8811|8812|8813|8816|8817|8818|8819, 00, Globalstar(Mobile_Satellite_Service) = 8818|8819, 00, Greece = 30, 00 , Greenland = 299, 00, Grenada = 1473, 011, 1 Guadeloupe = 590, 00, Guam = 1671, 011, 1 Guantanamo_Bay = 5399, 00, 0 Guatemala = 502, 00|130|147, Guinea-Bissau = 245, 00, Guinea = 224, 00, 0 Guyana = 592, 001, 0 Haiti = 509, 00, 0 Honduras = 504, 00, 0 Hong_Kong = 852, 001|0080|009, Hungary = 36, 00, 06 ICO_Global(Mobile_Satellite_Service) = 8810|8811, 00, Iceland = 354 , 00, 0 India = 91, 00 , 0 Indonesia = 62, 001|007|017, 0 Inmarsat = 870, 00, Inmarsat(Atlantic_Ocean-East) = 871, 00, Inmarsat(Atlantic_Ocean-West) = 874, 00, Inmarsat(Indian_Ocean) = 873, 00, Inmarsat(Pacific_Ocean) = 872, 00, International_Freephone_Service = 800, , International_Shared_Cost_Service_(ISCS) = 808, , Iran = 98, 00, 0 Iraq = 964, 00, 0 Ireland = 353, 00|048, 0 Iridium(Mobile_Satellite_service) = 8816|8817, 00, Israel = 972, 00|012|013|014, 0 Italy = 39, 00, Jamaica = 1876, 011, 1 Japan = 81, 001|010|0061|0041, 0 Jordan = 962, 00, 0 Kazakhstan = 7, 810, 8 Kenya = 254, 000|006|007, 0 Kiribati = 686, 00, 0 Korea_(North) = 850, 00, 0 Korea_(South) = 82, 001|002|00700, 0|082 Kuwait = 965, 00, 0 Kyrgyz_Republic = 996, 00, 0 Laos = 856, 00, 0 Latvia = 371, 00, Lebanon = 961, 00, 0 Lesotho = 266, 00, 0 Liberia = 231, 00, 22 Libya = 218, 00, 0 Liechtenstein = 423, 00, Lithuania = 370, 00, 8 Luxembourg = 352, 00, Macao = 853, 00, 0 Macedonia = 389, 00, 0 Madagascar = 261, 00, 0 Malawi = 265, 00, Malaysia = 60, 00, 0 Maldives = 960, 00, 0 Mali_Republic = 223, 00, 0 Malta = 356, 00, 21 Marshall_Islands = 692, 011, 1 Martinique = 596, 00, 0 Mauritania = 222, 00, 0 Mauritius = 230, 020, 0 Mayotte_Island = 269, 00, Mexico = 52, 00, 01 Micronesia = 691, 011, 1 Midway_Island = 1808, 011, 1 Moldova = 373, 00, 0 Monaco = 377, 00, 0 Mongolia = 976, 001, 0 Montenegro = 382, 99, 0 Montserrat = 1664, 011, 1 Morocco = 212, 00, Mozambique = 258, 00, 0 Myanmar = 95, 00, Namibia = 264, 00, 0 Nauru = 674, 00, 0 Nepal = 977, 00, 0 Netherlands = 31, 00, 0 Netherlands_Antilles = 599, 00, 0 Nevis = 1869, 011, 1 New_Caledonia = 687, 00, 0 New_Zealand = 64, 00, 0 Nicaragua = 505, 00, 0 Niger = 227, 00, 0 Nigeria = 234 , 009, 0 Niue = 683, 00, 0 Norfolk_Island = 672, 00, Saipan = 1670, 011, 1 Rota = 1670, 011, 1 Tinian = 1670, 011, 1 Norway = 47, 00, Oman = 968, 00, 0 Pakistan = 92, 00, 0 Palau = 680, 011, Palestinian_Settlements = 970, 00, 0 Panama = 507, 00|088|055|, 0 Papua_New_Guinea = 675, 05, Paraguay = 595, 002, 0 Peru = 51, 00, 0 Philippines = 63, 00, 0 Poland = 48, 00, 0 Portugal = 351, 00|882, Puerto_Rico = 1787|1939, 011, 1 Qatar = 974 , 00, 0 Reunion_Island = 262, 00, 0 Romania = 40, 00|022, 0 Russia = 7, 810, 8 Rwandese_Republic = 250, 00, 0 St._Helena = 290, 00, St._Kitts/Nevis = 1869, 011, 1 St._Lucia = 1758, 011, 1 St._Pierre_&_Miquelon = 508, 00, 0 St._Vincent_&_Grenadines = 1784, 011, 1 Samoa = 685, 0, 0 San_Marino = 378, 00, 0 Sao_Tome_and_Principe = 239, 00, 0 Saudi_Arabia = 966, 00, 0 Senegal = 221, 00, 0 Serbia = 381, 99, 0 Seychelles_Republic = 248, 00, 0 Sierra_Leone = 232, 00, 0 Singapore = 65, 001|002|008|012|013|018|019, Slovak_Republic = 421, 00, 0 Slovenia = 386, 00, 0 Solomon_Islands = 677, 00, Somali_Democratic_Republic = 252, 00, South_Africa = 27, 00, 0 Spain = 34, 00, Sri_Lanka = 94, 00, 0 Sudan = 249, 00, 0 Suriname = 597, 00, Swaziland = 268, 00, Sweden = 46, 00, 0 Switzerland = 41, 00, 0 Syria = 963, 00, 0 Taiwan = 886, 002, Tajikistan = 992, 810, 8 Tanzania = 255, 000|005|006, 0 Thailand = 66, 001|008|009, 0 Thuraya(Mobile_Satellite_service) = 88216, , Timor_Leste = 670, , Togolese_Republic = 228, 00, Tokelau = 690, 00, Tonga_Islands = 676, 00, Trinidad_&_Tobago = 1868, 011, 1 Tunisia = 216, 00, 0 Turkey = 90 , 00, 0 Turkmenistan = 993, 810, 8 Turks_and_Caicos_Islands = 1649, 011, 1 Tuvalu = 688, 00, Uganda = 256, 000|005|007, 0 Ukraine = 380, 810, 8 United_Arab_Emirates = 971, 00, 0 United_Kingdom = 44, 00, 0 United_States_of_America = 1, 011, 1 US_Virgin_Islands = 1340, 011, 1 Universal_Personal_Telecommunications_(UPT) = 878, , Uruguay = 598, 00, 0 Uzbekistan = 998, 810, 8 Vanuatu = 678, 00, Vatican_City = 39, 379, 00 Venezuela = 58, 00, 0 Vietnam = 84, 00, 0 Wake_Island = 808, 00, Wallis_and_Futuna_Islands = 681, 19, Yemen = 967, 00, 0 Zambia = 260 , 00, 0 Zanzibar = 255, 000, 0 Zimbabwe = 263 , 00, 0 libphone-utils-0.1+git20110523/libphone-utils.pc.in000066400000000000000000000004231156646267600216160ustar00rootroot00000000000000prefix=@prefix@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@ Name: libphone-utils Description: a library for aux phone functions Version: @VERSION@ Requires: glib-2.0 gobject-2.0 Libs: -L${libdir} -lphone-utils -lm Cflags: -I${includedir}/phone-utils libphone-utils-0.1+git20110523/libphone-utils_git.bb000066400000000000000000000004731156646267600220420ustar00rootroot00000000000000DESCRIPTION = "phone-utils library" SECTION = "libs" PV = "0.0.2+gitr${SRCPV}" PR = "r2" DEPENDS="glib-2.0" inherit pkgconfig autotools autotools_stage CONFFILES_${PN} = "${sysconfdir}/phone-utils.conf" SRC_URI = "git://git.shr-project.org/repo/libphone-utils.git;protocol=http;branch=master" S="${WORKDIR}/git" libphone-utils-0.1+git20110523/m4/000077500000000000000000000000001156646267600162505ustar00rootroot00000000000000libphone-utils-0.1+git20110523/m4/expand.m4000066400000000000000000000014121156646267600177670ustar00rootroot00000000000000AC_DEFUN([EXPAND], [ EXP_VAR=[$1] FROM_VAR=[$2] dnl first expand prefix and exec_prefix if necessary prefix_save=$prefix exec_prefix_save=$exec_prefix # normally, this is done automatically first when running AC_OUTPUT, but we need them expanded now test "x$prefix" = xNONE && prefix=$ac_default_prefix # Let make expand exec_prefix. test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' full_var="$FROM_VAR" dnl loop until it doesn"t change anymore while true; do new_full_var="`eval echo $full_var`" if test "x$new_full_var" = "x$full_var"; then break; fi full_var=$new_full_var done dnl clean up full_var=$new_full_var AC_SUBST([$1], "$full_var") dnl restore prefix and exec_prefix prefix=$prefix_save exec_prefix=$exec_prefix_save ]) libphone-utils-0.1+git20110523/src/000077500000000000000000000000001156646267600165175ustar00rootroot00000000000000libphone-utils-0.1+git20110523/src/Makefile.am000066400000000000000000000003671156646267600205610ustar00rootroot00000000000000SUBDIRS = lib bin ACLOCAL_AMFLAGS = -I m4 MAINTAINERCLEANFILES = \ Makefile.in Makefile aclocal.m4 config.guess \ config.h.in config.sub configure install-sh \ ltconfig ltmain.sh missing mkinstalldirs \ stamp-h.in acconfig.h stamp-h depcomp libphone-utils-0.1+git20110523/src/bin/000077500000000000000000000000001156646267600172675ustar00rootroot00000000000000libphone-utils-0.1+git20110523/src/bin/Makefile.am000066400000000000000000000006161156646267600213260ustar00rootroot00000000000000MAINTAINERCLEANFILES = Makefile.in localedir = $(datadir)/locale AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -DPKGDATADIR=\"$(pkgdatadir)\" \ -I$(top_srcdir)/src/lib @GLIB_CFLAGS@ -lm AM_CFLAGS = -Wall -Wextra -Werror bin_PROGRAMS = phoneutils_test phoneutils_test_SOURCES = phoneutils_test.c phoneutils_test_LDADD = $(top_builddir)/src/lib/libphone-utils.la phoneutils_test_LDFLAGS = libphone-utils-0.1+git20110523/src/bin/phoneutils_test.c000066400000000000000000000017251156646267600226710ustar00rootroot00000000000000#include #include #include #include int main(int argc, char *argv[]) { char *normalized, *number; if (argc != 2) { fprintf(stderr, "Wrong syntax! Correct syntax is: phoneutils_test \n"); return 1; } phone_utils_init(); number = strdup(argv[1]); if (!number) { perror("strdup number"); exit(2); } normalized = phone_utils_normalize_number(number); if (normalized) { printf("Normalized number: %s\n", normalized); free(normalized); } phone_utils_remove_filler_chars(number); printf("Filtered number: %s\n", number); free(number); number = argv[1]; if (phone_utils_call_is_valid_number(number)) { printf("Number is valid for calls.\n"); } else { printf("Number is not valid for calls.\n"); } if (phone_utils_sms_is_valid_number(number)) { printf("Number is valid for SMS.\n"); } else { printf("Number is not valid for SMS.\n"); } phone_utils_deinit(); return 0; } libphone-utils-0.1+git20110523/src/lib/000077500000000000000000000000001156646267600172655ustar00rootroot00000000000000libphone-utils-0.1+git20110523/src/lib/Makefile.am000066400000000000000000000010611156646267600213170ustar00rootroot00000000000000MAINTAINERCLEANFILES = Makefile.in localedir = $(datadir)/locale AM_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" -DPKGDATADIR=\"$(pkgdatadir)\" AM_CFLAGS = -Wall -Wextra -Werror @GLIB_CFLAGS@ -lm lib_LTLIBRARIES = libphone-utils.la libphone_utils_la_SOURCES = phone-utils.c phone-utils.h \ str-utils.c str-utils.h \ phone-utils-gsm.c phone-utils-gsm.h libphone_utils_HEADERS = phone-utils.h phone-utils-gsm.h libphone_utilsdir = $(includedir)/phone-utils libphone_utils_la_LDFLAGS = $(all_libraries) -ldl libphone_utils_la_LIBADD = @GLIB_LIBS@ libphone-utils-0.1+git20110523/src/lib/phone-utils-gsm.c000066400000000000000000000227321156646267600224720ustar00rootroot00000000000000/* * Copyright (C) 2009 * Authors (alphabetical) : * Tom Hacohen (tom@stosb.com) * * This program 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; version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ #include #include #include #include "phone-utils-gsm.h" #include "str-utils.h" /* a mapping of unicode value to size in bytes in the gsm charset */ static int gsm_char_size[][2] = { {0x0040, 1}, /* # COMMERCIAL AT */ {0x00A3, 1}, /* # POUND SIGN */ {0x0024, 1}, /* # DOLLAR SIGN */ {0x00A5, 1}, /* # YEN SIGN */ {0x00E8, 1}, /* # LATIN SMALL LETTER E WITH GRAVE */ {0x00E9, 1}, /* # LATIN SMALL LETTER E WITH ACUTE */ {0x00F9, 1}, /* # LATIN SMALL LETTER U WITH GRAVE */ {0x00EC, 1}, /* # LATIN SMALL LETTER I WITH GRAVE */ {0x00F2, 1}, /* # LATIN SMALL LETTER O WITH GRAVE */ {0x00E7, 1}, /* # LATIN SMALL LETTER C WITH CEDILLA */ {0x000A, 1}, /* # LINE FEED */ {0x00D8, 1}, /* # LATIN CAPITAL LETTER O WITH STROKE */ {0x00F8, 1}, /* # LATIN SMALL LETTER O WITH STROKE */ {0x000D, 1}, /* # CARRIAGE RETURN */ {0x00C5, 1}, /* # LATIN CAPITAL LETTER A WITH RING ABOVE */ {0x00E5, 1}, /* # LATIN SMALL LETTER A WITH RING ABOVE */ {0x0394, 1}, /* # GREEK CAPITAL LETTER DELTA */ {0x005F, 1}, /* # LOW LINE */ {0x03A6, 1}, /* # GREEK CAPITAL LETTER PHI */ {0x0393, 1}, /* # GREEK CAPITAL LETTER GAMMA */ {0x039B, 1}, /* # GREEK CAPITAL LETTER LAMDA */ {0x03A9, 1}, /* # GREEK CAPITAL LETTER OMEGA */ {0x03A0, 1}, /* # GREEK CAPITAL LETTER PI */ {0x03A8, 1}, /* # GREEK CAPITAL LETTER PSI */ {0x03A3, 1}, /* # GREEK CAPITAL LETTER SIGMA */ {0x0398, 1}, /* # GREEK CAPITAL LETTER THETA */ {0x039E, 1}, /* # GREEK CAPITAL LETTER XI */ {0x00A0, 1}, /* # ESCAPE TO EXTENSION TABLE (or displayed as NBSP, see note above) */ {0x000C, 2}, /* # FORM FEED */ {0x005E, 2}, /* # CIRCUMFLEX ACCENT */ {0x007B, 2}, /* # LEFT CURLY BRACKET */ {0x007D, 2}, /* # RIGHT CURLY BRACKET */ {0x005C, 2}, /* # REVERSE SOLIDUS */ {0x005B, 2}, /* # LEFT SQUARE BRACKET */ {0x007E, 2}, /* # TILDE */ {0x005D, 2}, /* # RIGHT SQUARE BRACKET */ {0x007C, 2}, /* # VERTICAL LINE */ {0x20AC, 2}, /* # EURO SIGN */ {0x00C6, 1}, /* # LATIN CAPITAL LETTER AE */ {0x00E6, 1}, /* # LATIN SMALL LETTER AE */ {0x00DF, 1}, /* # LATIN SMALL LETTER SHARP S (German) */ {0x00C9, 1}, /* # LATIN CAPITAL LETTER E WITH ACUTE */ {0x0020, 1}, /* # SPACE */ {0x0021, 1}, /* # EXCLAMATION MARK */ {0x0022, 1}, /* # QUOTATION MARK */ {0x0023, 1}, /* # NUMBER SIGN */ {0x00A4, 1}, /* # CURRENCY SIGN */ {0x0025, 1}, /* # PERCENT SIGN */ {0x0026, 1}, /* # AMPERSAND */ {0x0027, 1}, /* # APOSTROPHE */ {0x0028, 1}, /* # LEFT PARENTHESIS */ {0x0029, 1}, /* # RIGHT PARENTHESIS */ {0x002A, 1}, /* # ASTERISK */ {0x002B, 1}, /* # PLUS SIGN */ {0x002C, 1}, /* # COMMA */ {0x002D, 1}, /* # HYPHEN-MINUS */ {0x002E, 1}, /* # FULL STOP */ {0x002F, 1}, /* # SOLIDUS */ {0x0030, 1}, /* # DIGIT ZERO */ {0x0031, 1}, /* # DIGIT ONE */ {0x0032, 1}, /* # DIGIT TWO */ {0x0033, 1}, /* # DIGIT THREE */ {0x0034, 1}, /* # DIGIT FOUR */ {0x0035, 1}, /* # DIGIT FIVE */ {0x0036, 1}, /* # DIGIT SIX */ {0x0037, 1}, /* # DIGIT SEVEN */ {0x0038, 1}, /* # DIGIT EIGHT */ {0x0039, 1}, /* # DIGIT NINE */ {0x003A, 1}, /* # COLON */ {0x003B, 1}, /* # SEMICOLON */ {0x003C, 1}, /* # LESS-THAN SIGN */ {0x003D, 1}, /* # EQUALS SIGN */ {0x003E, 1}, /* # GREATER-THAN SIGN */ {0x003F, 1}, /* # QUESTION MARK */ {0x00A1, 1}, /* # INVERTED EXCLAMATION MARK */ {0x0041, 1}, /* # LATIN CAPITAL LETTER A */ {0x0042, 1}, /* # LATIN CAPITAL LETTER B */ {0x0043, 1}, /* # LATIN CAPITAL LETTER C */ {0x0044, 1}, /* # LATIN CAPITAL LETTER D */ {0x0045, 1}, /* # LATIN CAPITAL LETTER E */ {0x0046, 1}, /* # LATIN CAPITAL LETTER F */ {0x0047, 1}, /* # LATIN CAPITAL LETTER G */ {0x0048, 1}, /* # LATIN CAPITAL LETTER H */ {0x0049, 1}, /* # LATIN CAPITAL LETTER I */ {0x004A, 1}, /* # LATIN CAPITAL LETTER J */ {0x004B, 1}, /* # LATIN CAPITAL LETTER K */ {0x004C, 1}, /* # LATIN CAPITAL LETTER L */ {0x004D, 1}, /* # LATIN CAPITAL LETTER M */ {0x004E, 1}, /* # LATIN CAPITAL LETTER N */ {0x004F, 1}, /* # LATIN CAPITAL LETTER O */ {0x0050, 1}, /* # LATIN CAPITAL LETTER P */ {0x0051, 1}, /* # LATIN CAPITAL LETTER Q */ {0x0052, 1}, /* # LATIN CAPITAL LETTER R */ {0x0053, 1}, /* # LATIN CAPITAL LETTER S */ {0x0054, 1}, /* # LATIN CAPITAL LETTER T */ {0x0055, 1}, /* # LATIN CAPITAL LETTER U */ {0x0056, 1}, /* # LATIN CAPITAL LETTER V */ {0x0057, 1}, /* # LATIN CAPITAL LETTER W */ {0x0058, 1}, /* # LATIN CAPITAL LETTER X */ {0x0059, 1}, /* # LATIN CAPITAL LETTER Y */ {0x005A, 1}, /* # LATIN CAPITAL LETTER Z */ {0x00C4, 1}, /* # LATIN CAPITAL LETTER A WITH DIAERESIS */ {0x00D6, 1}, /* # LATIN CAPITAL LETTER O WITH DIAERESIS */ {0x00D1, 1}, /* # LATIN CAPITAL LETTER N WITH TILDE */ {0x00DC, 1}, /* # LATIN CAPITAL LETTER U WITH DIAERESIS */ {0x00A7, 1}, /* # SECTION SIGN */ {0x00BF, 1}, /* # INVERTED QUESTION MARK */ {0x0061, 1}, /* # LATIN SMALL LETTER A */ {0x0062, 1}, /* # LATIN SMALL LETTER B */ {0x0063, 1}, /* # LATIN SMALL LETTER C */ {0x0064, 1}, /* # LATIN SMALL LETTER D */ {0x0065, 1}, /* # LATIN SMALL LETTER E */ {0x0066, 1}, /* # LATIN SMALL LETTER F */ {0x0067, 1}, /* # LATIN SMALL LETTER G */ {0x0068, 1}, /* # LATIN SMALL LETTER H */ {0x0069, 1}, /* # LATIN SMALL LETTER I */ {0x006A, 1}, /* # LATIN SMALL LETTER J */ {0x006B, 1}, /* # LATIN SMALL LETTER K */ {0x006C, 1}, /* # LATIN SMALL LETTER L */ {0x006D, 1}, /* # LATIN SMALL LETTER M */ {0x006E, 1}, /* # LATIN SMALL LETTER N */ {0x006F, 1}, /* # LATIN SMALL LETTER O */ {0x0070, 1}, /* # LATIN SMALL LETTER P */ {0x0071, 1}, /* # LATIN SMALL LETTER Q */ {0x0072, 1}, /* # LATIN SMALL LETTER R */ {0x0073, 1}, /* # LATIN SMALL LETTER S */ {0x0074, 1}, /* # LATIN SMALL LETTER T */ {0x0075, 1}, /* # LATIN SMALL LETTER U */ {0x0076, 1}, /* # LATIN SMALL LETTER V */ {0x0077, 1}, /* # LATIN SMALL LETTER W */ {0x0078, 1}, /* # LATIN SMALL LETTER X */ {0x0079, 1}, /* # LATIN SMALL LETTER Y */ {0x007A, 1}, /* # LATIN SMALL LETTER Z */ {0x00E4, 1}, /* # LATIN SMALL LETTER A WITH DIAERESIS */ {0x00F6, 1}, /* # LATIN SMALL LETTER O WITH DIAERESIS */ {0x00F1, 1}, /* # LATIN SMALL LETTER N WITH TILDE */ {0x00FC, 1}, /* # LATIN SMALL LETTER U WITH DIAERESIS */ {0x00E0, 1}, /* # LATIN SMALL LETTER A WITH GRAVE */ {0 , 0} /* END */ }; int phone_utils_gsm_get_char_size(int chr) { int j = 0; while (gsm_char_size[j][1] && gsm_char_size[j][0] != chr) { j++; } if (gsm_char_size[j][1]) { /*this means it's in the table, count it in size. */ return gsm_char_size[j][1]; } return 0; } /* returns true if the function will have to be encoded in ucs */ int phone_utils_gsm_is_ucs(const char *string) { int i; int chr; i=0; chr = utf8_get_next(string, &i); for ( ; chr ; chr = utf8_get_next(string, &i)) { if (!phone_utils_gsm_get_char_size(chr)) { return 1; } } return 0; } int phone_utils_gsm_sms_strlen(const char *string) { int i; int len, size; int ucs; int chr; i=0; chr = utf8_get_next(string, &i); for (len = size = ucs = 0 ; chr ; chr = utf8_get_next(string, &i), len++) { int char_size; char_size = phone_utils_gsm_get_char_size(chr); if (char_size) { size += char_size; } else { ucs = 1; } } return (ucs) ? len : size; } char ** phone_utils_gsm_sms_split_message(const char *message, int len, int ucs) { char **messages; int limit = 1; /* just a safe value so it won't crash */ int number_of_messages; int i, j; int start, end; if (ucs) { limit = PHONE_UTILS_GSM_SMS_UCS_LIMIT; /* ucs-2 number of chars limit */ if (len > limit) { limit = PHONE_UTILS_GSM_SMS_UCS_SPLIT_LIMIT; } } else { limit = PHONE_UTILS_GSM_SMS_TEXT_LIMIT; /* regular number of chars limit */ if (len > limit) { limit = PHONE_UTILS_GSM_SMS_TEXT_SPLIT_LIMIT; } } number_of_messages = (int) ceilf((float) len / limit); messages = calloc(number_of_messages + 1, sizeof(char *)); if (!messages) { goto end; } /* copy the messages */ start = end = 0; for (i = 0 ; i < number_of_messages ; i++) { /* we want to go "limit" chars */ for (j = 0 ; j < limit ; j++) { utf8_get_next(message, &end); } messages[i] = malloc((end - start) + 1); /* the actual utf8 len + 1 for null */ if (!messages[i]) { goto clean_messages; } /* copy that part of the string */ strncpy(messages[i], &message[start], end - start); messages[i][end - start] = '\0'; start = end; /* advance start */ } messages[i] = NULL; /* terminate the list with a null */ i--; /* make i point to the last real message */ /* reduce the side of the last message to the real size needed */ if (len % limit) { messages[i] = realloc(messages[i], strlen(messages[i]) + 1); } end: return messages; /* error handling */ clean_messages: if (messages) { for (i = 0 ; i < number_of_messages ; i++) { if (messages[i]) { free(messages[i]); } } free(messages); messages = NULL; } goto end; } /* assumes number is not null */ int phone_utils_gsm_number_is_ussd(const char *number){ /*FIXME: make sure this algo is correct */ int len = strlen(number); if (len == 0) return 0; if (number[len - 1] == '#' || len <= 2) { return 1; } return 0; } libphone-utils-0.1+git20110523/src/lib/phone-utils-gsm.h000066400000000000000000000045751156646267600225040ustar00rootroot00000000000000/* * Copyright (C) 2009 * Authors (alphabetical) : * Tom Hacohen (tom@stosb.com) * * This program 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; version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ #ifndef _PHONE_UTILS_GSM_H #define _PHONE_UTILS_GSM_H /* sms stuff */ #define PHONE_UTILS_GSM_SMS_TEXT_LIMIT 160 #define PHONE_UTILS_GSM_SMS_TEXT_SPLIT_LIMIT 153 #define PHONE_UTILS_GSM_SMS_UCS_LIMIT 70 #define PHONE_UTILS_GSM_SMS_UCS_SPLIT_LIMIT 67 /* Receives a utf8 encoded string and returns the string len of this string * if it'll be sent via an sms. This function detects whether this string * should be represented in gsm7 or ucs. * If it should be represnetd in gsm7 this function returns the number * of bytes needed in order to represent this string (i.e ] is counted as 2) * If this string should be sent using the ucs2 encoding the number of chars * needed in order to represent this, i.e the equiv of a regular utf8-strlen * * This function assumes srting is a valid utf8 string*/ int phone_utils_gsm_sms_strlen(const char *string); /* Receives a utf8 encoded string and returns true if this string has to * be represented in ucs2 or false if it can be representehd in gsm7 * * This function assumes srting is a valid utf8 string*/ int phone_utils_gsm_is_ucs(const char *string); /* This function recieves a unicode char and returns the number of bytes * this char takes in order to be represented in the gsm 7bit charset * * returns 0 when this char can not be represented using this charset. */ int phone_utils_gsm_get_char_size(int chr); /* takes a message and splits it to buffers that can be used * for sending split messages. pdu is true if should split as ucs. * len is the len of the message (got from phone_utils_gsm_sms_strlen) * the function allocates the array and the strings inside * the array (as every string inside it) is null terminated */ char ** phone_utils_gsm_sms_split_message(const char *message, int len, int ucs); int phone_utils_gsm_number_is_ussd(const char *number); #endif libphone-utils-0.1+git20110523/src/lib/phone-utils.c000066400000000000000000000416401156646267600217050ustar00rootroot00000000000000/* * Copyright (C) 2009 * Authors (alphabetical) : * Tom Hacohen (tom@stosb.com) * * Thanks (alphabetical) : * Joerg "DocScrutinizer" Reisenweber (joerg@openmoko.org / reisenweber@gmx.net) - The number normalization method is mostly based on an algorithm suggested by him. * * * This program 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; version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ #include #include #include #include #include #include "phone-utils.h" #include "str-utils.h" /* the internal prefixes */ struct PrefixField { const char *value; int len; }; struct Prefix { struct PrefixField *fields; char *value; int len; }; static struct Prefix international_prefix = {NULL, NULL, 0}; static struct Prefix national_prefix = {NULL, NULL, 0}; static struct Prefix country_code = {NULL, NULL, 0}; static struct Prefix area_code = {NULL, NULL, 0}; /* all the information needed for processing a number */ static char *trailing_delimiters = "wWpP;,"; #define POSSIBLE_DIGITS "0123456789ABCD" static char *possible_chars = POSSIBLE_DIGITS "+"; static char *filler_chars = " -()."; int phone_utils_init() { international_prefix.fields = NULL; international_prefix.value = NULL; national_prefix.fields = NULL; national_prefix.value = NULL; country_code.fields = NULL; country_code.value = NULL; area_code.fields = NULL; area_code.value = NULL; /* trailing_delimiters = NULL; possible_chars = NULL; filler_chars = NULL; */ return phone_utils_init_from_file(PHONE_UTILS_CONFIG); } static void _phone_utils_free_prefix(struct Prefix *prefix) { if (prefix->value) { free(prefix->value); } } void phone_utils_deinit() { _phone_utils_free_prefix(&international_prefix); _phone_utils_free_prefix(&national_prefix); _phone_utils_free_prefix(&country_code); _phone_utils_free_prefix(&area_code); } int phone_utils_set_codes(char *_international_prefix, char *_national_prefix, char *_country_code, char *_area_code) { int ret = 0; if (_international_prefix) ret = ret || phone_utils_set_user_international_prefix(_international_prefix); if (_national_prefix) ret = ret || phone_utils_set_user_national_prefix(_national_prefix); if (_country_code) ret = ret || phone_utils_set_user_country_code(_country_code); if (_area_code) ret = ret || phone_utils_set_user_area_code (_area_code); return ret; } /*void phone_utils_set_delimiters(char *trailing_delimiters, char *possible_chars, char *filler_chars) */ int phone_utils_init_from_file(const char *filename) { GKeyFile *keyfile; GKeyFileFlags flags; GError *error = NULL; char *tmp; int ret = 0; keyfile = g_key_file_new (); if (!keyfile) { g_debug("Can't allocate memory! %s:%d\n" "Initializing key from file failed\n", __FILE__, __LINE__); return 1; } flags = G_KEY_FILE_KEEP_TRANSLATIONS; if (!g_key_file_load_from_file (keyfile, filename, flags, &error)) { g_key_file_free(keyfile); g_warning ("%s", error->message); g_error_free(error); return 1; } /* Init all the fields */ tmp = g_key_file_get_string(keyfile,PHONE_UTILS_CONFIG_CODES_GROUP, "international_prefix",NULL); ret = ret || phone_utils_set_user_international_prefix(tmp); g_free(tmp); tmp = g_key_file_get_string(keyfile,PHONE_UTILS_CONFIG_CODES_GROUP, "national_prefix",NULL); ret = ret || phone_utils_set_user_national_prefix(tmp); g_free(tmp); tmp = g_key_file_get_string(keyfile,PHONE_UTILS_CONFIG_CODES_GROUP, "country_code",NULL); ret = ret || phone_utils_set_user_country_code(tmp); g_free(tmp); tmp = g_key_file_get_string(keyfile,PHONE_UTILS_CONFIG_CODES_GROUP, "area_code",NULL); ret = ret || phone_utils_set_user_area_code(tmp); g_free(tmp); g_key_file_free(keyfile); return ret; } int phone_utils_save_config() { return phone_utils_save_config_to_file(PHONE_UTILS_CONFIG); } int phone_utils_save_config_to_file(const char *filename) { GKeyFile *keyfile; GError *error = NULL; FILE *out; char *data; int ret = 0; keyfile = g_key_file_new (); if (!keyfile) { g_debug("Can't allocate memory! %s:%d\n" "Initializing key from file failed\n", __FILE__, __LINE__); ret = 1; goto end; } /* set all the values */ { char *tmp; tmp = phone_utils_get_user_international_prefixes(); g_key_file_set_value(keyfile, PHONE_UTILS_CONFIG_CODES_GROUP, "international_prefix", tmp); tmp = phone_utils_get_user_national_prefixes(); g_key_file_set_value(keyfile, PHONE_UTILS_CONFIG_CODES_GROUP, "national_prefix", tmp); tmp = phone_utils_get_user_country_codes(); g_key_file_set_value(keyfile, PHONE_UTILS_CONFIG_CODES_GROUP, "country_code", tmp); tmp = phone_utils_get_user_area_codes(); g_key_file_set_value(keyfile, PHONE_UTILS_CONFIG_CODES_GROUP, "area_code", tmp); } if (!(data = g_key_file_to_data (keyfile, NULL, &error))) { g_warning ("%s", error->message); g_error_free(error); ret = 1; goto free_key_file; } out = fopen(filename, "w"); if (!out) { g_debug("%s:%d Can't open file %s! (%s)\n", __FILE__, __LINE__, filename, strerror(errno)); ret = 1; goto free_data; } fputs(data, out); if (ferror(out)) { g_debug("%s:%d Can't write to file %s! (%s)\n", __FILE__, __LINE__, filename, strerror(errno)); } /*clean up and exit */ fclose(out); free_data: g_free(data); free_key_file: g_key_file_free(keyfile); end: return ret; } int phone_utils_is_initialized() { return international_prefix.value && national_prefix.value && country_code.value && area_code.value && trailing_delimiters && possible_chars && filler_chars; } static const char * _phone_utils_get_user_prefix(const struct Prefix *field) { if (!field || !field->fields) return NULL; return (field[0].value) ? field[0].value : NULL; } static char * _phone_utils_get_strdup_user_prefix(const struct Prefix *field) { const char *ret; ret = _phone_utils_get_user_prefix(field); return (ret) ? strdup(ret) : NULL; } char * phone_utils_get_strdup_user_international_prefix() { return _phone_utils_get_strdup_user_prefix(&international_prefix); } char * phone_utils_get_strdup_user_national_prefix() { return _phone_utils_get_strdup_user_prefix(&national_prefix); } char * phone_utils_get_strdup_user_country_code() { return _phone_utils_get_strdup_user_prefix(&country_code); } char * phone_utils_get_strdup_user_area_code() { return _phone_utils_get_strdup_user_prefix(&area_code); } const char * phone_utils_get_user_international_prefix() { return _phone_utils_get_user_prefix(&international_prefix); } const char * phone_utils_get_user_national_prefix() { return _phone_utils_get_user_prefix(&national_prefix); } const char * phone_utils_get_user_country_code() { return _phone_utils_get_user_prefix(&country_code); } const char * phone_utils_get_user_area_code() { return _phone_utils_get_user_prefix(&area_code); } static char * _phone_utils_get_user_prefixes(struct Prefix *prefix) { int i; char *ret = NULL; char *src; char *dst; if (!prefix) return NULL; ret = malloc(prefix->len + 1); if (!ret) { g_debug("Can't allocate memory! %s:%d\n" "Getting user prefixes failed\n", __FILE__, __LINE__); return NULL; } dst = ret; src = prefix->value; for (i = 0 ; i < prefix->len ; i++) { if (*src == '\0') { *dst = PHONE_UTILS_FIELD_DELIMITER; } else { *dst = *src; } src++; dst++; } *dst = '\0'; return ret; } char * phone_utils_get_user_international_prefixes() { return _phone_utils_get_user_prefixes(&international_prefix); } char * phone_utils_get_user_national_prefixes() { return _phone_utils_get_user_prefixes(&national_prefix); } char * phone_utils_get_user_country_codes() { return _phone_utils_get_user_prefixes(&country_code); } char * phone_utils_get_user_area_codes() { return _phone_utils_get_user_prefixes(&area_code); } static int _phone_utils_set_user_prefix(struct Prefix *prefix, const char *value) { /* Set both len and actual value */ char *pos, *prev; int i; int num_of_fields; if (!value) value = ""; _phone_utils_free_prefix(prefix); prefix->value = strdup(value); if (!prefix->value) { g_debug("Can't allocate memory! %s:%d\n" "Rolling back the setting\n", __FILE__, __LINE__); return 1; } prefix->len = strlen(prefix->value); num_of_fields = 1; /* at least one, as we have the basic one */ for (pos = prefix->value ; *pos ; pos++) { if (*pos == PHONE_UTILS_FIELD_DELIMITER) { num_of_fields++; } } /* if we had more than one fields, we should add one more because the number * of fields is the number of delimiters +1 */ num_of_fields += (num_of_fields > 1) ? 1 : 0; /* Allocate fields and null terminate the array */ prefix->fields = malloc(sizeof(struct PrefixField) * (num_of_fields + 1)); if (!prefix->fields) { g_debug("Can't allocate memory! %s:%d\n" "Rolling back the setting\n", __FILE__, __LINE__); free(prefix->value); prefix->value = NULL; return 1; } prev = pos = prefix->value; i = 0; while (1) { if (*pos == PHONE_UTILS_FIELD_DELIMITER || !*pos) { prefix->fields[i].value = prev; prefix->fields[i].len = pos - prev; i++; if (!*pos) { break; } *pos = '\0'; prev = ++pos; } else { pos++; } } /* after we finish, null terminate the array */ prefix->fields[i].value = NULL; return 0; } int phone_utils_set_user_international_prefix(const char *value) { return _phone_utils_set_user_prefix(&international_prefix, value); } int phone_utils_set_user_national_prefix(const char *value) { return _phone_utils_set_user_prefix(&national_prefix, value); } int phone_utils_set_user_country_code(const char *value) { return _phone_utils_set_user_prefix(&country_code, value); } int phone_utils_set_user_area_code(const char *value) { return _phone_utils_set_user_prefix(&area_code, value); } static int _phone_utils_get_prefix_of_number(struct Prefix *prefix, const char *number) { struct PrefixField *field; int i; int empty_index = -1; for (i = 0, field = prefix->fields ; field->value ; field++, i++) { if (field->len == 0) { empty_index = i; } else if (!strncmp(field->value, number, field->len)) { return i; } } return empty_index; } /*FIXME: handle failed memory allocations! */ char * phone_utils_normalize_number_using_params(const char *_number, const char *param_country, const char *param_area) { /*FIXME: add support for normalizing completely to what's wanted */ char *number = strdup(_number); char *tmp; int found; char *pos; int len; const char *international, *national; int international_len, national_len; /* Optimize, already got those saved, get them */ international = phone_utils_get_user_international_prefix(); national = phone_utils_get_user_national_prefix(); international_len = strlen(international); national_len = strlen(national); /* on error */ if (!number) { return NULL; } remove_from_chrs(&number, trailing_delimiters, 0); len = filter_string(number, filler_chars); number = realloc(number, len + 1); len = remove_from_chrs_r(&number, possible_chars, 1); /* if empty, i.e some sort of code / ilegal number, return the number */ if (len == 0) { free(number); return strdup(_number); } /* if normalized, replace the CC and AC to the new ones*/ if (number[0] == '+') { /* Strip CC and AC and then replace them. */ pos = number + 1; found = _phone_utils_get_prefix_of_number(&country_code, pos); if (found >= 0) { pos += country_code.fields[found].len; found = _phone_utils_get_prefix_of_number(&area_code, pos); if (found >= 0) { int total_len; int param_country_len = strlen(param_country); int param_area_len = strlen(param_area); pos += area_code.fields[found].len; len -= pos - number; tmp = number; /* malloc: +1 for '+' */ total_len = 1 + param_country_len + param_area_len + len; number = malloc (total_len + 1); number[0] = '+'; strncpy(&number[1], param_country, param_country_len); strncpy(&number[1 + param_country_len], param_area, param_area_len); strncpy(&number[1 + param_country_len + param_area_len], pos, len); number[total_len] = '\0'; free(tmp); } } } /* step 1: normalize 00 to + */ else if (international_len > 0 && !strncmp(number, international, international_len)) { tmp = number; number = strdup(&number[international_len - 1]); *number = '+'; free(tmp); } /* step 2: normalize national prefix to + * if national = "" assume it's a match */ else if (national_len >= 0 && !strncmp(number, national, national_len)) { int total_len; int param_country_len = strlen(param_country); tmp = number; /* malloc: +1 for '+' */ total_len = 1 + param_country_len + len - national_len; number = malloc(total_len + 1); number[0] = '+'; strncpy(&number[1], param_country, param_country_len); strncpy(&number[1 + param_country_len], &tmp[national_len], len - national_len); number[total_len] = '\0'; free(tmp); } /* by default, just try to add + to the start, better than not trying at all. */ else { int total_len; int param_country_len = strlen(param_country); tmp = number; /* malloc: +1 for '+' */ total_len = 1 + param_country_len + len; number = malloc (total_len + 1); number[0] = '+'; strncpy(&number[1], param_country, param_country_len); strncpy(&number[1 + param_country_len], tmp, len); number[total_len] = '\0'; free(tmp); } return number; } char * phone_utils_normalize_number(const char *_number) { const char *country, *area; char *ret; country = phone_utils_get_user_country_code(); area = phone_utils_get_user_area_code(); ret = phone_utils_normalize_number_using_params(_number, country, area); return ret; } /*Returns -1 when smaller, -2 when MATCHES and smaller, 0 when equal and 1 when greater, 2 when greater and extension This conforms to regular strcmp but adds more info*/ static int _extended_strcmp(const char *a, const char * b) { for( ; *a && *b && *a == *b ; a++, b++) ; if (!*a && !*b) { return 0; } /* If one reached end and the other didn't: */ else if (!*a && *b) { return -2; } else if (*a && !*b) { return 2; } else { /* return a regular negative */ return (*a < *b) ? -1 : 1; } } /* both will be normalized using the basic, unless already normalized, returns like strcmp * Used for fast comparing and ordering of numbers (for instance for use with sqlite) */ int phone_utils_numbers_compare(const char * _a, const char * _b) { int ret; char *a = NULL; char *b = NULL; int clean_a = 0; int clean_b = 0; if (*_a != '+') { a = phone_utils_normalize_number(_a); clean_a = 1; } else { /* A bit hackish */ a = (char *) _a; } if (*_b != '+') { b = phone_utils_normalize_number(_b); clean_b = 1; } else { b = (char *) _b; } ret = _extended_strcmp(a, b); /* clean up */ if (clean_a) free(a); if (clean_b) free(b); return ret; } /* _a will be normalized using all the known options _b will be optimized * using only the basic */ int phone_utils_numbers_equal(const char * _a, const char * _b) { int ret = 0; char *a; char *b = phone_utils_normalize_number(_b); char *pos; int cpos, apos; if (!b) return 0; pos = b + 1; /* Get to the first char after the + */ cpos = _phone_utils_get_prefix_of_number(&country_code, pos); if (cpos >= 0) { pos += country_code.fields[cpos].len; } apos = _phone_utils_get_prefix_of_number(&area_code, pos); if (apos >= 0) { pos += area_code.fields[apos].len; } a = phone_utils_normalize_number_using_params( _a, country_code.fields[cpos].value, area_code.fields[apos].value); if (a && b) { if (strcmp(a, b) == 0) { ret = 1; } } else { ret = 0; } /* clean up */ if (a) free(a); if (b) free(b); return ret; } int phone_utils_sms_is_valid_number(const char *number) { if (!number) return 0; /* FIXME: YUCK! I hate hardcoded stuff */ if (*number == '+') number++; while (*number) { if (!strchr(POSSIBLE_DIGITS, *number) && !strchr(filler_chars, *number)) { return 0; } number++; } return 1; } int phone_utils_call_is_valid_number(const char *number) { if (!number) return 0; /* FIXME: YUCK! I hate hardcoded stuff */ if (*number == '+') number++; while (*number) { if (!strchr(POSSIBLE_DIGITS, *number) && !strchr(filler_chars, *number) && !strchr(trailing_delimiters, *number)) { return 0; } number++; } return 1; } int phone_utils_remove_filler_chars(char *number) { return filter_string(number, filler_chars); } libphone-utils-0.1+git20110523/src/lib/phone-utils.h.in000066400000000000000000000132371156646267600223200ustar00rootroot00000000000000/* * Copyright (C) 2009 * Authors (alphabetical) : * Tom Hacohen (tom@stosb.com) * * This program 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; version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ #ifndef _PHONE_UTILS_H #define _PHONE_UTILS_H #include #include #define PHONE_UTILS_CONFIG "@SYSCONFDIR@/phone-utils.conf" #define PHONE_UTILS_CONFIG_CODES_GROUP "local" #define PHONE_UTILS_FIELD_DELIMITER '|' /* Initializes the use of phone-utils, calls phone_utils_init_from_file * with the default config filename (PHONE_UTILS_CONFIG) */ int phone_utils_init(); /* Cleans up the memory allocated by the lib, assumes the lib is already * initialized. */ void phone_utils_deinit(); /* returns true if the lib is already initialized, false otherwise */ int phone_utils_is_initialized(); /* calls all the phone_utils_set_* functions on all the arguments returns * 0 on sucess. */ int phone_utils_set_codes(char *_international_prefix, char *_national_prefix, char *_country_code, char *_area_code); /*void phone_utils_set_delimiters(char *trailing_delimiters, char *possible_chars, char *filler_chars) */ /* initalizes the lib from configuration file denoted by filename * assumes filename is a valid null terminated string */ int phone_utils_init_from_file(const char *filename) ; /* calls phone_utils_save_config_to_file with the default filename (PHONE_UTILS_CONFIG) */ int phone_utils_save_config(); /* saves all the currently active configuration to the file denoted by filename * assumes filename is a valid string */ int phone_utils_save_config_to_file(const char *filename); /* returns a copy allocated by strdup of this parameter */ char * phone_utils_get_strdup_user_international_prefix() ; /* returns a copy allocated by strdup of this parameter */ char * phone_utils_get_strdup_user_national_prefix() ; /* returns a copy allocated by strdup of this parameter */ char * phone_utils_get_strdup_user_country_code(); /* returns a copy allocated by strdup of this parameter */ char * phone_utils_get_strdup_user_area_code() ; /* returns this parameter */ const char * phone_utils_get_user_international_prefix() ; /* returns this parameter */ const char * phone_utils_get_user_national_prefix() ; /* returns this parameter */ const char * phone_utils_get_user_country_code(); /* returns this parameter */ const char * phone_utils_get_user_area_code() ; /* sets this parameters using value returns 0 on sucess */ int phone_utils_set_user_international_prefix(const char *value) ; /* sets this parameters using value returns 0 on sucess */ int phone_utils_set_user_national_prefix(const char *value) ; /* sets this parameters using value returns 0 on sucess */ int phone_utils_set_user_country_code(const char *value); /* sets this parameters using value returns 0 on sucess */ int phone_utils_set_user_area_code(const char *value) ; /* document, TBD */ char *phone_utils_get_user_international_prefixes(); char *phone_utils_get_user_national_prefixes(); char *phone_utils_get_user_country_codes(); char *phone_utils_get_user_area_codes(); /* receives a valid string that holds a number to normalize * and normalizes it according (mostly) this guidelines: * * normalized number = "+" * non-normalized my be: | | * * * so: * Nr1 := Nr s/(.*)/\+$1/ #00 49 911 12345 -> + 49 911 12345 * Nr2 = Nr1 s//\+/ # 0 911 12345 -> + 49 911 12345 * Nr3 = Nr2 s/[^\+](.*)/\+$1/ # 12345 -> + 49 911 12345 * step3 above isn't considered very practical for cellphones * , , , and are user definable config-values * * some examples: * normalized "*31#0049 (0) 30 12300 - 456W*1200*#" becomes +493012300456 * normalized "0049 30 123 00 456" becomes +493012300456 * normalized "030 123 00 456;foo" becomes +493012300456 * normalized "123 00 456" becomes +493012300456 * * returns a malloc allocated string containing the normalized number * returns NULL on error. */ char * phone_utils_normalize_number(const char *_number); /* TBD */ char * phone_utils_normalize_number_using_params(const char *_number, const char *param_country, const char *param_area); /* receives two valid strings containing phone numbers, normalizes them * using phone_utils_normalize_number and returns a strcmp like result */ int phone_utils_numbers_compare(const char * _a, const char * _b); /* receives two valid strings containing phone numbers, normalizes them * using phone_utils_normalize_number and returns true if they are equal * false otherwise */ int phone_utils_numbers_equal(const char * _a, const char * _b); /* receives a valid string containing a phone number and returns true if * it's a valid sms phone number, false otherwise. */ int phone_utils_sms_is_valid_number(const char *number); /* receives a valid string containing a phone number and returns true if * it's a valid call phone number, false otherwise. */ int phone_utils_call_is_valid_number(const char *number); /* receives a valid string containing a phone number. * Tries to remove all the filler_chars for the number. * returns 0 on success error code on failure. */ int phone_utils_remove_filler_chars(char *number); #endif libphone-utils-0.1+git20110523/src/lib/str-utils.c000066400000000000000000000056471156646267600214130ustar00rootroot00000000000000#include #include #include "str-utils.h" int filter_string(char *string, char filters_array[]) { char *result = string; char *end = string; while (*end) { char *pos; /* go through the null terminated char array * stop after went trough it all or found a match */ for (pos=filters_array ; *pos && (*pos != *end) ; pos++); /* if not matched, the char shouldn't be filtered */ if (!*pos) { *result++ = *end; } end++; } *result = '\0'; return result - string; } char * strchrs(char *string, char filters_array[], int negate) { while (*string) { /* check if in the array */ if (!strchr(filters_array, *string) != !negate) break; string++; } return (*string) ? string : NULL; } char * strrchrs(char *string, char filters_array[], int negate) { char *start = string; if (!*string) return NULL; /* find the last non null char */ while (*++string); string--; while (string >= start) { /* check if in the array */ if (!strchr(filters_array, *string) != !negate) break; string--; } return (string >= start) ? string : NULL; } int remove_from_chrs(char **string, char filters_array[], int negate) { char *start = *string; char *pos; int len; pos = strchrs(*string, filters_array, negate); if (!pos) return strlen(*string); *pos = 0; len = pos - start; *string = realloc(*string, len + 1); return len; } int remove_from_chrs_r(char **string, char filters_array[], int negate) { char *pos = strrchrs(*string, filters_array, negate); if (!pos) return strlen(*string); if (!*pos) { *string = strdup(""); return 0; } pos++; pos = strdup(pos); free(*string); *string = pos; return strlen(*string); } /* Many thanks to evas */ int utf8_get_next(const char *buf, int *iindex) { /* Reads UTF8 bytes from @buf, starting at *@index and returns * the decoded code point at iindex offset, and advances iindex * to the next code point after this. * * Returns 0 to indicate there is no next char */ int index = *iindex, len, r; unsigned char d, d2, d3, d4; /* if this char is the null terminator, exit */ if (!buf[index]) return 0; d = buf[index++]; while (buf[index] && ((buf[index] & 0xc0) == 0x80)) index++; len = index - *iindex; if (len == 1) r = d; else if (len == 2) { /* 2 bytes */ d2 = buf[*iindex + 1]; r = d & 0x1f; /* copy lower 5 */ r <<= 6; r |= (d2 & 0x3f); /* copy lower 6 */ } else if (len == 3) { /* 3 bytes */ d2 = buf[*iindex + 1]; d3 = buf[*iindex + 2]; r = d & 0x0f; /* copy lower 4 */ r <<= 6; r |= (d2 & 0x3f); r <<= 6; r |= (d3 & 0x3f); } else { /* 4 bytes */ d2 = buf[*iindex + 1]; d3 = buf[*iindex + 2]; d4 = buf[*iindex + 3]; r = d & 0x0f; /* copy lower 4 */ r <<= 6; r |= (d2 & 0x3f); r <<= 6; r |= (d3 & 0x3f); r <<= 6; r |= (d4 & 0x3f); } *iindex = index; return r; } libphone-utils-0.1+git20110523/src/lib/str-utils.h000066400000000000000000000023131156646267600214030ustar00rootroot00000000000000/* * Copyright (C) 2009 * Authors (alphabetical) : * Tom Hacohen (tom@stosb.com) * * This program 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; version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ #ifndef _STR_UTILS_H #define _STR_UTILS_H /* This function receives a pointer to a string * and a NULL terminated array of chars and updates the string * to not include the chars from the filters_array. * * returns the length of the new string */ int filter_string(char *string, char filters_array[]); char * strchrs(char *string, char filters_array[], int negate); char * strrchrs(char *string, char filters_array[], int negate); int remove_from_chrs(char **string, char filters_array[], int negate); int remove_from_chrs_r(char **string, char filters_array[], int negate); int utf8_get_next(const char *buf, int *iindex); #endif libphone-utils-0.1+git20110523/src/python/000077500000000000000000000000001156646267600200405ustar00rootroot00000000000000libphone-utils-0.1+git20110523/src/python/phoneutils/000077500000000000000000000000001156646267600222325ustar00rootroot00000000000000libphone-utils-0.1+git20110523/src/python/phoneutils/__init__.py000066400000000000000000000000331156646267600243370ustar00rootroot00000000000000from c_phoneutils import * libphone-utils-0.1+git20110523/src/python/phoneutils/c_phoneutils.pyx000066400000000000000000000061461156646267600254770ustar00rootroot00000000000000# Copyright (c) 2009 Sebastian Krzyszkowiak # # This file is part of python-phoneutils, which is part of libphone-utils. # # python-phoneutils 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. # # python-phoneutils 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 libphone-utils. If not, see . # cdef extern from "phone-utils.h": int phone_utils_init() void phone_utils_deinit() int phone_utils_set_codes(char *_international_prefix, char *_national_prefix, char *_country_code, char *_area_code) int phone_utils_init_from_file(char *filename) int phone_utils_save_config() int phone_utils_save_config_to_file(char *filename) int phone_utils_is_initialized() char * phone_utils_get_user_international_prefix() char * phone_utils_get_user_national_prefix() char * phone_utils_get_user_country_code() char * phone_utils_get_user_area_code() int phone_utils_set_user_international_prefix(char *value) int phone_utils_set_user_national_prefix(char *value) int phone_utils_set_user_country_code(char *value) int phone_utils_set_user_area_code(char *value) char * phone_utils_normalize_number(char *_number) int phone_utils_numbers_equal(char * _a, char * _b) int phone_utils_numbers_compare(char * _a, char * _b) def init(): phone_utils_init() def deinit(): phone_utils_deinit() def is_initialized(): if phone_utils_is_initialized(): return True else: return False def set_codes(ip, np, cc, ac): phone_utils_set_codes(ip, np, cc, ac) def init_from_file(filename): phone_utils_init_from_file(filename) def save_config(): phone_utils_save_config() def save_config_to_file(filename): phone_utils_save_config_to_file(filename) def get_user_international_prefix(): return phone_utils_get_user_international_prefix() def get_user_national_prefix(): return phone_utils_get_user_national_prefix() def get_user_country_code(): return phone_utils_get_user_country_code() def get_user_area_code(): return phone_utils_get_user_area_code() def set_user_international_prefix(value): phone_utils_set_user_international_prefix(value) def set_uset_national_prefix(value): phone_utils_set_user_national_prefix(value) def set_user_country_code(value): phone_utils_set_user_country_code(value) def set_user_area_code(value): phone_utils_set_user_area_code(value) def normalize_number(number): return phone_utils_normalize_number(number) def numbers_equal(a, b): if phone_utils_numbers_equal(a, b): return True else: return False def numbers_compare(a, b): return phone_utils_numbers_compare(a, b) libphone-utils-0.1+git20110523/src/python/setup.py000066400000000000000000000035341156646267600215570ustar00rootroot00000000000000import sys import os if not os.path.exists("phoneutils/c_phoneutils.c"): try: import Cython except ImportError: raise SystemExit("You need Cython -- http://cython.org/") try: import Pyrex except ImportError: raise SystemExit( "You need Pyrex -- " "http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/") from distutils.core import setup from setuptools import find_packages from distutils.extension import Extension from Cython.Distutils import build_ext import commands def pkgconfig(*packages, **kw): flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries'} pkgs = ' '.join(packages) cmdline = 'pkg-config --libs --cflags %s' % pkgs status, output = commands.getstatusoutput(cmdline) if status != 0: raise ValueError("could not find pkg-config module: %s" % pkgs) for token in output.split(): if flag_map.get(token[:2]): kw.setdefault(flag_map.get(token[:2]), []).append(token[2:]) elif token.startswith("-Wl,"): kw.setdefault("extra_link_args", []).append(token) else: kw.setdefault("extra_compile_args", []).append(token) return kw phoneutils_mod = Extension('phoneutils.c_phoneutils', sources=['phoneutils/c_phoneutils.pyx'], **pkgconfig('"libphone-utils"')) setup( name = 'python-phoneutils', version = '0.1', license = 'LGPL', author = 'Sebastian Krzyszkowiak', author_email = 'seba.dos1@gmail.com', url='http://shr-project.org/', description = 'Python bindings for libphone-utils', long_description = '', keywords = 'wrapper bindings phone utils telephone numbers', packages = find_packages(), # zip_safe=False, cmdclass = {"build_ext": build_ext}, ext_modules = [phoneutils_mod] )