blob: 742e14b2f9f89e311c462b5effee20d13b27b2c3 [file] [log] [blame]
Oliver Smithbf7deda2019-11-20 10:56:35 +01001/* Copyright 2019 by sysmocom s.f.m.c. GmbH <info@sysmocom.de>
2 *
3 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 */
19
20#include <string.h>
21#include <osmocom/core/application.h>
22#include <osmocom/core/select.h>
23#include <osmocom/hlr/logging.h>
24#include <osmocom/mslookup/mslookup_client.h>
25
26void *ctx;
27
28const char *domains[] = {
29 "gsup.hlr.123456789012345.imsi",
30 "gsup.hlr.1.imsi",
31 "sip.voice.1.msisdn",
32 "a.b.c.imsi",
33 "",
34 ".",
35 "...",
36 ".....",
37 ".....1.msisdn",
38 "fofdndsf. d.ads ofdsf. ads.kj.1243455132.msisdn",
39 "foo.12345678901234567890.imsi",
40 "gsup.hlr.123456789012345.what",
41 NULL,
42 "blarg",
43 "blarg.",
44 "blarg.1.",
45 "blarg.1.msisdn",
46 "blarg.1.msisdn.",
47 ".1.msisdn",
48 "1.msisdn",
49 "qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmm.1.msisdn",
50 "qwerty.1.qwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmqwertyuiopasdfghjklzxcvbnmm",
51};
52
Harald Welte7a476532022-11-03 11:38:41 +010053void test_osmo_mslookup_query_init_from_domain_str(void)
Oliver Smithbf7deda2019-11-20 10:56:35 +010054{
55 int i;
56 for (i = 0; i < ARRAY_SIZE(domains); i++) {
57 const char *d = domains[i];
58 struct osmo_mslookup_query q;
59
60 int rc = osmo_mslookup_query_init_from_domain_str(&q, d);
61 if (rc)
62 fprintf(stderr, "%s -> rc = %d\n", osmo_quote_str(d, -1), rc);
63 else
64 fprintf(stderr, "%s -> %s %s %s\n", osmo_quote_str(d, -1),
65 osmo_quote_str_c(ctx, q.service, -1),
66 osmo_quote_str_c(ctx, q.id.imsi, -1),
67 osmo_mslookup_id_type_name(q.id.type));
68 }
69}
70
Harald Welte7a476532022-11-03 11:38:41 +010071int main(int argc, char **argv)
Oliver Smithbf7deda2019-11-20 10:56:35 +010072{
73 ctx = talloc_named_const(NULL, 0, "main");
74 osmo_init_logging2(ctx, NULL);
75
Pau Espin Pedrold6993ea2021-02-19 13:20:18 +010076 log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
Oliver Smithbf7deda2019-11-20 10:56:35 +010077 log_set_print_level(osmo_stderr_target, 0);
78 log_set_print_category(osmo_stderr_target, 0);
79 log_set_print_category_hex(osmo_stderr_target, 0);
80 log_set_use_color(osmo_stderr_target, 0);
81 log_set_category_filter(osmo_stderr_target, DMSLOOKUP, true, LOGL_DEBUG);
82
83 test_osmo_mslookup_query_init_from_domain_str();
84
85 talloc_free(ctx);
86
87 return 0;
88}