Exemple #1
0
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;
}
JNIEXPORT jint JNICALL Java_avahi4j_EntryGroup_update_1service_1txt_1records
			(JNIEnv *e, jobject t, jlong ptr, jint interfaceNum, jint proto,
					jstring name, jstring type, jstring domain, jarray txtRecord,
					jint length){
	dprint("[LOG] Entering %s\n", __PRETTY_FUNCTION__);

	struct avahi4j_entry_group *group = (struct avahi4j_entry_group *) (uintptr_t) ptr;

	AvahiIfIndex avahi_if;
	AvahiProtocol avahi_proto;
	const char *avahi_name=NULL, *avahi_type=NULL, *avahi_domain=NULL;
	AvahiStringList *list = NULL;
	jstring current;
	const char* record;
	int result, i;

	// translate the Protocol Enum and interface index
	GET_AVAHI_PROTO(avahi_proto, proto);
	GET_AVAHI_IF_IDX(avahi_if, interfaceNum);

	// go through the list of TXT  record and add them to the AvahiStringList
	for(i=0; i<length; i++) {
		current = (jstring) (*e)->GetObjectArrayElement(e, txtRecord, i);
		if(current==NULL)
		{
			dprint("error getting txt record %d\n",i);
			THROW_EXCEPTION(e, JNI_EXCP, "error getting record %d",i);
			return 0;
		}

		GET_UTF_STR(record, current, e, 0);
		dprint("Adding '%s' to TXT record\n", record);
		list = avahi_string_list_add(list, record);
		PUT_UTF_STR(record, current, e);
	}

	// get UTF string from name, type, domain (can be NULL)
	GET_UTF_STR_JUMP(avahi_name, name, e, bail);
	GET_UTF_STR_JUMP(avahi_type, type,e ,bail);
	GET_UTF_STR_JUMP(avahi_domain, domain, e, bail);

	result = avahi_entry_group_update_service_txt_strlst(group->group, avahi_if,
			avahi_proto, 0, avahi_name, avahi_type, avahi_domain, list);

bail:
	// free UTF string
	PUT_UTF_STR(avahi_name, name, e);
	PUT_UTF_STR(avahi_type, type,e);
	PUT_UTF_STR(avahi_domain, domain, e);

	// free string list
	avahi_string_list_free(list);

	CHECK_N_RET(avahi_entry_group_update_service_txt_strlst, result);
}
Exemple #3
0
bool CZeroconfAvahi::doForceReAnnounceService(const std::string& fcr_identifier)
{
  bool ret = false;
  ScopedEventLoopBlock l_block(mp_poll);
  tServiceMap::iterator it = m_services.find(fcr_identifier);
  if (it != m_services.end() && it->second->mp_group)
  {
    // to force a reannounce on avahi its enough to reverse the txtrecord list
    it->second->mp_txt = avahi_string_list_reverse(it->second->mp_txt);

    // this will trigger the reannouncement
    if ((avahi_entry_group_update_service_txt_strlst(it->second->mp_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, AvahiPublishFlags(0),
                                              it->second->m_name.c_str(),
                                              it->second->m_type.c_str(), NULL, it->second->mp_txt)) >= 0)
      ret = true;
  }

  return ret;
}
void
Avahi::PresencePublisher::publish (G_GNUC_UNUSED const Ekiga::PersonalDetails& details_)
{
  if (group != NULL) {

    Ekiga::CallManager::InterfaceList interfaces;
    AvahiStringList* txt_record = NULL;
    int ret;

    txt_record = prepare_txt_record ();
    for (Ekiga::CallCore::const_iterator iter = call_core.begin ();
	 iter != call_core.end ();
	 ++iter) {

      Ekiga::CallManager::InterfaceList ints = (*iter)->get_interfaces ();
      interfaces.insert (interfaces.begin (), ints.begin (), ints.end ());

    }

    for (Ekiga::CallManager::InterfaceList::const_iterator iter = interfaces.begin ();
	 iter != interfaces.end ();
	 ++iter) {

      gchar *typ = NULL;

      typ = g_strdup_printf ("_%s._%s",
			     iter->voip_protocol.c_str (),
			     iter->protocol.c_str ());

      /* FIXME: no collision checking here */
      ret =
	avahi_entry_group_update_service_txt_strlst (group, AVAHI_IF_UNSPEC,
						     AVAHI_PROTO_UNSPEC,
						     (AvahiPublishFlags)0,
						     name, typ, NULL,
						     txt_record);

      g_free (typ);
    }

    avahi_string_list_free (txt_record);
  }
}
Exemple #5
0
int avahi_entry_group_update_service_txt(
    AvahiEntryGroup *group,
    AvahiIfIndex interface,
    AvahiProtocol protocol,
    AvahiPublishFlags flags,
    const char *name,
    const char *type,
    const char *domain,
    ...) {

    va_list va;
    int r;
    AvahiStringList *txt;

    va_start(va, domain);
    txt = avahi_string_list_new_va(va);
    r = avahi_entry_group_update_service_txt_strlst(group, interface, protocol, flags, name, type, domain, txt);
    avahi_string_list_free(txt);
    va_end(va);
    return r;
}
Exemple #6
0
static void
epc_service_publish_details (EpcService *self)
{
  gint result;

  if (EPC_DEBUG_LEVEL (1))
    g_debug ("%s: Publishing details for `%s'...",
             G_STRLOC, self->dispatcher->priv->name);

  result = avahi_entry_group_update_service_txt_strlst (self->group,
                                                        AVAHI_IF_UNSPEC, self->protocol, 0,
                                                        self->dispatcher->priv->name,
                                                        self->type, self->domain,
                                                        self->details);

  if (AVAHI_OK != result)
    g_warning ("%s: Failed publish details for `%s': %s (%d)",
               G_STRLOC, self->dispatcher->priv->name,
               avahi_strerror (result), result);

  epc_service_schedule_commit (self);
}
Exemple #7
0
gboolean _mdns_publish(BonjourDnsSd *data, PublishType type, GSList *records) {
	int publish_result = 0;
	AvahiSessionImplData *idata = data->mdns_impl_data;
	AvahiStringList *lst = NULL;

	g_return_val_if_fail(idata != NULL, FALSE);

	if (!idata->group) {
		idata->group = avahi_entry_group_new(idata->client,
						     _entry_group_cb, idata);
		if (!idata->group) {
			purple_debug_error("bonjour",
				"Unable to initialize the data for the mDNS (%s).\n",
				avahi_strerror(avahi_client_errno(idata->client)));
			return FALSE;
		}
	}

	while (records) {
		PurpleKeyValuePair *kvp = records->data;
		lst = avahi_string_list_add_pair(lst, kvp->key, kvp->value);
		records = records->next;
	}

	/* Publish the service */
	switch (type) {
		case PUBLISH_START:
			publish_result = avahi_entry_group_add_service_strlst(
				idata->group, AVAHI_IF_UNSPEC,
				AVAHI_PROTO_UNSPEC, 0,
				purple_account_get_username(data->account),
				ICHAT_SERVICE, NULL, NULL, data->port_p2pj, lst);
			break;
		case PUBLISH_UPDATE:
			publish_result = avahi_entry_group_update_service_txt_strlst(
				idata->group, AVAHI_IF_UNSPEC,
				AVAHI_PROTO_UNSPEC, 0,
				purple_account_get_username(data->account),
				ICHAT_SERVICE, NULL, lst);
			break;
	}

	/* Free the memory used by temp data */
	avahi_string_list_free(lst);

	if (publish_result < 0) {
		purple_debug_error("bonjour",
			"Failed to add the " ICHAT_SERVICE " service. Error: %s\n",
			avahi_strerror(publish_result));
		return FALSE;
	}

	if (type == PUBLISH_START
			&& (publish_result = avahi_entry_group_commit(idata->group)) < 0) {
		purple_debug_error("bonjour",
			"Failed to commit " ICHAT_SERVICE " service. Error: %s\n",
			avahi_strerror(publish_result));
		return FALSE;
	}

	return TRUE;
}
Exemple #8
0
int old_main(int argc, char *argv[]) {
    struct zc_published_service service = {
            .client = NULL,
            .entry_group = NULL,
            .config = NULL
    };
    char *zcp_argv[] = {"avahi-publish", "-s", "myservice", "_rtp._tcp",  "12345", "Here it is"};
    zc_publish_main(&service, 6, zcp_argv);

    struct zc_queue *queue = create_queue_pointer();
    char *zcb_argv[] = {"avahi-browse", "-a", "-p", "-r", "-t", "-v"};
    zc_browse_main(queue, 6, zcb_argv);

    struct zc_queue_elem *cursor = NULL;
    struct zc_element *zc_elem = NULL;
    char *t= NULL;
    cursor = queue_pop_front(queue);
    while (cursor != NULL){
        zc_elem = (struct zc_element *)cursor;
        t = avahi_string_list_to_string(zc_elem->txt_options);
        fprintf(stdout, "Elem : %s:%d %s %s %s %s \n", zc_elem->address, zc_elem->port, zc_elem->ifname, zc_elem->hostname, zc_elem->type, t);
        cursor = queue_pop_front(queue);
    }

    if (!service.entry_group) {
        if (!(service.entry_group = avahi_entry_group_new(*(service.config->client), zcp_entry_group_callback, service.config))) {
            fprintf(stdout, ("Failed to create entry group: %s\n"), avahi_strerror(avahi_client_errno(*(service.config->client))));
            return -1;
        }else{
            fprintf(stdout, ("OK to create entry group: \n"));
        }
    }

    //assert(avahi_entry_group_is_empty(service.entry_group));

    fprintf(stderr, ("Name %s: \n"), service.config->name);
//
    service.config->txt = avahi_string_list_add(NULL, "plop=ok");
    avahi_entry_group_update_service_txt_strlst(service.entry_group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, 0, service.config->name, service.config->stype, service.config->domain, service.config->txt);

    //sleep(1);
    char *zcb_argv2[] = {"avahi-browse", "-a", "-p", "-r", "-t", "-v"};
    zc_browse_main(queue, 6, zcb_argv2);

    cursor = queue_pop_front(queue);
    while (cursor != NULL){
        zc_elem = (struct zc_element *)cursor;
        t = avahi_string_list_to_string(zc_elem->txt_options);
        fprintf(stdout, "Elem : %s:%d %s %s %s \n", zc_elem->address, zc_elem->port, zc_elem->hostname, zc_elem->type, t);
        cursor = queue_pop_front(queue);
    }

//    sleep(2);
//    char *zcp_argv3[] = {"avahi-publish", "-s", "myservice", "_http._tcp",  "12345", "Here it is 2 le retour"};
//    zc_publish_main(&client, &simple_poll, &service2, 6, zcp_argv3);
//
//    char *zcb_argv2[] = {"avahi-browse", "-a", "-p", "-r", "-t", "-v"};
//    sleep(5);
//    zc_browse_main(queue, 6, zcb_argv2);

    queue_delete_queue_pointer(queue);

    if (service.client){
        fprintf(stderr, "Clean up client \n");
        avahi_client_free(service.client);
    }
    if(service.config->simple_poll){
        fprintf(stderr, "Clean up poll \n");
        avahi_simple_poll_free(service.config->simple_poll);
    }
    if(service.config){
        fprintf(stderr, "Clean up config \n");
        free(service.config);
    }
    return 0;
}