send_magstripe.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright (c) 2019 Clementine Computing LLC.
  3. *
  4. * This file is part of PopuFare.
  5. *
  6. * PopuFare is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * PopuFare is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <unistd.h>
  23. #include "common_defs.h"
  24. #include "commhub.h"
  25. int main(int argc, char **argv)
  26. {
  27. int fd;
  28. char foo[1024];
  29. char *bar;
  30. struct message_record msg;
  31. int retval, i;
  32. fd = connect_to_message_server(argv[0]);
  33. if(fd < 0)
  34. {
  35. fprintf(stderr,"Cannot connect to IPC server!\n");
  36. exit(1);
  37. }
  38. while(!feof(stdin))
  39. {
  40. bar = fgets(foo, sizeof(foo), stdin);
  41. if(bar == NULL)
  42. break;
  43. for(i = 0; i < 1024; i++)
  44. {
  45. if(foo[i] == '\0')
  46. break;
  47. if( (foo[i] == '\r') ||(foo[i] == '\n') )
  48. {
  49. foo[i] = '\0';
  50. break;
  51. }
  52. }
  53. prepare_message(&msg, MAILBOX_TOKEN_MAG, foo, i);
  54. retval = send_message(fd, &msg);
  55. if(retval < 0)
  56. {
  57. fprintf(stderr, "Error attempting to send message!\n");
  58. exit(2);
  59. }
  60. }
  61. return 0;
  62. }