https://github.com/kjdev/woothee-c
The C implementation of Project Woothee
https://github.com/kjdev/woothee-c
Last synced: 10 months ago
JSON representation
The C implementation of Project Woothee
- Host: GitHub
- URL: https://github.com/kjdev/woothee-c
- Owner: kjdev
- License: mit
- Created: 2015-11-12T23:52:26.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-01T05:02:13.000Z (over 9 years ago)
- Last Synced: 2025-02-09T06:44:16.966Z (about 1 year ago)
- Language: C
- Size: 39.1 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Woothee C
[](https://travis-ci.org/kjdev/woothee-c)
[](https://codecov.io/github/kjdev/woothee-c?branch=master)
The C implementation of Project Woothee, which is multi-language user-agent
strings parsers.
https://github.com/woothee/woothee
## Installation
```
$ make
$ make test
$ make install
```
> requires pcre library
## Usage
### Parsing user-agent
``` c
#include
int main() {
woothee_t *woothee = woothee_parse("user agent string");
woothee->name;
// => name of browser (or string like name of user-agent)
woothee->category;
// => "pc", "smartphone", "mobilephone", "appliance", "crawler", "misc", "unknown"
woothee->os;
// => os from user-agent, or carrier name of mobile phones
woothee->version;
// => version of browser, or terminal type name of mobile phones
woothee->os_version;
// => version of operating systems (for some typical cases)
woothee_delete(woothee);
return 0;
}
```
Parse user-agent string and returns struct with keys `name`, `category`, `os`,
`version`, `os_version` and `vendor`.
For unknown user-agent (or partially failed to parse),
result may have value 'UNKNOWN'.
* `category`
* labels of user terminal type, one of 'pc', 'smartphone', 'mobilephone',
'appliance', 'crawler' or 'misc' (or 'UNKNOWN')
* `name`
* the name of browser, like 'Internet Explorer', 'Firefox', 'GoogleBot'
* `version`
* version string, like '8.0' for IE, '9.0.1' for Firefix,
'0.2.149.27' for Chrome, and so on
* `os`
* ex: 'Windows 7', 'Mac OSX', 'iPhone', 'iPad', 'Android'
* This field used to indicate cellar phone carrier for category 'mobilephone'
* `vendor`
* optional field, shows browser vendor
* `os_version`
* optional field, shows version of operating systems
### Finding crawlers (almost all, not all) in fast
``` c
woothee_is_crawler("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)");
// => 0
```
### Compile in woothee library
Create example code.
``` c
/* example.c */
#include
#include
int main(int argc, char **argv) {
if (argc > 1) {
woothee_t *woothee = woothee_parse(argv[1]);
printf("name = %s\n", woothee->name);
woothee_delete(woothee);
}
return 0;
}
```
Compile example code.
```
$ gcc -o example example.c `pkg-config --cflags --libs woothee`
```
Execute example.
```
$ ./example "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)"
name = Internet Explorer
```