pike.git / src / modules / _Protocols_DNS_SD / sd.c

version» Context lines:

pike.git/src/modules/_Protocols_DNS_SD/sd.c:53: Inside #if defined(HAVE_DNS_SD) || defined(HAVE_HOWL), #if defined(HAVE_DNS_SD) and #if defined(HAVE_DNS_SD_H)
  #ifdef HAVE_DNS_SD_H      /* Workaround for typo in 10.3 header (which 10.4 doesn't preserve) */   #define kDNSServiceErr_BadinterfaceIndex kDNSServiceErr_BadInterfaceIndex      #include <dns_sd.h>   #endif      #define IS_ERR(x) ((x) != kDNSServiceErr_NoError)    + /* Include these for htons(3SOCKET) et al. */ + #ifdef HAVE_ARPA_INET_H + #include <arpa/inet.h> + #endif + #ifdef HAVE_NETINET_IN_H + #include <netinet/in.h> + #endif +    /* Instance variables for each service registration */   struct service {    DNSServiceRef service_ref;   };         static void raise_error(char *msg, DNSServiceErrorType err)   {    char *reason;   
pike.git/src/modules/_Protocols_DNS_SD/sd.c:157:    if (err == kDNSServiceErr_NoError)    svc->service_ref = ref;       err = DNSServiceProcessResult(ref);    return err;   }         static void stop_service(struct service *svc)   { -  if (svc->service_ref) { +  if (svc->service_ref)    DNSServiceRefDeallocate(svc->service_ref); -  svc->service_ref = NULL; +    } - } +          static DNSServiceErrorType update_txt_record(struct service *svc,    char *txt, int txtlen)   {    if (svc->service_ref) {    int ttl = 0;    return DNSServiceUpdateRecord(svc->service_ref, NULL, 0,    txtlen, txt, ttl);    }
pike.git/src/modules/_Protocols_DNS_SD/sd.c:283:   }         static void * howl_thread(void *arg)   {    sw_discovery_run(service_session);    return NULL;   }       - static void init_howl_module() + static void init_howl_module(void)   {    if (sw_discovery_init(&service_session) == SW_OKAY) {    th_create_small(&service_thread, howl_thread, NULL);    }   }       - static void exit_howl_module() + static void exit_howl_module(void)   {    /* Close active session */    if (service_session)    sw_discovery_fina(service_session);       /* Kill Howl thread if running */    if (service_thread)    th_kill(service_thread, SIGCHLD);   }         #endif /* defined(HAVE_HOWL) && !defined(HAVE_DNS_SD) */               static void f_update_txt(INT32 args)   { -  check_all_args("Service->update_txt", args, +  check_all_args(NULL, args,    BIT_STRING, /* txt */    0);       /* Can only be called if we have valid service */    if (THIS->service_ref) {    char *txt = sp[0 - args].u.string->str;    int txtlen = sp[0 - args].u.string->len;       int err = update_txt_record(THIS, txt, txtlen);    if (IS_ERR(err))
pike.git/src/modules/_Protocols_DNS_SD/sd.c:332:    }    pop_n_elems(args);   }         static void f_create(INT32 args)   {    char *name, *service, *domain, *txt;    int port, txtlen, err;    -  check_all_args("Service->create", args, +  check_all_args(NULL, args,    BIT_STRING, /* name */    BIT_STRING, /* service */    BIT_STRING, /* domain */    BIT_INT, /* port */    BIT_STRING | BIT_VOID, /* txt */    0);       /* Stop existing service if one is running */    stop_service(THIS);   
pike.git/src/modules/_Protocols_DNS_SD/sd.c:359:       /* Optional TXT record may theoretically contain NUL chars so we can't    trust strlen. */    txt = (args == 5) ? sp[4 - args].u.string->str : NULL;    txtlen = txt ? sp[4 - args].u.string->len : 0;       /* Register new service */    err = start_service(THIS, name, service, domain, port, txt, txtlen);    if (IS_ERR(err))    raise_error("Could not register service.", err); -  pop_n_elems(args); +    }       - static void init_service_struct(struct object *UNUSED(o)) - { -  THIS->service_ref = 0; - } -  -  +    static void exit_service_struct(struct object *UNUSED(o))   {    /* Stop an existing service */    stop_service(THIS);   }         PIKE_MODULE_INIT   {    start_new_program();       ADD_STORAGE(struct service);    -  set_init_callback(init_service_struct); +     set_exit_callback(exit_service_struct);       /* function(string, string, string, int, string|void:void) */    ADD_FUNCTION("create", f_create,    tFunc(tStr tStr tStr tInt tOr(tStr, tVoid), tVoid), 0);       /* function(string:void) */    ADD_FUNCTION("update_txt", f_update_txt, tFunc(tStr, tVoid), 0);       end_class("Service", 0);