Home | History | Annotate | Download | only in avahi-core

Lines Matching refs:rj

78     AvahiResponseJob *rj;
83 if (!(rj = avahi_new(AvahiResponseJob, 1))) {
88 rj->scheduler = s;
89 rj->record = avahi_record_ref(record);
90 rj->time_event = NULL;
91 rj->flush_cache = 0;
92 rj->querier_valid = 0;
94 if ((rj->state = state) == AVAHI_SCHEDULED)
95 AVAHI_LLIST_PREPEND(AvahiResponseJob, jobs, s->jobs, rj);
96 else if (rj->state == AVAHI_DONE)
97 AVAHI_LLIST_PREPEND(AvahiResponseJob, jobs, s->history, rj);
98 else /* rj->state == AVAHI_SUPPRESSED */
99 AVAHI_LLIST_PREPEND(AvahiResponseJob, jobs, s->suppressed, rj);
101 return rj;
104 static void job_free(AvahiResponseScheduler *s, AvahiResponseJob *rj) {
106 assert(rj);
108 if (rj->time_event)
109 avahi_time_event_free(rj->time_event);
111 if (rj->state == AVAHI_SCHEDULED)
112 AVAHI_LLIST_REMOVE(AvahiResponseJob, jobs, s->jobs, rj);
113 else if (rj->state == AVAHI_DONE)
114 AVAHI_LLIST_REMOVE(AvahiResponseJob, jobs, s->history, rj);
115 else /* rj->state == AVAHI_SUPPRESSED */
116 AVAHI_LLIST_REMOVE(AvahiResponseJob, jobs, s->suppressed, rj);
118 avahi_record_unref(rj->record);
119 avahi_free(rj);
124 static void job_set_elapse_time(AvahiResponseScheduler *s, AvahiResponseJob *rj, unsigned msec, unsigned jitter) {
128 assert(rj);
132 if (rj->time_event)
133 avahi_time_event_update(rj->time_event, &tv);
135 rj->time_event = avahi_time_event_new(s->time_event_queue, &tv, elapse_callback, rj);
138 static void job_mark_done(AvahiResponseScheduler *s, AvahiResponseJob *rj) {
140 assert(rj);
142 assert(rj->state == AVAHI_SCHEDULED);
144 AVAHI_LLIST_REMOVE(AvahiResponseJob, jobs, s->jobs, rj);
145 AVAHI_LLIST_PREPEND(AvahiResponseJob, jobs, s->history, rj);
147 rj->state = AVAHI_DONE;
149 job_set_elapse_time(s, rj, AVAHI_RESPONSE_HISTORY_MSEC, 0);
151 gettimeofday(&rj->delivery, NULL);
192 AvahiResponseJob *rj = userdata;
195 assert(rj);
197 avahi_response_scheduler_post(rj->scheduler, r, flush_cache, rj->querier_valid ? &rj->querier : NULL, 0);
200 static int packet_add_response_job(AvahiResponseScheduler *s, AvahiDnsPacket *p, AvahiResponseJob *rj) {
203 assert(rj);
206 if (!avahi_dns_packet_append_record(p, rj->record, rj->flush_cache, 0))
211 avahi_server_enumerate_aux_records(s->interface->monitor->server, s->interface, rj->record, enumerate_aux_records_callback, rj);
212 job_mark_done(s, rj);
217 static void send_response_packet(AvahiResponseScheduler *s, AvahiResponseJob *rj) {
222 assert(rj);
229 if (packet_add_response_job(s, p, rj)) {
246 size = avahi_record_get_estimate_size(rj->record) + AVAHI_DNS_PACKET_HEADER_SIZE;
251 if (!packet_add_response_job(s, p, rj)) {
255 job_mark_done(s, rj);
266 AvahiResponseJob *rj = data;
268 assert(rj);
270 if (rj->state == AVAHI_DONE || rj->state == AVAHI_SUPPRESSED)
271 job_free(rj->scheduler, rj); /* Lets drop this entry */
273 send_response_packet(rj->scheduler, rj);
277 AvahiResponseJob *rj;
282 for (rj = s->jobs; rj; rj = rj->jobs_next) {
283 assert(rj->state == AVAHI_SCHEDULED);
285 if (avahi_record_equal_no_ttl(rj->record, record))
286 return rj;
293 AvahiResponseJob *rj;
298 for (rj = s->history; rj; rj = rj->jobs_next) {
299 assert(rj->state == AVAHI_DONE);
301 if (avahi_record_equal_no_ttl(rj->record, record)) {
304 /* avahi_log_debug("history age: %u", (unsigned) (avahi_age(&rj->delivery)/1000)); */
306 if (avahi_age(&rj->delivery)/1000 > AVAHI_RESPONSE_HISTORY_MSEC) {
308 job_free(s, rj);
312 return rj;
320 AvahiResponseJob *rj;
326 for (rj = s->suppressed; rj; rj = rj->jobs_next) {
327 assert(rj->state == AVAHI_SUPPRESSED);
328 assert(rj->querier_valid);
330 if (avahi_record_equal_no_ttl(rj->record, record) &&
331 avahi_address_cmp(&rj->querier, querier) == 0) {
334 if (avahi_age(&rj->delivery) > AVAHI_RESPONSE_SUPPRESS_MSEC*1000) {
336 job_free(s, rj);
340 return rj;
348 AvahiResponseJob *rj;
363 (rj = find_suppressed_job(s, record, querier)) &&
364 avahi_record_is_goodbye(record) == avahi_record_is_goodbye(rj->record) &&
365 rj->record->ttl >= record->ttl/2) {
372 if ((rj = find_history_job(s, record))) {
374 if (avahi_record_is_goodbye(record) == avahi_record_is_goodbye(rj->record) &&
375 rj->record->ttl >= record->ttl/2 &&
376 (rj->flush_cache || !flush_cache)) {
382 job_free(s, rj);
387 if ((rj = find_scheduled_job(s, record))) {
393 if (avahi_timeval_compare(&tv, &rj->delivery) < 0) {
394 rj->delivery = tv;
395 avahi_time_event_update(rj->time_event, &rj->delivery);
400 rj->flush_cache = 1;
403 if (!querier || (rj->querier_valid && avahi_address_cmp(querier, &rj->querier) != 0))
404 rj->querier_valid = 0;
407 avahi_record_unref(rj->record);
408 rj->record = avahi_record_ref(record);
415 if (!(rj = job_new(s, record, AVAHI_SCHEDULED)))
418 rj->delivery = tv;
419 rj->time_event = avahi_time_event_new(s->time_event_queue, &rj->delivery, elapse_callback, rj);
420 rj->flush_cache = flush_cache;
422 if ((rj->querier_valid = !!querier))
423 rj->querier = *querier;
430 AvahiResponseJob *rj;
437 if ((rj = find_scheduled_job(s, record))) {
439 if ((!rj->flush_cache || flush_cache) && /* flush cache bit was set correctly */
440 avahi_record_is_goodbye(record) == avahi_record_is_goodbye(rj->record) && /* both goodbye packets, or both not */
441 record->ttl >= rj->record->ttl/2) { /* sensible TTL */
445 job_mark_done(s, rj);
451 if ((rj = find_history_job(s, record))) {
453 avahi_record_unref(rj->record);
454 rj->record = avahi_record_ref(record);
457 if (!(rj = job_new(s, record, AVAHI_DONE)))
460 rj->flush_cache = flush_cache;
461 rj->querier_valid = 0;
463 gettimeofday(&rj->delivery, NULL);
464 job_set_elapse_time(s, rj, AVAHI_RESPONSE_HISTORY_MSEC, 0);
468 AvahiResponseJob *rj;
474 if ((rj = find_scheduled_job(s, record))) {
476 if (rj->querier_valid && avahi_address_cmp(querier, &rj->querier) == 0 && /* same originator */
477 avahi_record_is_goodbye(record) == avahi_record_is_goodbye(rj->record) && /* both goodbye packets, or both not */
478 record->ttl >= rj->record->ttl/2) { /* sensible TTL */
482 job_free(s, rj);
486 if ((rj = find_suppressed_job(s, record, querier))) {
489 avahi_record_unref(rj->record);
490 rj->record = avahi_record_ref(record);
495 if (!(rj = job_new(s, record, AVAHI_SUPPRESSED)))
497 rj->querier_valid = 1;
498 rj->querier = *querier;
501 gettimeofday(&rj->delivery, NULL);
502 job_set_elapse_time(s, rj, AVAHI_RESPONSE_SUPPRESS_MSEC, 0);