transport.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * OBEX Server
  5. *
  6. * Copyright (C) 2012 Intel Corporation
  7. *
  8. *
  9. */
  10. #ifdef HAVE_CONFIG_H
  11. #include <config.h>
  12. #endif
  13. #define _GNU_SOURCE
  14. #include <string.h>
  15. #include <errno.h>
  16. #include <glib.h>
  17. #include <inttypes.h>
  18. #include "obexd/src/log.h"
  19. #include "transport.h"
  20. static GSList *transports = NULL;
  21. struct obc_transport *obc_transport_find(const char *name)
  22. {
  23. GSList *l;
  24. for (l = transports; l; l = l->next) {
  25. struct obc_transport *transport = l->data;
  26. if (strcasecmp(name, transport->name) == 0)
  27. return transport;
  28. }
  29. return NULL;
  30. }
  31. int obc_transport_register(struct obc_transport *transport)
  32. {
  33. if (!transport) {
  34. error("Invalid transport");
  35. return -EINVAL;
  36. }
  37. if (obc_transport_find(transport->name)) {
  38. error("Permission denied: transport %s already registered",
  39. transport->name);
  40. return -EPERM;
  41. }
  42. DBG("transport %p name %s registered", transport, transport->name);
  43. transports = g_slist_append(transports, transport);
  44. return 0;
  45. }
  46. void obc_transport_unregister(struct obc_transport *transport)
  47. {
  48. if (!g_slist_find(transports, transport)) {
  49. error("Unable to unregister: No such transport %p", transport);
  50. return;
  51. }
  52. DBG("transport %p name %s unregistered", transport, transport->name);
  53. transports = g_slist_remove(transports, transport);
  54. }