/usr/share/gocode/src/github.com/google/cups-connector/privet/avahi.c is in google-cloud-print-connector 0.0~git20151105.24.1902938-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | // Copyright 2015 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
// +build !darwin
#include "avahi.h"
#include "_cgo_export.h"
const char *SERVICE_TYPE = "_privet._tcp",
*SERVICE_SUBTYPE = "_printer._sub._privet._tcp";
// startAvahiClient initializes a poll object, and a client.
const char *startAvahiClient(AvahiThreadedPoll **threaded_poll, AvahiClient **client) {
*threaded_poll = avahi_threaded_poll_new();
if (!*threaded_poll) {
return avahi_strerror(avahi_client_errno(*client));
}
int error;
*client = avahi_client_new(avahi_threaded_poll_get(*threaded_poll),
AVAHI_CLIENT_NO_FAIL, handleClientStateChange, NULL, &error);
if (!*client) {
avahi_threaded_poll_free(*threaded_poll);
return avahi_strerror(error);
}
error = avahi_threaded_poll_start(*threaded_poll);
if (AVAHI_OK != error) {
avahi_client_free(*client);
avahi_threaded_poll_free(*threaded_poll);
return avahi_strerror(error);
}
return NULL;
}
const char *addAvahiGroup(AvahiThreadedPoll *threaded_poll, AvahiClient *client,
AvahiEntryGroup **group, const char *service_name, unsigned short port, AvahiStringList *txt) {
*group = avahi_entry_group_new(client, handleGroupStateChange, (void *)service_name);
if (!*group) {
return avahi_strerror(avahi_client_errno(client));
}
int error = avahi_entry_group_add_service_strlst(
*group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, service_name,
SERVICE_TYPE, NULL, NULL, port, txt);
if (AVAHI_OK != error) {
avahi_entry_group_free(*group);
return avahi_strerror(error);
}
error = avahi_entry_group_add_service_subtype(*group, AVAHI_IF_UNSPEC,
AVAHI_PROTO_UNSPEC, 0, service_name, SERVICE_TYPE, NULL, SERVICE_SUBTYPE);
if (AVAHI_OK != error) {
avahi_entry_group_free(*group);
return avahi_strerror(error);
}
error = avahi_entry_group_commit(*group);
if (AVAHI_OK != error) {
avahi_entry_group_free(*group);
return avahi_strerror(error);
}
return NULL;
}
const char *updateAvahiGroup(AvahiThreadedPoll *threaded_poll, AvahiEntryGroup *group,
const char *service_name, AvahiStringList *txt) {
int error = avahi_entry_group_update_service_txt_strlst(group, AVAHI_IF_UNSPEC,
AVAHI_PROTO_UNSPEC, 0, service_name, SERVICE_TYPE, NULL, txt);
if (AVAHI_OK != error) {
return avahi_strerror(error);
}
return NULL;
}
const char *removeAvahiGroup(AvahiThreadedPoll *threaded_poll, AvahiEntryGroup *group) {
int error = avahi_entry_group_free(group);
if (AVAHI_OK != error) {
return avahi_strerror(error);
}
return NULL;
}
void stopAvahiClient(AvahiThreadedPoll *threaded_poll, AvahiClient *client) {
avahi_threaded_poll_stop(threaded_poll);
avahi_client_free(client);
avahi_threaded_poll_free(threaded_poll);
}
|