[5605] | 1 | //protocol-echo.c: |
---|
[5193] | 2 | |
---|
| 3 | /* |
---|
[5381] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2011-2012 |
---|
[5193] | 5 | * |
---|
| 6 | * This file is part of roard a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * RoarAudio is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
| 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
| 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
[5579] | 26 | #include <roaraudio.h> |
---|
[5193] | 27 | |
---|
[5606] | 28 | static int _handle(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara) { |
---|
[5193] | 29 | struct roar_buffer * buf; |
---|
| 30 | void * data; |
---|
| 31 | ssize_t len; |
---|
| 32 | |
---|
[5606] | 33 | (void)client, (void)userdata, (void)protopara, (void)protoparalen, (void)pluginpara; |
---|
[5579] | 34 | |
---|
| 35 | ROAR_DBG("_handle(client=%i, vio=%p) = ?", client, vio); |
---|
[5193] | 36 | |
---|
| 37 | if ( roar_buffer_new_data(&buf, 1024, &data) == -1 ) |
---|
| 38 | return -1; |
---|
| 39 | |
---|
| 40 | len = roar_vio_read(vio, data, 1024); |
---|
| 41 | if ( len < 1 ) { |
---|
[5579] | 42 | ROAR_DBG("_handle(client=%i, vio=%p) = -1 // error=%s(%i)", client, vio, roar_errorstring, roar_error); |
---|
[5193] | 43 | return -1; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | if ( roar_buffer_set_len(buf, len) == -1 ) { |
---|
[5579] | 47 | ROAR_DBG("_handle(client=%i, vio=%p) = -1 // error=%s(%i)", client, vio, roar_errorstring, roar_error); |
---|
[5193] | 48 | roar_buffer_free(buf); |
---|
| 49 | return -1; |
---|
| 50 | } |
---|
| 51 | |
---|
[5603] | 52 | if ( roar_buffer_moveintoqueue(obuffer, &buf) == -1 ) |
---|
| 53 | return -1; |
---|
[5193] | 54 | |
---|
[5579] | 55 | ROAR_DBG("_handle(client=%i, vio=%p) = 0", client, vio); |
---|
[5193] | 56 | return 0; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | |
---|
[5579] | 60 | static const struct roar_dl_proto proto = { |
---|
| 61 | .proto = ROAR_PROTO_ECHO, |
---|
| 62 | .description = "Send all data send to the server back to the client", |
---|
| 63 | .flags = ROAR_DL_PROTO_FLAGS_NONE, |
---|
| 64 | .set_proto = NULL, |
---|
| 65 | .unset_proto = NULL, |
---|
| 66 | .handle = _handle, |
---|
| 67 | .flush = NULL, |
---|
| 68 | .flushed = NULL, |
---|
| 69 | .status = NULL |
---|
[5193] | 70 | }; |
---|
| 71 | |
---|
[5579] | 72 | static int __reg_proto(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib) { |
---|
| 73 | (void)para, (void)lib; |
---|
| 74 | ROAR_DL_PLUGIN_REG_FN(ROAR_DL_PROTO_SUBTYPE, proto, ROAR_DL_PROTO_VERSION); |
---|
| 75 | return 0; |
---|
| 76 | } |
---|
[5193] | 77 | |
---|
[5434] | 78 | ROAR_DL_PLUGIN_START(protocol_echo) { |
---|
| 79 | ROAR_DL_PLUGIN_META_PRODUCT_NIV("protocol-echo", ROAR_VID_ROARAUDIO, ROAR_VNAME_ROARAUDIO); |
---|
[5340] | 80 | ROAR_DL_PLUGIN_META_VERSION(ROAR_VERSION_STRING); |
---|
| 81 | ROAR_DL_PLUGIN_META_LICENSE_TAG(GPLv3_0); |
---|
| 82 | ROAR_DL_PLUGIN_META_CONTACT_FLNE("Philipp", "Schafft", "ph3-der-loewe", "lion@lion.leolix.org"); |
---|
| 83 | ROAR_DL_PLUGIN_META_DESC("Implementation of a dummy protocol sending all data back to the sender"); |
---|
[5275] | 84 | |
---|
[5579] | 85 | ROAR_DL_PLUGIN_REG(ROAR_DL_FN_PROTO, __reg_proto); |
---|
[5193] | 86 | } ROAR_DL_PLUGIN_END |
---|
| 87 | |
---|
| 88 | //ll |
---|