A fast, lightweight and simple STOMP compatible messaging server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (C) 2011 Bernhard Froehlich <decke@bluelife.at>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Author's name may not be used endorse or promote products derived
  12. * from this software without specific prior written permission.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  18. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  20. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  22. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  23. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  24. * POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include "util.h"
  30. struct configparam
  31. {
  32. char key[CONFIGMAXKEY];
  33. char value[CONFIGMAXVALUE];
  34. };
  35. struct configparam config[] = {
  36. { "authUser", "" },
  37. { "authPass", "" },
  38. { "dbFile", "/tmp/redqueue.db" },
  39. { "listenIP", "127.0.0.1" },
  40. { "listenPort", "8080" },
  41. { "logFile", "/var/log/redqd.log" },
  42. { "", "" }
  43. };
  44. int configparse(char *filename)
  45. {
  46. char *value;
  47. char line[255];
  48. FILE *file = fopen(filename, "r");
  49. if(file == NULL)
  50. return 1;
  51. while(fgets(line, sizeof(line), file) != NULL)
  52. {
  53. if(line[0] == '#')
  54. continue;
  55. line[strlen(line)-1] = '\0';
  56. if((value = strstr(line, " ")) != NULL || (value = strstr(line, "\t")) != NULL)
  57. {
  58. *value = '\0';
  59. value++;
  60. while(*value == ' ' || *value == '\t')
  61. value++;
  62. if(strlen(line) == 0 || strlen(value) == 0)
  63. continue;
  64. if(configset(line, value) != 0)
  65. return 1;
  66. }
  67. }
  68. fclose(file);
  69. return 0;
  70. }
  71. char* configget(char *key)
  72. {
  73. int i;
  74. for(i=0; config[i].key[0] != '\0'; i++)
  75. {
  76. if(strcmp(key, config[i].key) == 0)
  77. {
  78. return config[i].value;
  79. }
  80. }
  81. return NULL;
  82. }
  83. int configset(char *key, char *value)
  84. {
  85. int i;
  86. for(i=0; config[i].key[0] != '\0'; i++)
  87. {
  88. if(strcmp(key, config[i].key) == 0)
  89. {
  90. strncpy(config[i].value, value, sizeof(config[i].value)-1);
  91. config[i].value[sizeof(config[i].value)-1] = '\0';
  92. return 0;
  93. }
  94. }
  95. printf("configset: Unknown config param <%s>\n", key);
  96. return 1;
  97. }