util.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Misc utilities
  3. *
  4. * (c) Adrian Smith 2012-2014, triode1@btinternet.com
  5. * (c) Philippe 2016-2017, philippe_44@outlook.com
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #ifndef __UTIL_H
  22. #define __UTIL_H
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <stdio.h>
  26. #include "platform.h"
  27. #include "pthread.h"
  28. #define NFREE(p) if (p) { free(p); p = NULL; }
  29. typedef struct metadata_s {
  30. char *artist;
  31. char *album;
  32. char *title;
  33. char *genre;
  34. char *path;
  35. char *artwork;
  36. char *remote_title;
  37. u32_t track;
  38. u32_t duration;
  39. u32_t track_hash;
  40. u32_t sample_rate;
  41. u8_t sample_size;
  42. u8_t channels;
  43. } metadata_t;
  44. void free_metadata(struct metadata_s *metadata);
  45. void dup_metadata(struct metadata_s *dst, struct metadata_s *src);
  46. u32_t gettime_ms(void);
  47. #ifdef WIN32
  48. char* strsep(char** stringp, const char* delim);
  49. char *strndup(const char *s, size_t n);
  50. int asprintf(char **strp, const char *fmt, ...);
  51. void winsock_init(void);
  52. void winsock_close(void);
  53. #else
  54. char *strlwr(char *str);
  55. #endif
  56. char* strextract(char *s1, char *beg, char *end);
  57. in_addr_t get_localhost(char **name);
  58. void get_mac(u8_t mac[]);
  59. int shutdown_socket(int sd);
  60. int bind_socket(short unsigned *port, int mode);
  61. int conn_socket(unsigned short port); typedef struct {
  62. char *key;
  63. char *data;
  64. } key_data_t;
  65. bool http_parse(int sock, char *method, key_data_t *rkd, char **body, int *len); char* http_send(int sock, char *method, key_data_t *rkd);
  66. char* kd_lookup(key_data_t *kd, char *key);
  67. bool kd_add(key_data_t *kd, char *key, char *value);
  68. char* kd_dump(key_data_t *kd);
  69. void kd_free(key_data_t *kd);
  70. int _fprintf(FILE *file, ...);
  71. #endif