remote Plugin umo¿liwia zdalne sterowanie programem gg2. remote nas³uchuje na gnie¼dzie lokalnym na datagramy. Akceptuje tylko datagramy, które przenosz± ze sob± tzw. credentials. S³u¿± one do identyfikacji klienta. Obs³ugiwane komendy: |======================================================================| | komenda | dzia³anie | |======================================================================| | gui show | pokazuje/ukrywa okienko GUI | |----------------------------------------------------------------------| | gui warn <tekst> | wy¶wietla okienko GUI z ostrze¿eniem | | | zawartym w <tekst> | |----------------------------------------------------------------------| | gui msg <tekst> | wy¶wietla okienko GUI z wiadomo¶i± | | | zawart± w <tekst> | |----------------------------------------------------------------------| | gui notify <tekst> | wy¶wietla okienko GUI z powiadomieniem | | | zawartym w <tekst> | |----------------------------------------------------------------------| | quit | koñczy dzia³anie programu gg2 | |----------------------------------------------------------------------| | xosd show <tekst> | wy¶wietla <tekst> za pomoc± xosd | |----------------------------------------------------------------------| | remote get_icon | ¿±da podania nazwy tematu i nazwy pliku, | | | w którym znajduje siê pixmapa okre¶laj±ca | | | aktualn± ikonkê dockletu. Je¶li temat to | | | bubble a plik online.png, to zwracane jest | | | "ok bubble/online.png" lub | | | "err <wyja¶nienie>", je¶li wyst±pi³ b³±d | | | uniemo¿liwiaj±cy zwrócenie danych. | |----------------------------------------------------------------------| | remote_get_icon_path | tak jak w "remote get_icon", z t± ró¿nic±, ¿e | | | zwracana jest pe³na ¶cie¿ka do pliku z pixmap±| |----------------------------------------------------------------------| Przyk³adowy klient, który wysy³a komendy z linii poleceñ: --cut-here-- #include <pwd.h> #include <sys/un.h> #include <sys/types.h> #include <sys/socket.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <unistd.h> #include <stdlib.h> const char *pth_unix = ".gg2_remote"; char *sock_path; int sck = -1; struct sockaddr_un sun; void client_init (void) { struct passwd *pw; pw = getpwuid (getuid ()); if (pw == NULL) return; /* tu by sie przydalo sprawdzanie poprawnosci pw->pw_dir */ sock_path = malloc (strlen (pw->pw_dir) + 1 + strlen (pth_unix) + 1); if (!sock_path) abort (); strcpy (sock_path, pw->pw_dir); strcpy (sock_path + strlen (pw->pw_dir) + 1, pth_unix); sock_path[strlen (pw->pw_dir)] = '/'; sck = socket (PF_UNIX, SOCK_DGRAM, 0); if (sck == -1) goto abort; sun.sun_family = AF_UNIX; bzero (&sun.sun_path, sizeof (sun.sun_path)); strcpy (sun.sun_path, sock_path); return; abort: printf ("%s\n", strerror (errno)); if (sck != -1) { close (sck); sck = -1; } return; } int wyslij (char *text) { struct msghdr msg; struct cmsghdr *cmsg; int text_len = strlen (text) + 1; char buf[CMSG_SPACE (sizeof (struct ucred))]; struct ucred *pcred; struct iovec iov; msg.msg_control = buf; msg.msg_controllen = sizeof (buf); cmsg = CMSG_FIRSTHDR (&msg); cmsg->cmsg_level = SOL_SOCKET; cmsg->cmsg_type = SCM_CREDENTIALS; cmsg->cmsg_len = CMSG_LEN (sizeof (struct ucred)); pcred = (struct ucred *) CMSG_DATA (cmsg); pcred->pid = getpid (); pcred->uid = getuid (); pcred->gid = getgid (); msg.msg_name = &sun; msg.msg_namelen = sizeof (sun); iov.iov_base = text; iov.iov_len = text_len; msg.msg_iov = &iov; msg.msg_iovlen = 1; return sendmsg (sck, &msg, 0); } int main (int argc, char *argv[]) { char buf[512]; client_init (); if (sck == -1) return -1; if (argc < 2) return 0; printf ("%s -> %d\n", argv[1], wyslij (argv[1])); printf ("%s\n", strerror (errno)); close (sck); free (sock_path); return 0; } --cut-here-- $Id: README.remote,v 1.1.1.1 2003/03/20 10:37:01 krzyzak Exp $