send_billing_record.c 1.9 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 "billdb.h"
  24. #include "../common/common_defs.h"
  25. #include "../commhub/commhub.h"
  26. int main(int argc, char **argv)
  27. {
  28. int fd;
  29. char foo[BILLING_LINE_SIZE];
  30. char *bar;
  31. struct message_record msg;
  32. int retval, i;
  33. fd = connect_to_message_server(argv[0]);
  34. if(fd < 0)
  35. {
  36. fprintf(stderr,"Cannot connect to IPC server!\n");
  37. exit(1);
  38. }
  39. while(!feof(stdin))
  40. {
  41. bar = fgets(foo, sizeof(foo), stdin);
  42. if(bar == NULL)
  43. break;
  44. for(i = 0; i < BILLING_LINE_SIZE; i++)
  45. {
  46. if(foo[i] == '\0')
  47. break;
  48. if( (foo[i] == '\r') ||(foo[i] == '\n') )
  49. {
  50. foo[i] = '\0';
  51. break;
  52. }
  53. }
  54. prepare_message(&msg, MAILBOX_BILLING_LOG, foo, i);
  55. retval = send_message(fd, &msg);
  56. if(retval < 0)
  57. {
  58. fprintf(stderr, "Error attempting to send message!\n");
  59. exit(2);
  60. }
  61. }
  62. return 0;
  63. }