Skip to content

THE Fastest and most Accurate device detection for C / PHP / Perl / Python and Node.js - professionally maintained device data

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE
Unknown
license.md
Notifications You must be signed in to change notification settings

51Degrees/Device-Detection

Repository files navigation

51Degrees Device Detection in C / C++ includes PHP, Python, Perl, .NET, Node.js, and Go

Recent Changes | Supported Databases | Developer Documention | Available Properties

Need .NET | Java | PHP Script?

Important note regarding trie

51Degrees Trie data files are now distributed directly from the 51Degrees website. Go to the pricing page for more information.

As of December 2023, we have retired the git.51degrees.com service. Please refer to our blog for more information.

Quick start

Use C code like...

// Declare Resources.
fiftyoneDegreesProvider provider;
fiftyoneDegreesWorkset *ws = NULL;
char *properties = "IsMobile,DeviceType,ScreenInchesDiagonal,PriceBand";
int cacheSize = 1000;
int poolSize = 5;
// Initialise provider.
fiftyoneDegreesDataSetInitStatus status = fiftyoneDegreesInitProviderWithPropertyString(
"[DATA FILE LOCATION]", &provider, properties, poolSize, cacheSize);
// Get workset from the pool.
ws = fiftyoneDegreesProviderWorksetGet(provider);
// Perform detection.
fiftyoneDegreesMatch(ws, "[DEVICE USER AGENT]");
// Return Workset to the pool.
fiftyoneDegreesWorksetRelease(ws);
// Free provider when program complete.
fiftyoneDegreesProviderFree(&provider);

... to turn User-Agent HTTP header into useful information about device type, screen diagonal in inches, price band of the device and whether or not device is mobile.

Use C++ code like ...

Provider provider = new Provider("[DATA FILE LOCATION]",
	"IsMobile,DeviceType,ScreenInchesDiagonal,PriceBand");
Match match = Provider.getMatch("[YOUR USERAGENT]");
match.Dispose();
provider.Dispose();

... to turn User-Agent HTTP headers into useful information about device type, screen diagonal in inches, price band of the device and whether or not device is mobile.

Extensions available for PHP, Python, Perl and Node.

