⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 Bluezan implementation of the Bluetooth&#8482 wireless standards specifications for Linux. The code
💻 C
字号:
/* * Copyright (C) 2002, 2003, 2004 Philip Blundell <philb@gnu.org> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. */#include <sys/types.h>#include <stdlib.h>#include <time.h>#include <stdio.h>#include <string.h>#include <unistd.h>#include <sys/stat.h>#include <libintl.h>#include <locale.h>#include <gtk/gtk.h>#include <dbus/dbus.h>#include <dbus/dbus-glib.h>#include <dbus/dbus-glib-lowlevel.h>#include "pin-ui.h"#define OLD_SERVICE_NAME   "org.handhelds.gpe.bluez"#define OLD_INTERFACE_NAME OLD_SERVICE_NAME ".PinAgent"#define NEW_SERVICE_NAME   "org.bluez.PinAgent"#define NEW_INTERFACE_NAME NEW_SERVICE_NAME#define _(x) gettext(x)extern DBusHandlerResult bluez_pin_handle_dbus_request (DBusConnection *connection, DBusMessage *message);DBusHandlerResulthandler_func (DBusConnection     *connection,	      DBusMessage        *message,	      void               *user_data){  if (dbus_message_is_method_call (message, NEW_INTERFACE_NAME, "PinRequest"))    return bluez_pin_handle_dbus_request (connection, message);    if (dbus_message_is_method_call (message, OLD_INTERFACE_NAME, "PinRequest"))    return bluez_pin_handle_dbus_request (connection, message);  if (dbus_message_is_signal (message,                              DBUS_INTERFACE_ORG_FREEDESKTOP_LOCAL,                              "Disconnected"))    exit (0);    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;}static DBusObjectPathVTable dbus_vtable = {  NULL,  handler_func,  NULL};voidbluez_pin_dbus_server_run (void){  DBusConnection *connection;  DBusError error;  static const char *old_object_path = "/org/handhelds/gpe/bluez/PinAgent";  static const char *new_object_path = "/org/bluez/PinAgent";   int errors = 0;  dbus_error_init (&error);  connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);  if (connection == NULL)    {      fprintf (stderr, "Failed to open connection to system message bus: %s\n",               error.message);      dbus_error_free (&error);      exit (1);    }  dbus_connection_setup_with_g_main (connection, NULL);  dbus_connection_register_object_path (connection, new_object_path, &dbus_vtable, NULL);  dbus_connection_register_object_path (connection, old_object_path, &dbus_vtable, NULL);  dbus_bus_acquire_service (connection, NEW_SERVICE_NAME, 0, &error);  if (dbus_error_is_set (&error))    {      fprintf (stderr, "Failed to acquire %s service: %s\n", NEW_SERVICE_NAME, error.message);      dbus_error_free (&error);      errors++;    }  dbus_bus_acquire_service (connection, OLD_SERVICE_NAME, 0, &error);  if (dbus_error_is_set (&error))    {      fprintf (stderr, "Failed to acquire %s service: %s\n", OLD_SERVICE_NAME, error.message);      dbus_error_free (&error);      errors++;    }  if (errors == 2)	/* Both services unavailable? */    exit (1);}voidlegacy_pin_result (BluetoothPinRequest *req, gchar *result){  if (result)    printf ("PIN:%s\n", result);  else    printf ("ERR\n");  gtk_main_quit ();}voidlegacy_pin_request (gboolean outgoing, gchar *address, gchar *name){  BluetoothPinRequest *req;  req = bluetooth_pin_request_new (outgoing, address, name);  g_signal_connect (G_OBJECT (req), "result", G_CALLBACK (legacy_pin_result), NULL);}voidusage (char *argv[]){  fprintf (stderr, _("Usage: %s <in|out> <address> [name]\n"), argv[0]);  fprintf (stderr, _(" or    %s --dbus\n"), argv[0]);  exit (1);}int main (int argc, char *argv[]){  char *dpy;  gboolean dbus_mode = FALSE;  gchar *address, *name = NULL;  dpy = getenv ("DISPLAY");  setlocale (LC_ALL, "");  bindtextdomain (PACKAGE, PACKAGE_LOCALE_DIR);  textdomain (PACKAGE);  if (argc > 1 && !strcmp (argv[1], "--dbus"))    dbus_mode = TRUE;  if (dbus_mode == FALSE && dpy == NULL)    {      char *auth = NULL;      FILE *fp;      dpy = ":0";      fp = popen ("/bin/ps --format args --no-headers -C X -C XFree86", "r");      if (fp)	{	  char buf[1024];	  while (fgets (buf, sizeof (buf), fp))	    {	      char *p = strtok (buf, " ");	      int authf = 0;	      while (p)		{		  if (authf)		    {		      auth = strdup (p);		      authf = 0;		    }		  else if (p[0] == ':')		    dpy = strdup (p);		  else if (!strcmp (p, "-auth"))		    authf = 1;		  p = strtok (NULL, " ");		}	    }	  pclose (fp);	}      setenv ("DISPLAY", dpy, 0);      if (auth)	setenv ("XAUTHORITY", auth, 0);    }  gtk_set_locale ();  gtk_init (&argc, &argv);  if (dbus_mode)    {      bluez_pin_dbus_server_run ();      gtk_main ();    }  else    {      gboolean outgoing = FALSE;      if (argc < 3)	usage (argv);      if (strcmp (argv[1], "in") == 0)	outgoing = FALSE;      else if (strcmp (argv[1], "out") == 0)	outgoing = TRUE;      else	usage (argv);      address = argv[2];      if (argc == 4)	name = argv[3];      legacy_pin_request (outgoing, address, name);      gtk_main ();    }  exit (0);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -