plugins.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* vcc/plugins.c
  2. *
  3. * This file is part of vcc.
  4. *
  5. * vcc is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * vcc is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with vcc. If not, see <https://www.gnu.org/licenses/>
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <unistd.h>
  21. #include <fcntl.h>
  22. #include <errno.h>
  23. #include <string.h>
  24. #include <ctype.h>
  25. #include <sys/stat.h>
  26. #include <sys/types.h>
  27. #include <sys/socket.h>
  28. #include <netinet/in.h>
  29. #include <arpa/inet.h>
  30. #include <poll.h>
  31. #include <signal.h>
  32. #include <klist.h>
  33. #include <vcc/vcc.h>
  34. #include <vcc/plugin.h>
  35. #include <vcc/version.h>
  36. #include <vcc/pretty.h>
  37. extern struct plugin plg_hello, plg_robot;
  38. struct plugin *plugins[] = {
  39. &plg_hello, &plg_robot,
  40. (struct plugin *) NULL
  41. };
  42. int do_cmd_pls(char *s) {
  43. int i;
  44. struct plugin *p;
  45. (void) s;
  46. for (i = 0; (p = plugins[i]); i++)
  47. pretty_cmd_help(p->name, p->descr);
  48. return 0;
  49. }
  50. struct plugin *find_plg(char *s) {
  51. int i;
  52. struct plugin *p;
  53. for (i = 0; (p = plugins[i]); i++)
  54. if (!strcmp(s, p->name))
  55. return p;
  56. return NULL;
  57. }
  58. int plg_insert(struct plugin *plg) {
  59. plg->state = PLG_INSERTED;
  60. return 0;
  61. }
  62. int do_cmd_pins(char *s) {
  63. struct plugin *p;
  64. char name[MSG_SIZE];
  65. (void) s;
  66. fprintf(stderr, "plugin: ");
  67. scanf("%s", name);
  68. if (!(p = find_plg(name))) {
  69. fprintf(stderr, "*** plugin not found. \n");
  70. return 1;
  71. }
  72. return plg_insert(p);
  73. }