plugins.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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;
  38. struct plugin *plugins[] = {
  39. &plg_hello,
  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 do_cmd_pins(char *s) {
  59. struct plugin *p;
  60. char name[MSG_SIZE];
  61. (void) s;
  62. fprintf(stderr, "plugin: ");
  63. scanf("%s", name);
  64. if (!(p = find_plg(name))) {
  65. fprintf(stderr, "*** plugin not found. \n");
  66. return 1;
  67. }
  68. p->state = PLG_INSERTED;
  69. return 0;
  70. }