dvbsec_test.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * dvbsec testing.
  3. *
  4. * Copyright (c) 2005 by Andrew de Quincey <adq_dvb@lidskialf.net>
  5. *
  6. * This library is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as
  8. * published by the Free Software Foundation; either version 2.1 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program 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 Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <libdvbsec/dvbsec_cfg.h>
  24. void syntax(void);
  25. struct dvbsec_config *secconfigs = NULL;
  26. int seccount = 0;
  27. int secload_callback(void *private, struct dvbsec_config *sec);
  28. int main(int argc, char *argv[])
  29. {
  30. if (argc != 4) {
  31. syntax();
  32. }
  33. if (!strcmp(argv[1], "-sec")) {
  34. FILE *f = fopen(argv[2], "r");
  35. if (!f) {
  36. fprintf(stderr, "Unable to load %s\n", argv[2]);
  37. exit(1);
  38. }
  39. dvbsec_cfg_load(f, NULL, secload_callback);
  40. fclose(f);
  41. f = fopen(argv[3], "w");
  42. if (!f) {
  43. fprintf(stderr, "Unable to write %s\n", argv[3]);
  44. exit(1);
  45. }
  46. dvbsec_cfg_save(f, secconfigs, seccount);
  47. fclose(f);
  48. } else {
  49. syntax();
  50. }
  51. exit(0);
  52. }
  53. int secload_callback(void *private, struct dvbsec_config *sec)
  54. {
  55. (void) private;
  56. struct dvbsec_config *tmp = realloc(secconfigs, (seccount+1) * sizeof(struct dvbsec_config));
  57. if (tmp == NULL) {
  58. fprintf(stderr, "Out of memory\n");
  59. exit(1);
  60. }
  61. secconfigs = tmp;
  62. memcpy(&secconfigs[seccount++], sec, sizeof(struct dvbsec_config));
  63. return 0;
  64. }
  65. void syntax()
  66. {
  67. fprintf(stderr,
  68. "Syntax: dvbcfg_test <-zapchannel|-sec> <input filename> <output filename>\n");
  69. exit(1);
  70. }