Oliver Smith | 3a9f267 | 2019-11-20 10:56:35 +0100 | [diff] [blame] | 1 | /* 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 General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 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 General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include "mdns_rfc.h" |
| 23 | |
| 24 | struct osmo_mdns_record { |
| 25 | struct llist_head list; |
| 26 | enum osmo_mdns_rfc_record_type type; |
| 27 | uint16_t length; |
| 28 | uint8_t *data; |
| 29 | }; |
| 30 | |
| 31 | struct osmo_mdns_msg_request { |
| 32 | uint16_t id; |
| 33 | char *domain; |
| 34 | enum osmo_mdns_rfc_record_type type; |
| 35 | }; |
| 36 | |
| 37 | struct osmo_mdns_msg_answer { |
| 38 | uint16_t id; |
| 39 | char *domain; |
| 40 | /*! list of osmo_mdns_record. */ |
| 41 | struct llist_head records; |
| 42 | }; |
| 43 | |
| 44 | int osmo_mdns_msg_request_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_msg_request *req); |
| 45 | struct osmo_mdns_msg_request *osmo_mdns_msg_request_decode(void *ctx, const uint8_t *data, size_t data_len); |
| 46 | |
| 47 | void osmo_mdns_msg_answer_init(struct osmo_mdns_msg_answer *answer); |
| 48 | int osmo_mdns_msg_answer_encode(void *ctx, struct msgb *msg, const struct osmo_mdns_msg_answer *ans); |
| 49 | struct osmo_mdns_msg_answer *osmo_mdns_msg_answer_decode(void *ctx, const uint8_t *data, size_t data_len); |
| 50 | int osmo_mdns_result_from_answer(struct osmo_mslookup_result *result, const struct osmo_mdns_msg_answer *ans); |
| 51 | |
| 52 | struct osmo_mdns_record *osmo_mdns_record_txt_keyval_encode(void *ctx, const char *key, const char *value_fmt, ...); |
| 53 | int osmo_mdns_record_txt_keyval_decode(const struct osmo_mdns_record *rec, |
| 54 | char *key_buf, size_t key_size, char *value_buf, size_t value_size); |