~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to iris/irisnet/jdns/jdns_mdnsd.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2005       Jeremie Miller
3
 
 * Copyright (C) 2005,2006  Justin Karneges
4
 
 *
5
 
 * Permission is hereby granted, free of charge, to any person obtaining a
6
 
 * copy of this software and associated documentation files (the
7
 
 * "Software"), to deal in the Software without restriction, including
8
 
 * without limitation the rights to use, copy, modify, merge, publish,
9
 
 * distribute, sublicense, and/or sell copies of the Software, and to
10
 
 * permit persons to whom the Software is furnished to do so, subject to
11
 
 * the following conditions:
12
 
 *
13
 
 * The above copyright notice and this permission notice shall be included
14
 
 * in all copies or substantial portions of the Software.
15
 
 *
16
 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
 
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
 
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
 
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
 
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
 
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
 
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
 
 */
24
 
 
25
 
#ifndef JDNS_MDNSD_H
26
 
#define JDNS_MDNSD_H
27
 
 
28
 
#include "jdns_p.h"
29
 
 
30
 
struct mytimeval
31
 
{
32
 
        unsigned long int tv_sec;   /* seconds */
33
 
        unsigned long int tv_usec;  /* microseconds */
34
 
};
35
 
 
36
 
typedef struct mdnsd_struct *mdnsd; // main daemon data
37
 
typedef struct mdnsdr_struct *mdnsdr; // record entry
38
 
// answer data
39
 
typedef struct mdnsda_struct
40
 
{
41
 
    unsigned char *name;
42
 
    unsigned short int type;
43
 
    unsigned long int ttl;
44
 
    unsigned long int real_ttl;
45
 
    unsigned short int rdlen;
46
 
    unsigned char *rdata;
47
 
    unsigned long int ip; // A
48
 
    unsigned char *rdname; // NS/CNAME/PTR/SRV
49
 
    struct { unsigned short int priority, weight, port; } srv; // SRV
50
 
} *mdnsda;
51
 
 
52
 
///////////
53
 
// Global functions
54
 
//
55
 
// create a new mdns daemon for the given class of names (usually 1) and maximum frame size
56
 
mdnsd mdnsd_new(int class, int frame, int port, int (*time_now)(mdnsd d, void *arg), int (*rand_int)(mdnsd d, void *arg), void *arg);
57
 
//
58
 
// gracefully shutdown the daemon, use mdnsd_out() to get the last packets
59
 
void mdnsd_shutdown(mdnsd d);
60
 
//
61
 
// flush all cached records (network/interface changed)
62
 
void mdnsd_flush(mdnsd d);
63
 
//
64
 
// free given mdnsd (should have used mdnsd_shutdown() first!)
65
 
void mdnsd_free(mdnsd d);
66
 
//
67
 
///////////
68
 
 
69
 
///////////
70
 
// I/O functions
71
 
//
72
 
// incoming message from host (to be cached/processed)
73
 
void mdnsd_in(mdnsd d, const jdns_packet_t *m, const jdns_response_t *resp, const jdns_address_t *addr, unsigned short int port);
74
 
//
75
 
// outgoing messge to be delivered to host, returns >0 if one was returned and m/ip/port set
76
 
int mdnsd_out(mdnsd d, jdns_packet_t **m, jdns_address_t **addr, unsigned short int *port);
77
 
//
78
 
// returns the max wait-time until mdnsd_out() needs to be called again 
79
 
struct mytimeval *mdnsd_sleep(mdnsd d);
80
 
//
81
 
////////////
82
 
 
83
 
///////////
84
 
// Q/A functions
85
 
// 
86
 
// register a new query
87
 
//   answer(record, arg) is called whenever one is found/changes/expires (immediate or anytime after, mdnsda valid until ->ttl==0)
88
 
//   either answer returns -1, or another mdnsd_query with a NULL answer will remove/unregister this query
89
 
void mdnsd_query(mdnsd d, char *host, int type, int (*answer)(mdnsda a, void *arg), void *arg);
90
 
//
91
 
// returns the first (if last == NULL) or next answer after last from the cache
92
 
//   mdnsda only valid until an I/O function is called
93
 
mdnsda mdnsd_list(mdnsd d, char *host, int type, mdnsda last);
94
 
//
95
 
///////////
96
 
 
97
 
///////////
98
 
// Publishing functions
99
 
//
100
 
// create a new unique record (try mdnsda_list first to make sure it's not used)
101
 
//   conflict(arg) called at any point when one is detected and unable to recover
102
 
//   after the first data is set_*(), any future changes effectively expire the old one and attempt to create a new unique record
103
 
mdnsdr mdnsd_unique(mdnsd d, char *host, int type, long int ttl, void (*pubresult)(int result, char *host, int type, void *arg), void *arg);
104
 
// 
105
 
// create a new shared record
106
 
mdnsdr mdnsd_shared(mdnsd d, char *host, int type, long int ttl);
107
 
//
108
 
// de-list the given record
109
 
void mdnsd_done(mdnsd d, mdnsdr r);
110
 
//
111
 
// these all set/update the data for the given record, nothing is published until they are called
112
 
void mdnsd_set_raw(mdnsd d, mdnsdr r, char *data, int len);
113
 
void mdnsd_set_host(mdnsd d, mdnsdr r, char *name);
114
 
void mdnsd_set_ip(mdnsd d, mdnsdr r, unsigned long int ip);
115
 
void mdnsd_set_srv(mdnsd d, mdnsdr r, int priority, int weight, int port, char *name);
116
 
//
117
 
///////////
118
 
 
119
 
 
120
 
#endif