]> git.ipfire.org Git - people/ms/libloc.git/blame - src/loc/country.h
location-export: Validate country codes
[people/ms/libloc.git] / src / loc / country.h
CommitLineData
ec684c1a
MT
1/*
2 libloc - A library to determine the location of someone on the Internet
3
4 Copyright (C) 2019 IPFire Development Team <info@ipfire.org>
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15*/
16
17#ifndef LIBLOC_COUNTRY_H
18#define LIBLOC_COUNTRY_H
19
20#include <loc/libloc.h>
21#include <loc/format.h>
22#include <loc/stringpool.h>
23
24struct loc_country;
25int loc_country_new(struct loc_ctx* ctx, struct loc_country** country, const char* country_code);
26struct loc_country* loc_country_ref(struct loc_country* country);
27struct loc_country* loc_country_unref(struct loc_country* country);
28
29const char* loc_country_get_code(struct loc_country* country);
30
31const char* loc_country_get_continent_code(struct loc_country* country);
32int loc_country_set_continent_code(struct loc_country* country, const char* continent_code);
33
34const char* loc_country_get_name(struct loc_country* country);
35int loc_country_set_name(struct loc_country* country, const char* name);
36
37int loc_country_cmp(struct loc_country* country1, struct loc_country* country2);
38
0f0829ef
MT
39int loc_country_code_is_valid(const char* cc);
40
ec684c1a
MT
41#ifdef LIBLOC_PRIVATE
42
57146963
MT
43#include <string.h>
44
ec684c1a
MT
45int loc_country_new_from_database_v0(struct loc_ctx* ctx, struct loc_stringpool* pool,
46 struct loc_country** country, const struct loc_database_country_v0* dbobj);
47int loc_country_to_database_v0(struct loc_country* country,
48 struct loc_stringpool* pool, struct loc_database_country_v0* dbobj);
49
a7a3d958 50static inline void loc_country_code_copy(char* dst, const char* src) {
ec684c1a
MT
51 for (unsigned int i = 0; i < 2; i++) {
52 dst[i] = src[i];
53 }
ec684c1a
MT
54}
55
56#endif
57
58#endif