[Review All Properties](https://51degrees.com/resources/property-dictionary?utm_source=github&utm_medium=repository&utm_content=home-cta&utm_campaign=c-open-source" View all available properties and values")

Introduction

Use this project to detect device properties using HTTP browser User-Agent headers as input. It can be used to process server log files, or for real time device detection to support web optimisation.

Two detection methods are supported.

Pattern: Searches for device signatures in a User-Agent. Unlike previous versions, this does not use regular expression and uses an external data file for easy updates.

Trie: A large binary Trie (pronounced Try) populated with device Patterns. Uses a separate data file. Very fast. See Important note regarding trie

PHP, Python, Perl and C# APIs are built using SWIG, so all use the same C++ Provider and Match classes. This keeps all the APIs consistent and introduces any new features across all APIs simultaneously.

This package includes the following examples:

  1. Command line process which takes a user agent via stdin and return a device id via stdout. Can easily be modified to return other properties. (ProcPat & ProcTrie projects)

  2. Command line performance evaluation program which takes a file of user agents and returns a performance score measured in detections per second per CPU core. (PerfPat & PerfTrie projects)

  3. Visual Studio solution with example web site, command line projects and C++ projects to demonstrate how to access from managed and unmanaged code.

  4. Getting Started (Pattern and Trie), takes some common User-Agents and returns the value of the IsMobile property.

  5. Match Metrics, takes some common User-Agents and returns various metrics relating to the match carried out on them.

  6. Offline Processing, takes an input file with a list of User-Agent, processes them and writes results to an output file.

  7. Strongly Typed, takes some common User-Agents and returns the value of the IsMobile property as a boolean.

  8. Match for Device Id, takes some common device ids and returns the value of the IsMobile property.

  9. Reload from File (Pattern and Trie), illustrates how to reload the data file from the data file on disk without restarting the application. Contains example of both the single threaded and multithreaded reload.

  10. Reload from Memory (Pattern and Trie), illustrates how to reload the data file from a continuous memory space that the data file was read into without restarting the application. Contains example of both the single threaded and multithreaded reload.

  11. Find Profiles, illustrates how to retrieve profiles based on some user-defined value of one of the properties.

  12. PHP, Perl and Python folders containing makefiles for building the respective extensions.

Examples 3-8 are available in C, and in C# using the C++ Provider. They are also available in Python, Perl and PHP using the same C++ Provider within their subdirectories.

Use the following instructions to compile different versions for different target platforms.

Note: when compiling the examples with GCC or Clang there is a dependancy on dmalloc, and dmallocth for the multithreaded reload functions.

SWIG

All C/C++ based APIs depend on code generated by SWIG. The policy is to only support language versions (e.g. Python 2.7 and Python 3.4) which are supported in stable SWIG. Where neccessary development versions will be released in a separate branch using wrappers generated using a development branch of SWIG.

Included Files

makefile - Builds a command line executable under Linux. CMakeLists - Builds the example projects under Windows, Linux and OS X. LICENSE - The licence terms for all source code and Lite data.

ApacheBench/ - A version of the Apache Benchmarking tool modified to randomly generate User-Agent headers. See ApacheBench/README.md for more details.

CodeBlocks/ - project files for CodeBlocks IDE for 5 generic project types.

    PerfPat - Project files using standard C source.
    PerfTrie - Project files using standard C source.
    ProcPat - Project files using standard C source.
    ProcTrie - Project files using standard C source.
    Console - Project files using standard C source.
    FindProfiles - Project files using standard C source.
    GettingStarted - Project files using standard C source.
    MatchForDeviceId - Project files using standard C source.
    MatchMetrics - Project files using standard C source.
    OfflineProcessing - Project files using standard C source.
    ReloadFromFile - Project files using standard C source.
    ReloadFromMemory - Project files using standard C source.
    StronglyTyped - Project files using standard C source.

data/ - Open source device data files.

    51Degrees-LiteV3.2.dat - uncompressed data file for use with Pattern.     20000 User Agents.csv - file with 20,000 popular User-Agents.
Compare Device Databases

examples/ - Contain C source files of example programs. Corresponding project files are available for Visual Studio and Code Blocks.

go/ - Files for Golang extension. See go/README.md for details.

haproxy/ - References files necessary to build the API with HA Proxy.

node.js/ - Files for Node.js extension. See node.js/README.md for details.

perl/ - Files for Perl extension. See perl/README.md for details.

php/ - Files for PHP extension. See php/README.md for details.

python/ - Files for Python extension. See python/README.md for details.

src/ - all generic C files used across multiple platforms.

    threading.h - Macros used for threading including locking, signalling and running multi threaded operations for GCC and MSVC compilers.
    threading.c - provide more complex implementations for GCC compilers.

src/Pattern - all source files related to Pattern matching detection.

    51Degrees.h - The header file for the core detection library.
    51Degrees.c - All the code and necessary data. Quite large.
    ProcPat.c - The command line interface wrapper.
    PerfPat.c - The command line performance test executable.
    Provider.cpp - Uses 51Degrees.c and Match.cpp to serve a Provider object.
    Provider.hpp - The header file for Provider.cpp.
    Match.cpp - Uses 51Degrees.c to serve a match object.
    Match.hpp - The header file for Match.cpp.
    Profiles.cpp - Used by the provider for the find profiles functionality.
    Profiles.hpp - The header file for Profiles.cpp
    51Degrees.i - Used by SWIG to generate Pattern-based extensions.
    The CXX files - Wrappers generated by SWIG.
    ProcPat - Example console project that performs detection based on user input.
    PerfPat - Example console project that measures Pattern performance.

src/Trie - all source files related to Trie matching detection.

See Important note regarding trie

    51Degrees.c - Placeholder for source code needed to interrogate the data.
    51Degrees.h - Placeholder for the header file for the core detection library.     ProcTrie.c - The command line interface wrapper.
    PerfTrie.c - The command line performance test executable.
    Provider.cpp - Uses 51Degrees.c and Match.cpp to serve a Provider object.
    Provider.hpp - The header file for Provider.cpp.
    Match.cpp - Uses 51Degrees.c to serve a match object.
    Match.cpp - The header file for Match.cpp.

src/cityhash - a port of Google's cityhash algorithm to C by Alexander Nusov.

    city.h - The cityhash header file with CRC methods removed.
    city.c - The cityhash implementation in C with CRC methods removed.
    LICENSE.txt - Licence under which cityhash is distributed.

src/snprintf - source files to provide safe, OS independent snprintf functions if not supported by the compiler. These resources are no longer used but retained in case integrators need them.

    snprintf.h - The snprintf header file.
    snprintf.c - The snprintf implementation.
    LICENSE.txt - Licence under which snprintf is distributed.

VisualStudio/ - all files related exclusively to Windows and Visual Studio 2013.

    Win32build.bat - Builds command line executable in 32 bit Windows.
    Win64build.bat - Builds command line executable in 64 bit Windows.
    WinGCCbuild.bat - Builds command line executable using GCC for Windows.

    Interop/FiftyOne.Mobile.Detection.Provider.Interop.csproj - C# project.
    Interop/PatternWrapper.cs - C# class used to wrap and expose Pattern matching library to .NET callers.
    Interop/TrieWrapper.cs - C# class used to wrap and expose Trie matching library to .NET callers.
    Interop/Utils.cs - Utility class for shared internal methods.
    Interop/Properties/AssemblyInfo.cs - DLL header information.

    Trie/FiftyOne.Mobile.Detection.Provider.Trie.vcxproj - C library project.
    Trie/FuncsTrieDll.c - Dll methods accessible to any Windows library.

    Pattern/FiftyOne.Mobile.Detection.Provider.Pattern.vcxproj - C lib project.
    Pattern/FuncsPatternDll.c - Dll methods accessible to any Windows library.

    Console Interop/Console Interop.csproj - Project file for a console application which demonstrates access to the Interop wrapper.
    Console Interop/Program.cs - Main method with simple code to prove the Interop wrappers are working.
    Console Interop/Properties/AssemblyInfo.cs - Project header information.

    Examples/Getting Started/Getting Started.* - Project files for a getting started example.
    Examples/Getting Started Trie/Getting Started Trie.* - Project files for a getting started example.
    Examples/Match For Device Id/Match For Device Id.* - Project files for a match for device id example.
    Exampes/Match Metrics/Match Metrics.* - Project files for a match metrics example.
    Examples/Offline Processing/Offline Processing.* - Project files for an offline processing example.
    Exampels/Strongly Typed/Strongly Typed.* - Project files for a strongly typed example.
    Examples/Reload From File/Reload From File.* - Project files for a reload example.     Examples/Reload From File/Reload From Memory.* - Project files for a reload example.     Examples/Reload From File/Reload From File Trie.* - Project files for a reload example.     Examples/Reload From File/Reload From Memory Trie.* - Project files for a reload example.

    CS Examples/Getting Started/* - Project files for a getting started example.
    CS Examples/Getting Started Trie/* - Project files for a getting started example.
    CS Examples/Match For Device Id/* - Project files for a match for device id example.
    CS Examples/Match Metrics/* - Project files for a match metrics example.
    CS Examples/Offline Processing/* - Project files for an offline processing example.
    CS Examples/Strongly Typed/* - Project files for a strongly typed example.
    CS Examples/Reload Data File/* - Project files for a strongly typed example.
    CS Examples/Examples Tests/* - Project files for tests which test each example.

    Demo/Web Site.csproj - Demo web site using the Interop assembly to request properties associated with the requesting device.
    Demo/Default.aspx.* - Demo web page used to display properties. See these files for examples of how to create providers and reTrieve properties.
    Demo/Properties/AssemblyInfo.cs - Project header information.

    Performance/FiftyOne.Mobile.Detection.Performance.vcxproj - Project file for the multi threaded Windows command line executable.
    Performance/Performance.cpp - Main class for the executable.
    Performance/*.cpp & *.h - Related files to the C++ program.

    PerfPat/PerfPat.vcxproj - Project file using standard C source.
    PerfTrie/PerfTrie.vcxproj - Project file using standard C source.
    ProcPat/ProcPat.vcxproj - Project file using standard C source.
    ProcTrie/ProcTrie.vcxproj - Project file using standard C source.
    Console/Console.vcxproj - Project file using standard C source.

    x64Build.bat - Uses the Visual Studio compiler to build a x64 library.
    x86Build.bat - Uses the Visual Studio compiler to build a x86 library.
    VisualStudio.sln - Visual Studio 2013 solution including demonstration web site, interop console, performance and general C projects.

About

THE Fastest and most Accurate device detection for C / PHP / Perl / Python and Node.js - professionally maintained device data

Resources

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE
Unknown
license.md

Stars

Watchers

Forks

Packages

No packages published