Home | History | Annotate | Download | only in mDNSShared

Lines Matching defs:sdr

116 typedef void (*ProcessReplyFn)(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *msg, const char *const end);
156 DNSServiceOp *sdr;
424 DNSServiceOp *sdr;
455 sdr = malloc(sizeof(DNSServiceOp));
456 if (!sdr) { syslog(LOG_WARNING, "dnssd_clientstub ConnectToServer: malloc failed"); *ref = NULL; return kDNSServiceErr_NoMemory; }
457 sdr->next = NULL;
458 sdr->primary = NULL;
459 sdr->sockfd = dnssd_InvalidSocket;
460 sdr->validator = sdr->sockfd ^ ValidatorBits;
461 sdr->op = op;
462 sdr->max_index = 0;
463 sdr->logcounter = 0;
464 sdr->moreptr = NULL;
465 sdr->uid.u32[0] = 0;
466 sdr->uid.u32[1] = 0;
467 sdr->ProcessReply = ProcessReply;
468 sdr->AppCallback = AppCallback;
469 sdr->AppContext = AppContext;
470 sdr->rec = NULL;
472 sdr->disp_source = NULL;
473 sdr->disp_queue = NULL;
480 *p = sdr;
483 sdr->primary = *ref; // Set our primary pointer
484 sdr->sockfd = (*ref)->sockfd; // Inherit primary's socket
485 sdr->validator = (*ref)->validator;
486 sdr->uid = (*ref)->uid;
487 //printf("ConnectToServer sharing socket %d\n", sdr->sockfd);
495 sdr->sockfd = socket(AF_DNSSD, SOCK_STREAM, 0);
496 sdr->validator = sdr->sockfd ^ ValidatorBits;
497 if (!dnssd_SocketValid(sdr->sockfd))
500 FreeDNSServiceOp(sdr);
505 if (setsockopt(sdr->sockfd, SOL_SOCKET, SO_NOSIGPIPE, &optval, sizeof(optval)) < 0)
518 if (setsockopt(sdr->sockfd, SOL_SOCKET, SO_DEFUNCTOK, &defunct, sizeof(defunct)) < 0)
526 int err = connect(sdr->sockfd, (struct sockaddr *) &saddr, sizeof(saddr));
527 if (!err) break; // If we succeeded, return sdr
534 else { dnssd_close(sdr->sockfd); FreeDNSServiceOp(sdr); return kDNSServiceErr_ServiceNotRunning; }
536 //printf("ConnectToServer opened socket %d\n", sdr->sockfd);
539 *ref = sdr;
546 static DNSServiceErrorType deliver_request(ipc_msg_hdr *hdr, DNSServiceOp *sdr)
556 // Note: need to check hdr->op, not sdr->op.
557 // hdr->op contains the code for the specific operation we're currently doing, whereas sdr->op
559 // add_record_request but the parent sdr->op will be connection_request or reg_service_request)
560 if (sdr->primary ||
564 if (!DNSServiceRefValid(sdr))
566 syslog(LOG_WARNING, "dnssd_clientstub deliver_request: invalid DNSServiceRef %p %08X %08X", sdr, sdr->sockfd, sdr->validator);
640 if (MakeSeparateReturnSocket || sdr->op == send_bpf) datalen--; // Okay to use sdr->op when checking for op == send_bpf
652 if (write_all(sdr->sockfd, ((char *)hdr)+i, 1) < 0)
657 if (write_all(sdr->sockfd, (char *)hdr, datalen + sizeof(ipc_msg_hdr)) < 0)
663 sdr->sockfd, (unsigned long)(datalen + sizeof(ipc_msg_hdr)));
668 if (!MakeSeparateReturnSocket) errsd = sdr->sockfd;
669 if (MakeSeparateReturnSocket || sdr->op == send_bpf) // Okay to use sdr->op when checking for op == send_bpf
698 if (sdr->op == send_bpf) // Okay to use sdr->op when checking for op == send_bpf
738 if (sendmsg(sdr->sockfd, &msg, 0) < 0)
760 if (sdr->op == send_bpf) // Okay to use sdr->op when checking for op == send_bpf
812 DNSServiceOp *sdr = sdRef;
818 while (sdr)
820 // We can't touch the sdr after the callback as it can be deallocated in the callback
821 sdrNext = sdr->next;
823 sdr->moreptr = &morebytes;
824 switch (sdr->op)
827 if (sdr->AppCallback)((DNSServiceResolveReply) sdr->AppCallback)(sdrsdr->AppContext);
830 if (sdr->AppCallback)((DNSServiceQueryRecordReply)sdr->AppCallback)(sdr, 0, 0, error, NULL, 0, 0, 0, NULL, 0, sdr->AppContext);
833 if (sdr->AppCallback)((DNSServiceGetAddrInfoReply)sdr->AppCallback)(sdr, 0, 0, error, NULL, NULL, 0, sdr->AppContext);
836 if (sdr->AppCallback)((DNSServiceBrowseReply) sdr->AppCallback)(sdr, 0, 0, error, NULL, 0, NULL, sdr->AppContext);
839 if (sdr->AppCallback)((DNSServiceRegisterReply) sdr->AppCallback)(sdr, 0, error, NULL, 0, NULL, sdr->AppContext);
842 if (sdr->AppCallback)((DNSServiceDomainEnumReply) sdr->AppCallback)(sdr, 0, 0, error, NULL, sdr->AppContext);
845 if (sdr->AppCallback)((DNSServiceSetHostReply) sdr->AppCallback)(sdr, 0, error, NULL, sdr->AppContext);
849 rec = sdr->rec;
853 if (rec->AppCallback) ((DNSServiceRegisterRecordReply)rec->AppCallback)(sdr, 0, 0, error, rec->AppContext);
854 // The Callback can call DNSServiceRefDeallocate which in turn frees sdr and all the records.
861 if (sdr->AppCallback)((DNSServiceNATPortMappingReply)sdr->AppCallback)(sdr, 0, 0, error, 0, 0, 0, 0, 0, sdr->AppContext);
864 syslog(LOG_WARNING, "dnssd_clientstub CallbackWithError called with bad op %d", sdr->op);
870 sdr = sdrNext;
1107 static void handle_resolve_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *end)
1125 ((DNSServiceResolveReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_interface, cbh->cb_err, fullname, target, port.s, txtlen, txtrecord, sdr->AppContext);
1127 // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
1185 static void handle_query_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *const end)
1200 else ((DNSServiceQueryRecordReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_interface, cbh->cb_err, name, rrtype, rrclass, rdlen, rdata, ttl, sdr->AppContext);
1201 // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
1244 static void handle_addrinfo_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *const end)
1294 ((DNSServiceGetAddrInfoReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_interface, cbh->cb_err, hostname, sa, ttl, sdr->AppContext);
1295 // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
1339 static void handle_browse_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *const end)
1346 else ((DNSServiceBrowseReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_interface, cbh->cb_err, replyName, replyType, replyDomain, sdr->AppContext);
1347 // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
1386 static void handle_hostname_changed_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *const end)
1392 else ((DNSHostnameChangedReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_err, replyHostname, sdr->AppContext);
1393 // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
1443 static void handle_regservice_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *const end)
1450 else ((DNSServiceRegisterReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_err, name, regtype, domain, sdr->AppContext);
1451 // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
1514 static void handle_enumeration_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *const end)
1519 else ((DNSServiceDomainEnumReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_interface, cbh->cb_err, domain, sdr->AppContext);
1520 // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
1558 static void ConnectionResponse(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *const data, const char *const end)
1569 DNSServiceOp *op = sdr->next;
1575 // WARNING: Don't touch op or sdr after this -- client may have called DNSServiceRefDeallocate
1579 if (sdr->op == connection_request)
1580 rref->AppCallback(rref->sdr, rref, cbh->cb_flags, cbh->cb_err, rref->AppContext);
1583 syslog(LOG_WARNING, "dnssd_clientstub ConnectionResponse: sdr->op != connection_request");
1584 rref->AppCallback(rref->sdr, rref, 0, kDNSServiceErr_Unknown, rref->AppContext);
1586 // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function
1669 rref->sdr = sdRef;
1734 rref->sdr = sdRef;
1866 static void handle_port_mapping_response(DNSServiceOp *const sdr, const CallbackHeader *const cbh, const char *data, const char *const end)
1888 ((DNSServiceNATPortMappingReply)sdr->AppCallback)(sdr, cbh->cb_flags, cbh->cb_interface, cbh->cb_err, addr.l, protocol, internalPort.s, externalPort.s, ttl, sdr->AppContext);
1890 // MUST NOT touch sdr after invoking AppCallback -- client is allowed to dispose it from within callback function