From 7e745c98e62c6a29ee0c35479b6d0714a150f9f7 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Fri, 14 Mar 2025 21:22:48 +0100 Subject: [PATCH] aqhome, aqhome-apps: cleanup, removed unneeded files. --- apps/aqhome-mqttlog/s_publish.c | 79 +- apps/aqhome-mqttlog/s_setdata.c | 5 +- apps/aqhome-mqttlog/server.c | 21 +- apps/aqhome-mqttlog/xmlread.c | 2 +- apps/aqhome-nodes/db.c | 32 +- apps/aqhome-nodes/main.c | 4 +- apps/aqhome-nodes/server.c | 8 +- apps/aqhome-react/main.c | 2 +- apps/aqhome-react/server.c | 2 +- aqhome-mqtt.devices.old | 184 +++ aqhome-react.sh | 3 +- aqhome-react.vars | 0 aqhome/0BUILD | 8 - aqhome/client/0BUILD | 78 - aqhome/client/connection.c | 175 --- aqhome/client/connection.h | 28 - aqhome/data/vars_dbread.c | 2 - aqhome/events/0BUILD | 87 -- aqhome/events/eventhandler.c | 138 -- aqhome/events/eventhandler.h | 46 - aqhome/events/eventhandler_p.h | 30 - aqhome/events/eventsubscription.c | 93 -- aqhome/events/eventsubscription.h | 41 - aqhome/events/eventsubscription_p.h | 31 - aqhome/events/eventtimer.c | 194 --- aqhome/events/eventtimer.h | 65 - aqhome/events/eventtimer_p.h | 34 - aqhome/http/0BUILD | 95 -- aqhome/http/content.c | 117 -- aqhome/http/content.h | 63 - aqhome/http/content_files.c | 143 -- aqhome/http/content_files.h | 34 - aqhome/http/content_files_p.h | 29 - aqhome/http/content_p.h | 29 - aqhome/http/endpoint_http.c | 661 --------- aqhome/http/endpoint_http.h | 28 - aqhome/http/endpoint_http_p.h | 53 - aqhome/http/httprequest.c | 730 ---------- aqhome/http/httprequest.h | 85 -- aqhome/http/httprequest_p.h | 62 - aqhome/http/httpservice.c | 259 ---- aqhome/http/httpservice.h | 57 - aqhome/http/httpservice_conf.c | 1271 ----------------- aqhome/http/httpservice_conf.h | 60 - aqhome/http/httpservice_http.c | 412 ------ aqhome/http/httpservice_http.h | 64 - aqhome/http/httpservice_login.c | 45 - aqhome/http/httpservice_login.h | 30 - aqhome/http/httpservice_p.h | 44 - aqhome/http/urlhandler.c | 261 ---- aqhome/http/urlhandler.h | 70 - aqhome/http/urlhandler_p.h | 34 - aqhome/ipc/0BUILD | 94 -- aqhome/ipc/data/0BUILD | 90 -- aqhome/ipc/data/cmd_data.c | 44 - aqhome/ipc/data/cmd_data_getdata.c | 110 -- aqhome/ipc/data/ipc_data.c | 502 ------- aqhome/ipc/data/ipc_data.h | 72 - aqhome/ipc/data/msg_data_connect.c | 91 -- aqhome/ipc/data/msg_data_connect.h | 53 - aqhome/ipc/data/msg_data_datapoints.c | 175 --- aqhome/ipc/data/msg_data_datapoints.h | 56 - aqhome/ipc/data/msg_data_devices.c | 153 -- aqhome/ipc/data/msg_data_devices.h | 54 - aqhome/ipc/data/msg_data_getdata.c | 88 -- aqhome/ipc/data/msg_data_getdata.h | 48 - aqhome/ipc/data/msg_data_multidata.c | 160 --- aqhome/ipc/data/msg_data_multidata.h | 48 - aqhome/ipc/data/msg_data_set.c | 107 -- aqhome/ipc/data/msg_data_set.h | 40 - aqhome/ipc/data/msg_data_values.c | 155 -- aqhome/ipc/data/msg_data_values.h | 56 - aqhome/ipc/endpoint_ipc.c | 277 ---- aqhome/ipc/endpoint_ipc.h | 62 - aqhome/ipc/endpoint_ipc_p.h | 42 - aqhome/ipc/endpoint_ipcclient.c | 136 -- aqhome/ipc/endpoint_ipcclient.h | 46 - aqhome/ipc/msg_ipc_qwords.c | 121 -- aqhome/ipc/msg_ipc_qwords.h | 35 - aqhome/ipc/msg_ipc_result.c | 78 - aqhome/ipc/msg_ipc_result.h | 45 - aqhome/ipc/msg_ipc_tag16.c | 255 ---- aqhome/ipc/msg_ipc_tag16.h | 45 - aqhome/ipc/msg_ipc_tag16_p.h | 25 - aqhome/ipc/nodes/0BUILD | 90 -- aqhome/ipc/nodes/ipc_nodes.c | 16 - aqhome/ipc/nodes/ipc_nodes.h | 38 - aqhome/ipc/nodes/msg_ipc_forward.c | 95 -- aqhome/ipc/nodes/msg_ipc_forward.h | 32 - aqhome/ipc/nodes/msg_ipc_getdevices_req.c | 57 - aqhome/ipc/nodes/msg_ipc_getdevices_req.h | 27 - aqhome/ipc/nodes/msg_ipc_getdevices_rsp.c | 189 --- aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h | 53 - aqhome/ipc/nodes/msg_ipc_ping.c | 71 - aqhome/ipc/nodes/msg_ipc_ping.h | 29 - aqhome/ipc/nodes/msg_ipc_setaccmsggrps.c | 68 - aqhome/ipc/nodes/msg_ipc_setaccmsggrps.h | 29 - aqhome/ipc/nodes/msg_ipc_value.c | 136 -- aqhome/ipc/nodes/msg_ipc_value.h | 41 - aqhome/ipc/requests.c | 142 -- aqhome/ipc/requests.h | 30 - aqhome/ipc2/0BUILD | 32 +- aqhome/ipc2/endpoint.c | 2 +- aqhome/ipc2/ipc_client.c | 2 +- .../ipc2/{ipcmsgreader.c => ipc_msgreader.c} | 2 +- .../ipc2/{ipcmsgreader.h => ipc_msgreader.h} | 0 aqhome/ipc2/ipc_server.c | 4 +- aqhome/ipc2/mqtt_client.c | 2 +- .../{mqttmsgreader.c => mqtt_msgreader.c} | 2 +- .../{mqttmsgreader.h => mqtt_msgreader.h} | 0 .../{nodemsgreader.c => node_msgreader.c} | 2 +- .../{nodemsgreader.h => node_msgreader.h} | 0 aqhome/ipc2/tcpd_object.c | 2 +- aqhome/ipc2/tty_endpoint.c | 4 +- aqhome/ipc2/{ttyobject.c => tty_object.c} | 2 +- aqhome/ipc2/{ttyobject.h => tty_object.h} | 0 aqhome/libtest.c | 267 +--- aqhome/mqtt/0BUILD | 95 -- aqhome/mqtt/endpoint_mqtt.c | 226 --- aqhome/mqtt/endpoint_mqtt.h | 51 - aqhome/mqtt/endpoint_mqtt_p.h | 29 - aqhome/mqtt/endpoint_mqttc.c | 292 ---- aqhome/mqtt/endpoint_mqttc.h | 47 - aqhome/mqtt/msg_mqtt.c | 264 ---- aqhome/mqtt/msg_mqtt.h | 69 - aqhome/mqtt/msg_mqtt_connack.c | 110 -- aqhome/mqtt/msg_mqtt_connack.h | 44 - aqhome/mqtt/msg_mqtt_connect.c | 223 --- aqhome/mqtt/msg_mqtt_connect.h | 53 - aqhome/mqtt/msg_mqtt_publish.c | 213 --- aqhome/mqtt/msg_mqtt_publish.h | 33 - aqhome/mqtt/msg_mqtt_pubresponse.c | 74 - aqhome/mqtt/msg_mqtt_pubresponse.h | 31 - aqhome/mqtt/msg_mqtt_suback.c | 100 -- aqhome/mqtt/msg_mqtt_suback.h | 28 - aqhome/mqtt/msg_mqtt_subscribe.c | 127 -- aqhome/mqtt/msg_mqtt_subscribe.h | 27 - aqhome/msg/0BUILD | 46 +- aqhome/msg/dummy.c | 0 aqhome/msg/endpoint_tty.c | 423 ------ aqhome/msg/endpoint_tty.h | 26 - aqhome/msg/endpoint_tty_p.h | 34 - aqhome/msg/msg_claimaddr.c | 60 - aqhome/msg/msg_claimaddr.h | 29 - aqhome/msg/msg_denyaddr.c | 61 - aqhome/msg/msg_denyaddr.h | 29 - aqhome/msg/msg_device.c | 121 -- aqhome/msg/msg_device.h | 38 - aqhome/msg/msg_flashdata.c | 110 -- aqhome/msg/msg_flashdata.h | 34 - aqhome/msg/msg_flashend.c | 75 - aqhome/msg/msg_flashend.h | 31 - aqhome/msg/msg_flashready.c | 136 -- aqhome/msg/msg_flashready.h | 38 - aqhome/msg/msg_flashresponse.c | 50 - aqhome/msg/msg_flashresponse.h | 28 - aqhome/msg/msg_flashstart.c | 77 - aqhome/msg/msg_flashstart.h | 30 - aqhome/msg/msg_haveaddr.c | 60 - aqhome/msg/msg_haveaddr.h | 29 - aqhome/msg/msg_memstats.c | 94 -- aqhome/msg/msg_memstats.h | 38 - aqhome/msg/msg_needaddr.c | 52 - aqhome/msg/msg_needaddr.h | 28 - aqhome/msg/msg_node.c | 308 ---- aqhome/msg/msg_node.h | 106 -- aqhome/msg/msg_ping.c | 80 -- aqhome/msg/msg_ping.h | 30 - aqhome/msg/msg_pong.c | 51 - aqhome/msg/msg_pong.h | 29 - aqhome/msg/msg_reboot.c | 135 -- aqhome/msg/msg_reboot.h | 39 - aqhome/msg/msg_recvstats.c | 107 -- aqhome/msg/msg_recvstats.h | 37 - aqhome/msg/msg_sendstats.c | 79 - aqhome/msg/msg_sendstats.h | 34 - aqhome/msg/msg_sysstats.c | 76 - aqhome/msg/msg_sysstats.h | 35 - aqhome/msg/msg_value.c | 100 -- aqhome/msg/msg_value.h | 47 - aqhome/msg/msg_value2.c | 163 --- aqhome/msg/msg_value2.h | 46 - aqhome/msg/msg_value3.c | 234 --- aqhome/msg/msg_value3.h | 54 - aqhome/service/0BUILD | 82 -- aqhome/service/module.t2d | 88 -- aqhome/service/moduleperms.t2d | 75 - aqhome/service/permdef.t2d | 65 - aqhome/service/role.t2d | 72 - aqhome/service/service.c | 190 --- aqhome/service/service.h | 53 - aqhome/service/service_p.h | 29 - aqhome/service/session.t2d | 117 -- aqhome/service/user.t2d | 156 -- 194 files changed, 292 insertions(+), 17295 deletions(-) create mode 100644 aqhome-mqtt.devices.old create mode 100644 aqhome-react.vars delete mode 100644 aqhome/client/0BUILD delete mode 100644 aqhome/client/connection.c delete mode 100644 aqhome/client/connection.h delete mode 100644 aqhome/events/0BUILD delete mode 100644 aqhome/events/eventhandler.c delete mode 100644 aqhome/events/eventhandler.h delete mode 100644 aqhome/events/eventhandler_p.h delete mode 100644 aqhome/events/eventsubscription.c delete mode 100644 aqhome/events/eventsubscription.h delete mode 100644 aqhome/events/eventsubscription_p.h delete mode 100644 aqhome/events/eventtimer.c delete mode 100644 aqhome/events/eventtimer.h delete mode 100644 aqhome/events/eventtimer_p.h delete mode 100644 aqhome/http/0BUILD delete mode 100644 aqhome/http/content.c delete mode 100644 aqhome/http/content.h delete mode 100644 aqhome/http/content_files.c delete mode 100644 aqhome/http/content_files.h delete mode 100644 aqhome/http/content_files_p.h delete mode 100644 aqhome/http/content_p.h delete mode 100644 aqhome/http/endpoint_http.c delete mode 100644 aqhome/http/endpoint_http.h delete mode 100644 aqhome/http/endpoint_http_p.h delete mode 100644 aqhome/http/httprequest.c delete mode 100644 aqhome/http/httprequest.h delete mode 100644 aqhome/http/httprequest_p.h delete mode 100644 aqhome/http/httpservice.c delete mode 100644 aqhome/http/httpservice.h delete mode 100644 aqhome/http/httpservice_conf.c delete mode 100644 aqhome/http/httpservice_conf.h delete mode 100644 aqhome/http/httpservice_http.c delete mode 100644 aqhome/http/httpservice_http.h delete mode 100644 aqhome/http/httpservice_login.c delete mode 100644 aqhome/http/httpservice_login.h delete mode 100644 aqhome/http/httpservice_p.h delete mode 100644 aqhome/http/urlhandler.c delete mode 100644 aqhome/http/urlhandler.h delete mode 100644 aqhome/http/urlhandler_p.h delete mode 100644 aqhome/ipc/0BUILD delete mode 100644 aqhome/ipc/data/0BUILD delete mode 100644 aqhome/ipc/data/cmd_data.c delete mode 100644 aqhome/ipc/data/cmd_data_getdata.c delete mode 100644 aqhome/ipc/data/ipc_data.c delete mode 100644 aqhome/ipc/data/ipc_data.h delete mode 100644 aqhome/ipc/data/msg_data_connect.c delete mode 100644 aqhome/ipc/data/msg_data_connect.h delete mode 100644 aqhome/ipc/data/msg_data_datapoints.c delete mode 100644 aqhome/ipc/data/msg_data_datapoints.h delete mode 100644 aqhome/ipc/data/msg_data_devices.c delete mode 100644 aqhome/ipc/data/msg_data_devices.h delete mode 100644 aqhome/ipc/data/msg_data_getdata.c delete mode 100644 aqhome/ipc/data/msg_data_getdata.h delete mode 100644 aqhome/ipc/data/msg_data_multidata.c delete mode 100644 aqhome/ipc/data/msg_data_multidata.h delete mode 100644 aqhome/ipc/data/msg_data_set.c delete mode 100644 aqhome/ipc/data/msg_data_set.h delete mode 100644 aqhome/ipc/data/msg_data_values.c delete mode 100644 aqhome/ipc/data/msg_data_values.h delete mode 100644 aqhome/ipc/endpoint_ipc.c delete mode 100644 aqhome/ipc/endpoint_ipc.h delete mode 100644 aqhome/ipc/endpoint_ipc_p.h delete mode 100644 aqhome/ipc/endpoint_ipcclient.c delete mode 100644 aqhome/ipc/endpoint_ipcclient.h delete mode 100644 aqhome/ipc/msg_ipc_qwords.c delete mode 100644 aqhome/ipc/msg_ipc_qwords.h delete mode 100644 aqhome/ipc/msg_ipc_result.c delete mode 100644 aqhome/ipc/msg_ipc_result.h delete mode 100644 aqhome/ipc/msg_ipc_tag16.c delete mode 100644 aqhome/ipc/msg_ipc_tag16.h delete mode 100644 aqhome/ipc/msg_ipc_tag16_p.h delete mode 100644 aqhome/ipc/nodes/0BUILD delete mode 100644 aqhome/ipc/nodes/ipc_nodes.c delete mode 100644 aqhome/ipc/nodes/ipc_nodes.h delete mode 100644 aqhome/ipc/nodes/msg_ipc_forward.c delete mode 100644 aqhome/ipc/nodes/msg_ipc_forward.h delete mode 100644 aqhome/ipc/nodes/msg_ipc_getdevices_req.c delete mode 100644 aqhome/ipc/nodes/msg_ipc_getdevices_req.h delete mode 100644 aqhome/ipc/nodes/msg_ipc_getdevices_rsp.c delete mode 100644 aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h delete mode 100644 aqhome/ipc/nodes/msg_ipc_ping.c delete mode 100644 aqhome/ipc/nodes/msg_ipc_ping.h delete mode 100644 aqhome/ipc/nodes/msg_ipc_setaccmsggrps.c delete mode 100644 aqhome/ipc/nodes/msg_ipc_setaccmsggrps.h delete mode 100644 aqhome/ipc/nodes/msg_ipc_value.c delete mode 100644 aqhome/ipc/nodes/msg_ipc_value.h delete mode 100644 aqhome/ipc/requests.c delete mode 100644 aqhome/ipc/requests.h rename aqhome/ipc2/{ipcmsgreader.c => ipc_msgreader.c} (99%) rename aqhome/ipc2/{ipcmsgreader.h => ipc_msgreader.h} (100%) rename aqhome/ipc2/{mqttmsgreader.c => mqtt_msgreader.c} (99%) rename aqhome/ipc2/{mqttmsgreader.h => mqtt_msgreader.h} (100%) rename aqhome/ipc2/{nodemsgreader.c => node_msgreader.c} (99%) rename aqhome/ipc2/{nodemsgreader.h => node_msgreader.h} (100%) rename aqhome/ipc2/{ttyobject.c => tty_object.c} (99%) rename aqhome/ipc2/{ttyobject.h => tty_object.h} (100%) delete mode 100644 aqhome/mqtt/0BUILD delete mode 100644 aqhome/mqtt/endpoint_mqtt.c delete mode 100644 aqhome/mqtt/endpoint_mqtt.h delete mode 100644 aqhome/mqtt/endpoint_mqtt_p.h delete mode 100644 aqhome/mqtt/endpoint_mqttc.c delete mode 100644 aqhome/mqtt/endpoint_mqttc.h delete mode 100644 aqhome/mqtt/msg_mqtt.c delete mode 100644 aqhome/mqtt/msg_mqtt.h delete mode 100644 aqhome/mqtt/msg_mqtt_connack.c delete mode 100644 aqhome/mqtt/msg_mqtt_connack.h delete mode 100644 aqhome/mqtt/msg_mqtt_connect.c delete mode 100644 aqhome/mqtt/msg_mqtt_connect.h delete mode 100644 aqhome/mqtt/msg_mqtt_publish.c delete mode 100644 aqhome/mqtt/msg_mqtt_publish.h delete mode 100644 aqhome/mqtt/msg_mqtt_pubresponse.c delete mode 100644 aqhome/mqtt/msg_mqtt_pubresponse.h delete mode 100644 aqhome/mqtt/msg_mqtt_suback.c delete mode 100644 aqhome/mqtt/msg_mqtt_suback.h delete mode 100644 aqhome/mqtt/msg_mqtt_subscribe.c delete mode 100644 aqhome/mqtt/msg_mqtt_subscribe.h create mode 100644 aqhome/msg/dummy.c delete mode 100644 aqhome/msg/endpoint_tty.c delete mode 100644 aqhome/msg/endpoint_tty.h delete mode 100644 aqhome/msg/endpoint_tty_p.h delete mode 100644 aqhome/msg/msg_claimaddr.c delete mode 100644 aqhome/msg/msg_claimaddr.h delete mode 100644 aqhome/msg/msg_denyaddr.c delete mode 100644 aqhome/msg/msg_denyaddr.h delete mode 100644 aqhome/msg/msg_device.c delete mode 100644 aqhome/msg/msg_device.h delete mode 100644 aqhome/msg/msg_flashdata.c delete mode 100644 aqhome/msg/msg_flashdata.h delete mode 100644 aqhome/msg/msg_flashend.c delete mode 100644 aqhome/msg/msg_flashend.h delete mode 100644 aqhome/msg/msg_flashready.c delete mode 100644 aqhome/msg/msg_flashready.h delete mode 100644 aqhome/msg/msg_flashresponse.c delete mode 100644 aqhome/msg/msg_flashresponse.h delete mode 100644 aqhome/msg/msg_flashstart.c delete mode 100644 aqhome/msg/msg_flashstart.h delete mode 100644 aqhome/msg/msg_haveaddr.c delete mode 100644 aqhome/msg/msg_haveaddr.h delete mode 100644 aqhome/msg/msg_memstats.c delete mode 100644 aqhome/msg/msg_memstats.h delete mode 100644 aqhome/msg/msg_needaddr.c delete mode 100644 aqhome/msg/msg_needaddr.h delete mode 100644 aqhome/msg/msg_node.c delete mode 100644 aqhome/msg/msg_node.h delete mode 100644 aqhome/msg/msg_ping.c delete mode 100644 aqhome/msg/msg_ping.h delete mode 100644 aqhome/msg/msg_pong.c delete mode 100644 aqhome/msg/msg_pong.h delete mode 100644 aqhome/msg/msg_reboot.c delete mode 100644 aqhome/msg/msg_reboot.h delete mode 100644 aqhome/msg/msg_recvstats.c delete mode 100644 aqhome/msg/msg_recvstats.h delete mode 100644 aqhome/msg/msg_sendstats.c delete mode 100644 aqhome/msg/msg_sendstats.h delete mode 100644 aqhome/msg/msg_sysstats.c delete mode 100644 aqhome/msg/msg_sysstats.h delete mode 100644 aqhome/msg/msg_value.c delete mode 100644 aqhome/msg/msg_value.h delete mode 100644 aqhome/msg/msg_value2.c delete mode 100644 aqhome/msg/msg_value2.h delete mode 100644 aqhome/msg/msg_value3.c delete mode 100644 aqhome/msg/msg_value3.h delete mode 100644 aqhome/service/0BUILD delete mode 100644 aqhome/service/module.t2d delete mode 100644 aqhome/service/moduleperms.t2d delete mode 100644 aqhome/service/permdef.t2d delete mode 100644 aqhome/service/role.t2d delete mode 100644 aqhome/service/service.c delete mode 100644 aqhome/service/service.h delete mode 100644 aqhome/service/service_p.h delete mode 100644 aqhome/service/session.t2d delete mode 100644 aqhome/service/user.t2d diff --git a/apps/aqhome-mqttlog/s_publish.c b/apps/aqhome-mqttlog/s_publish.c index dfe2eb1..0de7bae 100644 --- a/apps/aqhome-mqttlog/s_publish.c +++ b/apps/aqhome-mqttlog/s_publish.c @@ -31,7 +31,7 @@ * ------------------------------------------------------------------------------------------------ */ -static int _handlePublish(AQH_OBJECT *o, const char *rcvdTopic, const char *rcvdValue); +static int _handlePublish(AQH_OBJECT *o, AQH_MQTTLOG_SERVER *xo, const char *rcvdTopic, const char *rcvdValue); static void _handleNumTopic(AQH_MQTTLOG_SERVER *xo, AQHMQTT_DEVICE *device, AQHMQTT_TOPIC *topic, const char *rcvdValue); static void _handleJsonTopic(AQH_MQTTLOG_SERVER *xo, AQHMQTT_DEVICE *device, @@ -69,12 +69,12 @@ void AQH_MqttLogServer_HandlePublishMsg(AQH_OBJECT *o, GWEN_UNUSED AQH_OBJECT *e if (topic && value) { int rv; - rv=_handlePublish(o, topic, value); + rv=_handlePublish(o, xo, topic, value); if (rv!=1) { DBG_INFO(NULL, "New topic \"%s\", trying to register", topic); rv=_registerNewDeviceForTopic(xo, topic); if (rv==1) { - rv=_handlePublish(o, topic, value); + rv=_handlePublish(o, xo, topic, value); if (rv!=1) { DBG_ERROR(NULL, "Topic \"%s\" still not handled, SNH!", topic); } @@ -92,53 +92,48 @@ void AQH_MqttLogServer_HandlePublishMsg(AQH_OBJECT *o, GWEN_UNUSED AQH_OBJECT *e -int _handlePublish(AQH_OBJECT *o, const char *rcvdTopic, const char *rcvdValue) +int _handlePublish(AQH_OBJECT *o, AQH_MQTTLOG_SERVER *xo, const char *rcvdTopic, const char *rcvdValue) { - if (o && rcvdTopic && *rcvdTopic) { - AQH_MQTTLOG_SERVER *xo; + if (o && rcvdTopic && *rcvdTopic && xo && xo->registeredDeviceList) { + AQHMQTT_DEVICE *device; - xo=AQH_MqttLogServer_GetServerData(o); - if (xo && xo->registeredDeviceList) { - AQHMQTT_DEVICE *device; + device=AQHMQTT_Device_List_First(xo->registeredDeviceList); + while(device) { + AQHMQTT_TOPIC_LIST *topicList; + const char *sDeviceName; + const char *sDeviceId; - device=AQHMQTT_Device_List_First(xo->registeredDeviceList); - while(device) { - AQHMQTT_TOPIC_LIST *topicList; - const char *sDeviceName; - const char *sDeviceId; + sDeviceName=AQHMQTT_Device_GetName(device); + sDeviceId=AQHMQTT_Device_GetId(device); - sDeviceName=AQHMQTT_Device_GetName(device); - sDeviceId=AQHMQTT_Device_GetId(device); + topicList=AQHMQTT_Device_GetTopicList(device); + if (topicList) { + AQHMQTT_TOPIC *topic; - topicList=AQHMQTT_Device_GetTopicList(device); - if (topicList) { - AQHMQTT_TOPIC *topic; - - topic=_findTopicMatchingTopic(topicList, rcvdTopic, AQHMQTT_TopicDir_In); + topic=_findTopicMatchingTopic(topicList, rcvdTopic, AQHMQTT_TopicDir_In); #if 0 - if (topic==NULL) { - topic=_findMaskMatchingTopic(topicList, rcvdTopic, AQHMQTT_TopicDir_In); - if (topic) - AQHMQTT_Topic_SetTopic(topic, rcvdTopic); - } -#endif - if (topic) { - DBG_INFO(AQH_LOGDOMAIN, - "Handling topic \"%s\" for device type %s (id: %s)", - rcvdTopic, - sDeviceName, sDeviceId?sDeviceId:""); - if (AQHMQTT_Topic_GetTopicType(topic)==AQHMQTT_TopicType_Json) - _handleJsonTopic(xo, device, topic, rcvdValue); - else - _handleNumTopic(xo, device, topic, rcvdValue); - return 1; - } + if (topic==NULL) { + topic=_findMaskMatchingTopic(topicList, rcvdTopic, AQHMQTT_TopicDir_In); + if (topic) + AQHMQTT_Topic_SetTopic(topic, rcvdTopic); + } +#endif + if (topic) { + DBG_INFO(AQH_LOGDOMAIN, + "Handling topic \"%s\" for device type %s (id: %s)", + rcvdTopic, + sDeviceName, sDeviceId?sDeviceId:""); + if (AQHMQTT_Topic_GetTopicType(topic)==AQHMQTT_TopicType_Json) + _handleJsonTopic(xo, device, topic, rcvdValue); + else + _handleNumTopic(xo, device, topic, rcvdValue); + return 1; } - - device=AQHMQTT_Device_List_Next(device); } - DBG_INFO(AQH_LOGDOMAIN, "ignoring topic \"%s\"", rcvdTopic); + + device=AQHMQTT_Device_List_Next(device); } + DBG_INFO(AQH_LOGDOMAIN, "ignoring topic \"%s\"", rcvdTopic); } return 0; } @@ -282,7 +277,7 @@ void _sendAnnounceValueMessage(AQH_MQTTLOG_SERVER *xo, const AQHMQTT_DEVICE *dev AQH_Endpoint_GetNextMessageId(xo->brokerEndpoint), 0, 0, msgValue); if (pubMsg) { - DBG_INFO(AQH_LOGDOMAIN, "BROKER ANNOUNCE_VALUE %s", AQH_Value_GetName(msgValue)); + DBG_ERROR(AQH_LOGDOMAIN, "BROKER ANNOUNCE_VALUE %s/%s", AQH_Value_GetDeviceName(msgValue), AQH_Value_GetName(msgValue)); AQH_Endpoint_AddMsgOut(xo->brokerEndpoint, pubMsg); } AQH_Value_free(msgValue); diff --git a/apps/aqhome-mqttlog/s_setdata.c b/apps/aqhome-mqttlog/s_setdata.c index de7c0d9..1c371e0 100644 --- a/apps/aqhome-mqttlog/s_setdata.c +++ b/apps/aqhome-mqttlog/s_setdata.c @@ -31,8 +31,7 @@ static void _sendDataForDevice(AQH_MQTTLOG_SERVER *xo, const AQHMQTT_DEVICE *device, const char *valueName, const char *valueData); -static void _sendValueToMqtt(AQH_MQTTLOG_SERVER *xo, const char *deviceId, - const AQHMQTT_TOPIC *topic, const char *valueData); +static void _sendValueToMqtt(AQH_MQTTLOG_SERVER *xo, const char *deviceId, const AQHMQTT_TOPIC *topic, const char *valueData); static GWEN_BUFFER *_createBufferForTopic(const char *deviceId, const AQHMQTT_TOPIC *topic); @@ -131,7 +130,7 @@ void _sendDataForDevice(AQH_MQTTLOG_SERVER *xo, -void _sendValueToMqtt(AQH_MQTTLOG_SERVER *xo, const char *deviceId, const AQHMQTT_TOPIC *topic, const char *valueData) +void _sendValueToMqtt(AQH_MQTTLOG_SERVER *xo, const char *deviceId, const AQHMQTT_TOPIC *topic, const char *valueData) { GWEN_BUFFER *buf; #if !DEBUG_DRY_RUN diff --git a/apps/aqhome-mqttlog/server.c b/apps/aqhome-mqttlog/server.c index 2062f62..1910e4a 100644 --- a/apps/aqhome-mqttlog/server.c +++ b/apps/aqhome-mqttlog/server.c @@ -109,10 +109,10 @@ static int _handleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObjec static int _handleBrokerDown(AQH_MQTTLOG_SERVER *xo); static int _handleMqttDown(AQH_MQTTLOG_SERVER *xo); -static void _handleMsgFromBroker(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *msg); +static void _handleMsgFromBroker(AQH_OBJECT *o, const AQH_MESSAGE *msg); static void _handleMsgFromMqtt(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *msg); -static void _handleMqttMsgPingRsp(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *msg); +static void _handleMqttMsgPingRsp(void); static int _createPidFile(const char *pidFilename); static int _diffInSeconds(time_t t1, time_t t0); @@ -474,7 +474,7 @@ int _startBroker(AQH_OBJECT *o, AQH_MQTTLOG_SERVER *xo) DBG_ERROR(NULL, "Error connecting to broker: %d", rv); return (rv<0)?rv:GWEN_ERROR_PERMISSIONS; } - DBG_NOTICE(NULL, "Connected to broker at %s:%d", xo->brokerAddress, xo->brokerPort); + DBG_NOTICE(NULL, "Fully connected to broker at %s:%d", xo->brokerAddress, xo->brokerPort); return 0; } else { @@ -658,7 +658,7 @@ void AQH_MqttLogServer_HandleBrokerMsgs(AQH_OBJECT *o) while( (msg=AQH_Endpoint_GetNextMsgIn(xo->brokerEndpoint)) ) { AQH_Message_SetObject(msg, xo->brokerEndpoint); - _handleMsgFromBroker(o, xo->brokerEndpoint, msg); + _handleMsgFromBroker(o, msg); AQH_Message_free(msg); } } @@ -666,7 +666,7 @@ void AQH_MqttLogServer_HandleBrokerMsgs(AQH_OBJECT *o) -void _handleMsgFromBroker(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *msg) +void _handleMsgFromBroker(AQH_OBJECT *o, const AQH_MESSAGE *msg) { GWEN_TAG16_LIST *tagList; @@ -762,14 +762,14 @@ void _handleMsgFromMqtt(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *msg) code=AQH_MqttMessage_GetTypeAndFlags(msg); switch(code & 0xf0) { case (AQH_MQTTMSG_MSGTYPE_PUBLISH & 0xf0): AQH_MqttLogServer_HandlePublishMsg(o, ep, msg); break; - case (AQH_MQTTMSG_MSGTYPE_PINGRESP & 0xf0): _handleMqttMsgPingRsp(o, ep, msg); break; + case (AQH_MQTTMSG_MSGTYPE_PINGRESP & 0xf0): _handleMqttMsgPingRsp(); break; default: break; } } -void _handleMqttMsgPingRsp(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *msg) +void _handleMqttMsgPingRsp(void) { DBG_INFO(NULL, "PING response received"); } @@ -962,8 +962,9 @@ void AQH_MqttLogServer_LoadRuntimeDeviceFiles(AQH_OBJECT *o) DBG_INFO(NULL, "Loading registered devices from file \"%s\"", xo->deviceFile); deviceList=AQH_MqttLogServer_ReadDeviceFile(o, xo->deviceFile); - if (deviceList) - AQH_MqttLogServer_SetRegisteredDeviceList(o, deviceList); + if (deviceList==NULL) + deviceList=AQHMQTT_Device_List_new(); + AQH_MqttLogServer_SetRegisteredDeviceList(o, deviceList); } } } @@ -999,7 +1000,7 @@ int AQH_MqttLogServer_SaveRuntimeDeviceFiles(AQH_OBJECT *o) * xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx */ -int _handleSignal(AQH_OBJECT *o, uint32_t slotId, AQH_OBJECT *senderObject, GWEN_UNUSED int param1, void *param2) +int _handleSignal(AQH_OBJECT *o, uint32_t slotId, GWEN_UNUSED AQH_OBJECT *senderObject, GWEN_UNUSED int param1, GWEN_UNUSED void *param2) { AQH_MQTTLOG_SERVER *xo; diff --git a/apps/aqhome-mqttlog/xmlread.c b/apps/aqhome-mqttlog/xmlread.c index 39db5d6..06649b1 100644 --- a/apps/aqhome-mqttlog/xmlread.c +++ b/apps/aqhome-mqttlog/xmlread.c @@ -80,7 +80,7 @@ AQHMQTT_DEVICE_LIST *AQH_MqttLogServer_ReadDeviceFile(AQH_OBJECT *o, const char deviceList=AQHMQTT_Device_List_new(); rv=_readDeviceFileToList(sFilename, deviceList); if (rv<0) { - DBG_ERROR(NULL, "File \"%s\" not found", sFilename); + DBG_ERROR(NULL, "Could not read file \"%s\" (empty?)", sFilename); AQHMQTT_Device_List_free(deviceList); return NULL; } diff --git a/apps/aqhome-nodes/db.c b/apps/aqhome-nodes/db.c index c328a7b..09346f0 100644 --- a/apps/aqhome-nodes/db.c +++ b/apps/aqhome-nodes/db.c @@ -258,22 +258,24 @@ void _setDeviceName(AQH_VALUE *value, uint32_t uid) void _announceValue(AQH_NODE_SERVER *xo, uint32_t uid, const AQHNODE_VALUE *v) { - AQH_VALUE *value; - AQH_MESSAGE *msg; - - value=AQH_Value_new(); - _setDeviceName(value, uid); - AQH_Value_SetDriver(value, "nodes"); - AQH_Value_SetName(value, AQHNODE_Value_GetName(v)); - AQH_Value_SetValueUnits(value, AQHNODE_Value_GetValueUnits(v)); - AQH_Value_SetValueType(value, AQHNODE_Value_GetValueType(v)); - AQH_Value_SetModality(value, AQHNODE_Value_GetModality(v)); + if (xo && xo->brokerEndpoint) { + AQH_VALUE *value; + AQH_MESSAGE *msg; - msg=AQH_IpcdMessageValues_newForOne(AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE, - AQH_Endpoint_GetNextMessageId(xo->brokerEndpoint), 0, - 0, value); - AQH_Endpoint_AddMsgOut(xo->brokerEndpoint, msg); - AQH_Value_free(value); + value=AQH_Value_new(); + _setDeviceName(value, uid); + AQH_Value_SetDriver(value, "nodes"); + AQH_Value_SetName(value, AQHNODE_Value_GetName(v)); + AQH_Value_SetValueUnits(value, AQHNODE_Value_GetValueUnits(v)); + AQH_Value_SetValueType(value, AQHNODE_Value_GetValueType(v)); + AQH_Value_SetModality(value, AQHNODE_Value_GetModality(v)); + + msg=AQH_IpcdMessageValues_newForOne(AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE, + AQH_Endpoint_GetNextMessageId(xo->brokerEndpoint), 0, + 0, value); + AQH_Endpoint_AddMsgOut(xo->brokerEndpoint, msg); + AQH_Value_free(value); + } } diff --git a/apps/aqhome-nodes/main.c b/apps/aqhome-nodes/main.c index 342bfd4..b97ffc7 100644 --- a/apps/aqhome-nodes/main.c +++ b/apps/aqhome-nodes/main.c @@ -149,13 +149,13 @@ void _runService(AQH_OBJECT *aqh, AQH_EVENT_LOOP *eventLoop) now=time(NULL); if (_diffInSeconds(now, timeLastConnectionCleanup)>CONNCLEAN_INTERVAL_IN_SECS) { - DBG_ERROR(NULL, "Cleanup connections"); + DBG_INFO(NULL, "Cleanup connections"); AQH_NodeServer_CleanupClients(aqh); timeLastConnectionCleanup=now; } if (_diffInSeconds(now, timeLastConnCheck)>CONNCHECK_INTERVAL_IN_SECS) { - DBG_ERROR(NULL, "Check connections"); + DBG_INFO(NULL, "Check connections"); AQH_NodeServer_CheckBrokerConnection(aqh); AQH_NodeServer_CheckTtyConnection(aqh); timeLastConnCheck=now; diff --git a/apps/aqhome-nodes/server.c b/apps/aqhome-nodes/server.c index d51515d..ee1456b 100644 --- a/apps/aqhome-nodes/server.c +++ b/apps/aqhome-nodes/server.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -580,7 +580,7 @@ int _startBroker(AQH_OBJECT *o, AQH_NODE_SERVER *xo) DBG_ERROR(NULL, "Error connecting to broker: %d", rv); return (rv<0)?rv:GWEN_ERROR_PERMISSIONS; } - DBG_ERROR(NULL, "Connected to broker at %s:%d", xo->brokerAddress, xo->brokerPort); + DBG_ERROR(NULL, "Fully connected to broker at %s:%d", xo->brokerAddress, xo->brokerPort); return 0; } else { @@ -808,7 +808,7 @@ void _handleMsgFromTty(AQH_OBJECT *o, AQH_NODE_SERVER *xo, const AQH_MESSAGE *ms uint8_t code; code=AQH_NodeMessage_GetMsgType(msg); - DBG_ERROR(NULL, "Received Node packet %d (%x)", (int) code, code); + DBG_INFO(NULL, "Received Node packet %d (%x)", (int) code, code); AQH_NodeServer_NodeMsgToDb(o, msg); _writeTtyMsgToLogFile(xo, msg); _forwardTtyMsgToBroker(o, xo, msg); @@ -1117,7 +1117,7 @@ void _handleMsgFromBroker(AQH_OBJECT *o, AQH_OBJECT *ep, const AQH_MESSAGE *msg) code=AQH_IpcMessage_GetCode(msg); protoId=AQH_IpcMessage_GetProtoId(msg); if (protoId==AQH_IPC_PROTOCOL_DATA_ID) { - DBG_ERROR(NULL, "Received IPC packet %d (%x)", (int) code, code); + DBG_INFO(NULL, "Received IPC packet %d (%x)", (int) code, code); switch(code) { case AQH_MSGTYPE_IPC_DATA_SETDATA: AQH_NodeServer_HandleSetData(o, ep, msg); break; default: break; diff --git a/apps/aqhome-react/main.c b/apps/aqhome-react/main.c index 42116ae..c125576 100644 --- a/apps/aqhome-react/main.c +++ b/apps/aqhome-react/main.c @@ -198,7 +198,7 @@ void _runService(AQH_OBJECT *aqh, AQH_EVENT_LOOP *eventLoop) } if (_diffInSeconds(now, lastSaveTime)>AQHOME_REACT_SAVE_INTERVAL) { - DBG_ERROR(NULL, "Writing var file"); + DBG_INFO(NULL, "Writing var file"); rv=AQH_ReactServer_WriteVarsFile(aqh); if (rv<0) { DBG_INFO(NULL, "Error writing runtime data"); diff --git a/apps/aqhome-react/server.c b/apps/aqhome-react/server.c index b815362..006becc 100644 --- a/apps/aqhome-react/server.c +++ b/apps/aqhome-react/server.c @@ -496,7 +496,7 @@ int _startBroker(AQH_OBJECT *o, AQH_REACT_SERVER *xo) DBG_ERROR(NULL, "Error connecting to broker: %d", rv); return (rv<0)?rv:GWEN_ERROR_PERMISSIONS; } - DBG_INFO(NULL, "Connected to broker at %s:%d", xo->brokerAddress, xo->brokerPort); + DBG_ERROR(NULL, "Fully connected to broker at %s:%d", xo->brokerAddress, xo->brokerPort); return 0; } else { diff --git a/aqhome-mqtt.devices.old b/aqhome-mqtt.devices.old new file mode 100644 index 0000000..be8c750 --- /dev/null +++ b/aqhome-mqtt.devices.old @@ -0,0 +1,184 @@ + + + + +tele/tasmota/plug01/SENSOR +tele/tasmota/*/SENSOR +tele/tasmota/ +/SENSOR + + + + + + + + + + + +cmnd/tasmota/ +/Power + + + + + + + + + +tele/tasmota/plug02/SENSOR +tele/tasmota/*/SENSOR +tele/tasmota/ +/SENSOR + + + + + + + + + + + +cmnd/tasmota/ +/Power + + + + + + + + + +tele/tasmota/plug03/SENSOR +tele/tasmota/*/SENSOR +tele/tasmota/ +/SENSOR + + + + + + + + + + + +cmnd/tasmota/ +/Power + + + + + + + + + +tele/tasmota_109C2F/SENSOR +tele/tasmota_*/SENSOR +tele/tasmota_ +/SENSOR + + + + + + + + + + + +cmnd/tasmota/ +/Power + + + + + + + + + +tele/tasmota_10359B/SENSOR +tele/tasmota_*/SENSOR +tele/tasmota_ +/SENSOR + + + + + + + + + + + +cmnd/tasmota_ +/Power + + + + + + + + + +tele/tasmota_0F25C2/SENSOR +tele/tasmota_*/SENSOR +tele/tasmota_ +/SENSOR + + + + + + + + + + + +cmnd/tasmota_ +/Power + + + + + + + + + +tele/tasmota_10A4B7/SENSOR +tele/tasmota_*/SENSOR +tele/tasmota_ +/SENSOR + + + + + + + + + + + +cmnd/tasmota_ +/Power + + + + + + + diff --git a/aqhome-react.sh b/aqhome-react.sh index 7709a3c..931fd0c 100755 --- a/aqhome-react.sh +++ b/aqhome-react.sh @@ -3,5 +3,4 @@ # export AQHOME_LOGLEVEL=info export LD_LIBRARY_PATH="0-build/aqhome/:$LD_LIBRARY_PATH" -0-build/apps/aqhome-react/aqhome-react -p ./aqhome-react.pid "$@" - +0-build/apps/aqhome-react/aqhome-react -p ./aqhome-react.pid -V ./aqhome-react.vars "$@" diff --git a/aqhome-react.vars b/aqhome-react.vars new file mode 100644 index 0000000..e69de29 diff --git a/aqhome/0BUILD b/aqhome/0BUILD index 7ef5be5..d33f5d3 100644 --- a/aqhome/0BUILD +++ b/aqhome/0BUILD @@ -64,29 +64,21 @@ msg - ipc ipc2 nodes - mqtt hexfile data - events events2 - client aqhmsg - aqhipc aqhipc2 aqhnodes - aqhmqtt aqhhexfile aqhdata - aqhevents aqhevents2 - aqhclient diff --git a/aqhome/client/0BUILD b/aqhome/client/0BUILD deleted file mode 100644 index 9128de9..0000000 --- a/aqhome/client/0BUILD +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - $(gwenhywfar_cflags) - -I$(topsrcdir) - -I$(topbuilddir) - - - - --include=$(builddir) - --include=$(srcdir) - - - - - - $(visibility_cflags) - - - - --api=AQHOME_API - - - - - - - - - - - - - - - - - - $(local/built_headers_pub) - - - - - connection.h - - - - - - - - - $(local/typefiles) - - connection.c - - - - - - - - - - - - - - - - - - - diff --git a/aqhome/client/connection.c b/aqhome/client/connection.c deleted file mode 100644 index 0f63ccc..0000000 --- a/aqhome/client/connection.c +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2024 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "./connection.h" - -#include "aqhome/ipc/endpoint_ipc.h" -#include "aqhome/ipc/endpoint_ipcclient.h" -#include "aqhome/ipc/data/ipc_data.h" -#include "aqhome/ipc/data/msg_data_connect.h" -#include "aqhome/ipc/msg_ipc_result.h" - -#include -#include -#include -#include -#include -#include - -#include - - - -GWEN_MSG_ENDPOINT *_physConnectToBroker(const char *addr, int port, const char *clientId, uint32_t flags); - - - - -int AQH_BrokerConnection_FlushOutMessageQueue(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds) -{ - time_t startTime; - - startTime=time(NULL); - - while(GWEN_MsgEndpoint_HaveMessageToSend(epTcp)) { - time_t now; - - GWEN_MsgEndpoint_IoLoop(epTcp, 1000); /* 1000 ms */ - now=time(NULL); - if (now-startTime>timeoutInSeconds) { - DBG_INFO(AQH_LOGDOMAIN, "Timeout"); - return GWEN_ERROR_TIMEOUT; - } - } - - return 0; -} - - - -GWEN_MSG *AQH_BrokerConnection_WaitForSpecificMessage(GWEN_MSG_ENDPOINT *epTcp, int msgCode, int timeoutInSeconds) -{ - time_t startTime; - - startTime=time(NULL); - - for (;;) { - GWEN_MSG *msg; - time_t now; - - GWEN_MsgEndpoint_IoLoop(epTcp, 1000); /* 1000 ms */ - msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp); - if (msg) { - uint16_t code; - - code=GWEN_IpcMsg_GetCode(msg); - if (code==msgCode) { - DBG_INFO(AQH_LOGDOMAIN, "Received expected IPC message"); - return msg; - } - else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) { - DBG_INFO(AQH_LOGDOMAIN, "Received IPC result message"); - return msg; - } - else { - DBG_INFO(AQH_LOGDOMAIN, "Received unexpected message %d (%x)", code, code); - } - GWEN_Msg_free(msg); - } - now=time(NULL); - if (now-startTime>timeoutInSeconds) { - DBG_INFO(AQH_LOGDOMAIN, "Timeout"); - break; - } - } - - return NULL; -} - - - -GWEN_MSG_ENDPOINT *AQH_BrokerConnection_OpenConnection(const char *addr, int port, - const char *clientId, - const char *userId, const char *passwd, - uint32_t flags, - int timeoutInSeconds) -{ - GWEN_MSG_ENDPOINT *epTcp; - GWEN_MSG *msgOut; - GWEN_MSG *msgIn; - uint32_t result; - - epTcp=_physConnectToBroker(addr, port, clientId, 0); - if (epTcp==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "ERROR creating TCP connection"); - return NULL; - } - - msgOut=AQH_ConnectDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_CONNECT_REQ, - GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0, - clientId, userId, passwd, flags); - if (msgOut==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Error creating message"); - GWEN_MsgEndpoint_free(epTcp); - return NULL; - } - GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut); - - msgIn=AQH_BrokerConnection_WaitForSpecificMessage(epTcp, AQH_MSGTYPE_IPC_DATA_RESULT, timeoutInSeconds); - if (msgIn==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "No response received"); - GWEN_MsgEndpoint_free(epTcp); - return NULL; - } - - result=AQH_ResultIpcMsg_GetResultCode(msgIn); - GWEN_Msg_free(msgIn); - - if (result!=AQH_MSG_IPC_SUCCESS) { - DBG_ERROR(AQH_LOGDOMAIN, "Response: %d", result); - GWEN_MsgEndpoint_free(epTcp); - return NULL; - } - - return epTcp; -} - - - -GWEN_MSG_ENDPOINT *_physConnectToBroker(const char *addr, int port, const char *clientId, uint32_t flags) -{ - GWEN_MSG_ENDPOINT *ep; - GWEN_MSG_ENDPOINT *ipcBaseEndpoint; - int rv; - - ep=AQH_ClientIpcEndpoint_new("brokerIpcClient", 0); - GWEN_MsgEndpoint_AddFlags(ep, flags); - - ipcBaseEndpoint=AQH_IpcEndpoint_CreateIpcTcpClient(addr, port, "brokerPhysEndpoint", 0); - AQH_IpcEndpoint_SetServiceName(ipcBaseEndpoint, clientId); - GWEN_MsgEndpoint_Tree2_AddChild(ep, ipcBaseEndpoint); - - rv=GWEN_MultilayerEndpoint_StartConnect(ep); - if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) { - DBG_ERROR(AQH_LOGDOMAIN, "Error connecting to broker server %s:%d (%d)", addr, port, rv); - GWEN_MsgEndpoint_free(ep); - return NULL; - } - - return ep; -} - - - - - - diff --git a/aqhome/client/connection.h b/aqhome/client/connection.h deleted file mode 100644 index b247219..0000000 --- a/aqhome/client/connection.h +++ /dev/null @@ -1,28 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2024 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQHOME_CLIENT_CONNECTION_H -#define AQHOME_CLIENT_CONNECTION_H - - -#include - -#include - - -GWEN_MSG_ENDPOINT *AQH_BrokerConnection_OpenConnection(const char *addr, int port, - const char *clientId, - const char *userId, const char *passwd, - uint32_t flags, - int timeoutInSeconds); -int AQH_BrokerConnection_FlushOutMessageQueue(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds); -GWEN_MSG *AQH_BrokerConnection_WaitForSpecificMessage(GWEN_MSG_ENDPOINT *epTcp, int msgCode, int timeoutInSeconds); - - - -#endif diff --git a/aqhome/data/vars_dbread.c b/aqhome/data/vars_dbread.c index 4e97ff3..55b5937 100644 --- a/aqhome/data/vars_dbread.c +++ b/aqhome/data/vars_dbread.c @@ -97,7 +97,6 @@ AQH_VARS *AQH_Vars_ReadDbFormat(const char *src) const char *_readLine(AQH_VARS **pVars, const char *src, GWEN_BUFFER *wbuf) { - int rv; const char *s; s=src; @@ -143,7 +142,6 @@ const char *_readLine(AQH_VARS **pVars, const char *src, GWEN_BUFFER *wbuf) const char *_readGroupOrVar(AQH_VARS **pVars, const char *src, GWEN_BUFFER *wbuf) { const char *s; - int rv; GWEN_Buffer_Reset(wbuf); s=_getWordToBuffer(src, " ={#\t\r\n", wbuf, _textFlags); diff --git a/aqhome/events/0BUILD b/aqhome/events/0BUILD deleted file mode 100644 index dc5fb56..0000000 --- a/aqhome/events/0BUILD +++ /dev/null @@ -1,87 +0,0 @@ - - - - - - - - $(gwenhywfar_cflags) - $(aqdatabase_cflags) - -I$(topsrcdir) - -I$(topbuilddir) - - - - --include=$(builddir) - --include=$(srcdir) - --include=$(aqdatabase_AQDATABASE_TYPEMAKERDIR)/c - - - - - - $(visibility_cflags) - - - - --api=AQHOME_API - - - - - - - - - - - - - - - - - - $(local/built_headers_pub) - - - - - eventsubscription.h - eventtimer.h - eventhandler.h - - - - - eventsubscription_p.h - eventtimer_p.h - eventhandler_p.h - - - - - $(local/typefiles) - - eventsubscription.c - eventtimer.c - eventhandler.c - - - - - - - - - - - - - - - - - - - diff --git a/aqhome/events/eventhandler.c b/aqhome/events/eventhandler.c deleted file mode 100644 index 59c475a..0000000 --- a/aqhome/events/eventhandler.c +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** - * This file is part of the project Gwenhywfar. - * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "./eventhandler_p.h" - -#include - - - -GWEN_INHERIT_FUNCTIONS(AQH_EVENT_HANDLER) -GWEN_LIST_FUNCTIONS(AQH_EVENT_HANDLER, AQH_EventHandler) - - - - -AQH_EVENT_HANDLER *AQH_EventHandler_new() -{ - AQH_EVENT_HANDLER *evh; - - GWEN_NEW_OBJECT(AQH_EVENT_HANDLER, evh); - GWEN_INHERIT_INIT(AQH_EVENT_HANDLER, evh); - GWEN_LIST_INIT(AQH_EVENT_HANDLER, evh); - - evh->timerList=AQH_EventTimer_List_new(); - evh->subscriptionList=AQH_EventSubscription_List_new(); - - return evh; -} - - - -void AQH_EventHandler_free(AQH_EVENT_HANDLER *evh) -{ - if (evh) { - GWEN_LIST_FINI(AQH_EVENT_HANDLER, evh); - GWEN_INHERIT_FINI(AQH_EVENT_HANDLER, evh); - - AQH_EventSubscription_List_free(evh->subscriptionList); - AQH_EventTimer_List_free(evh->timerList); - GWEN_FREE_OBJECT(evh); - } -} - - - -AQH_EVENT_TIMER_LIST *AQH_EventHandler_GetTimerList(const AQH_EVENT_HANDLER *evh) -{ - return evh?evh->timerList:NULL; -} - - - -void AQH_EventHandler_AddTimer(AQH_EVENT_HANDLER *evh, AQH_EVENT_TIMER *evt) -{ - if (evh && evt) { - AQH_EventTimer_SetId(evt, ++(evh->lastTimerId)); - AQH_EventTimer_List_Add(evt, evh->timerList); - } -} - - - -AQH_EVENT_SUBSCRIPTION_LIST *AQH_EventHandler_GetSubscriptionList(const AQH_EVENT_HANDLER *evh) -{ - return evh?evh->subscriptionList:NULL; -} - - - -void AQH_EventHandler_AddSubscription(AQH_EVENT_HANDLER *evh, AQH_EVENT_SUBSCRIPTION *evs) -{ - if (evh && evs) - AQH_EventSubscription_List_Add(evs, evh->subscriptionList); -} - - - -void AQH_EventHandler_HandleTimeTick(AQH_EVENT_HANDLER *evh, uint64_t t) -{ - if (evh) { - AQH_EVENT_TIMER *evt; - - evt=AQH_EventTimer_List_First(evh->timerList); - while(evt) { - AQH_EVENT_TIMER *evtNext; - - evtNext=AQH_EventTimer_List_Next(evt); - if (AQH_EventTimer_CheckWhetherTickTriggers(evt, t)) { - AQH_EventHandler_HandleEvent(evh, AQH_EventTimer_GetEventType(evt), AQH_EventTimer_GetId(evt), 0.0); - if (AQH_EventTimer_GetFlags(evt) & AQH_EVENT_TIMER_FLAGS_DELETE_IF_TRIGGERED) { - DBG_INFO(AQH_LOGDOMAIN, "Deleting timer after trigger"); - AQH_EventTimer_List_Del(evt); - AQH_EventTimer_free(evt); - } - } - evt=evtNext; - } - } -} - - - -void AQH_EventHandler_HandleEvent(AQH_EVENT_HANDLER *evh, int eventType, uint64_t objectId, double data) -{ - if (evh) { - AQH_EVENT_SUBSCRIPTION *evs; - - evs=AQH_EventSubscription_List_First(evh->subscriptionList); - while(evs) { - if (AQH_EventSubscription_GetEventType(evs)==eventType) { - int objectIdFromSubscription; - - objectIdFromSubscription=AQH_EventSubscription_GetObjectId(evs); - if (objectIdFromSubscription==0 || objectIdFromSubscription==objectId) - AQH_EventSubscription_CallHandler(evs, eventType, objectId, data); - } - - evs=AQH_EventSubscription_List_Next(evs); - } - } -} - - - - - - - - diff --git a/aqhome/events/eventhandler.h b/aqhome/events/eventhandler.h deleted file mode 100644 index 5af2fd4..0000000 --- a/aqhome/events/eventhandler.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** - * This file is part of the project Gwenhywfar. - * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_EVENT_HANDLER_H -#define AQH_EVENT_HANDLER_H - - -#include "aqhome/api.h" - -#include -#include - - - -typedef struct AQH_EVENT_HANDLER AQH_EVENT_HANDLER; -GWEN_INHERIT_FUNCTION_LIB_DEFS(AQH_EVENT_HANDLER, AQHOME_API) -GWEN_LIST_FUNCTION_LIB_DEFS(AQH_EVENT_HANDLER, AQH_EventHandler, AQHOME_API) - -#include "aqhome/events/eventtimer.h" -#include "aqhome/events/eventsubscription.h" - - - -AQHOME_API AQH_EVENT_HANDLER *AQH_EventHandler_new(); -AQHOME_API void AQH_EventHandler_free(AQH_EVENT_HANDLER *evh); - -AQHOME_API AQH_EVENT_TIMER_LIST *AQH_EventHandler_GetTimerList(const AQH_EVENT_HANDLER *evh); -AQHOME_API void AQH_EventHandler_AddTimer(AQH_EVENT_HANDLER *evh, AQH_EVENT_TIMER *evt); - -AQHOME_API AQH_EVENT_SUBSCRIPTION_LIST *AQH_EventHandler_GetSubscriptionList(const AQH_EVENT_HANDLER *evh); -AQHOME_API void AQH_EventHandler_AddSubscription(AQH_EVENT_HANDLER *evh, AQH_EVENT_SUBSCRIPTION *evs); - - -AQHOME_API void AQH_EventHandler_HandleTimeTick(AQH_EVENT_HANDLER *evh, uint64_t t); -AQHOME_API void AQH_EventHandler_HandleEvent(AQH_EVENT_HANDLER *evh, int eventType, uint64_t objectId, double data); - - - -#endif - - diff --git a/aqhome/events/eventhandler_p.h b/aqhome/events/eventhandler_p.h deleted file mode 100644 index 6e8ef78..0000000 --- a/aqhome/events/eventhandler_p.h +++ /dev/null @@ -1,30 +0,0 @@ -/**************************************************************************** - * This file is part of the project Gwenhywfar. - * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_EVENT_HANDLER_P_H -#define AQH_EVENT_HANDLER_P_H - - -#include "aqhome/events/eventhandler.h" - - - -struct AQH_EVENT_HANDLER { - GWEN_INHERIT_ELEMENT(AQH_EVENT_HANDLER) - GWEN_LIST_ELEMENT(AQH_EVENT_HANDLER) - - uint64_t lastTimerId; - AQH_EVENT_TIMER_LIST *timerList; - AQH_EVENT_SUBSCRIPTION_LIST *subscriptionList; -}; - - - -#endif - - diff --git a/aqhome/events/eventsubscription.c b/aqhome/events/eventsubscription.c deleted file mode 100644 index 5cd88cc..0000000 --- a/aqhome/events/eventsubscription.c +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** - * This file is part of the project Gwenhywfar. - * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "./eventsubscription_p.h" - -#include - - - - -GWEN_INHERIT_FUNCTIONS(AQH_EVENT_SUBSCRIPTION) -GWEN_LIST_FUNCTIONS(AQH_EVENT_SUBSCRIPTION, AQH_EventSubscription) - - - - -AQH_EVENT_SUBSCRIPTION *AQH_EventSubscription_new() -{ - AQH_EVENT_SUBSCRIPTION *evs; - - GWEN_NEW_OBJECT(AQH_EVENT_SUBSCRIPTION, evs); - GWEN_INHERIT_INIT(AQH_EVENT_SUBSCRIPTION, evs); - GWEN_LIST_INIT(AQH_EVENT_SUBSCRIPTION, evs); - - return evs; -} - - - -void AQH_EventSubscription_free(AQH_EVENT_SUBSCRIPTION *evs) -{ - if (evs) { - GWEN_LIST_FINI(AQH_EVENT_SUBSCRIPTION, evs); - GWEN_INHERIT_FINI(AQH_EVENT_SUBSCRIPTION, evs); - GWEN_FREE_OBJECT(evs); - } -} - - - -int AQH_EventSubscription_GetEventType(const AQH_EVENT_SUBSCRIPTION *evs) -{ - return evs?evs->eventType:0; -} - - - -void AQH_EventSubscription_SetEventType(AQH_EVENT_SUBSCRIPTION *evs, int i) -{ - if (evs) - evs->eventType=i; -} - - - -uint64_t AQH_EventSubscription_GetObjectId(const AQH_EVENT_SUBSCRIPTION *evs) -{ - return evs?evs->objectId:0; -} - - - -void AQH_EventSubscription_SetObjectId(AQH_EVENT_SUBSCRIPTION *evs, uint64_t i) -{ - if (evs) - evs->objectId=i; -} - - - -int AQH_EventSubscription_CallHandler(AQH_EVENT_SUBSCRIPTION *evs, int eventType, uint64_t objectId, double data) -{ - if (evs && evs->handlerFn) - return evs->handlerFn(evs, eventType, objectId, data); - return 0; -} - - - - - - - - diff --git a/aqhome/events/eventsubscription.h b/aqhome/events/eventsubscription.h deleted file mode 100644 index 0f04330..0000000 --- a/aqhome/events/eventsubscription.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - * This file is part of the project Gwenhywfar. - * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_EVENTSUBSCRIPTION_H -#define AQH_EVENTSUBSCRIPTION_H - - -#include "aqhome/api.h" - -#include -#include - - - -typedef struct AQH_EVENT_SUBSCRIPTION AQH_EVENT_SUBSCRIPTION; -GWEN_INHERIT_FUNCTION_LIB_DEFS(AQH_EVENT_SUBSCRIPTION, AQHOME_API) -GWEN_LIST_FUNCTION_LIB_DEFS(AQH_EVENT_SUBSCRIPTION, AQH_EventSubscription, AQHOME_API) - -typedef int (*AQH_EVENT_SUBSCRIPTION_HANDLER_FN)(AQH_EVENT_SUBSCRIPTION *evs, int eventType, uint64_t objectId, double data); - - -AQHOME_API AQH_EVENT_SUBSCRIPTION *AQH_EventSubscription_new(); -AQHOME_API void AQH_EventSubscription_free(AQH_EVENT_SUBSCRIPTION *evs); - -AQHOME_API int AQH_EventSubscription_GetEventType(const AQH_EVENT_SUBSCRIPTION *evs); -AQHOME_API void AQH_EventSubscription_SetEventType(AQH_EVENT_SUBSCRIPTION *evs, int i); - -AQHOME_API uint64_t AQH_EventSubscription_GetObjectId(const AQH_EVENT_SUBSCRIPTION *evs); -AQHOME_API void AQH_EventSubscription_SetObjectId(AQH_EVENT_SUBSCRIPTION *evs, uint64_t i); - -AQHOME_API int AQH_EventSubscription_CallHandler(AQH_EVENT_SUBSCRIPTION *evs, int eventType, uint64_t objectId, double data); - - -#endif - - diff --git a/aqhome/events/eventsubscription_p.h b/aqhome/events/eventsubscription_p.h deleted file mode 100644 index 22cc43f..0000000 --- a/aqhome/events/eventsubscription_p.h +++ /dev/null @@ -1,31 +0,0 @@ -/**************************************************************************** - * This file is part of the project Gwenhywfar. - * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_EVENTSUBSCRIPTION_P_H -#define AQH_EVENTSUBSCRIPTION_P_H - - -#include "aqhome/events/eventsubscription.h" - - - -struct AQH_EVENT_SUBSCRIPTION { - GWEN_INHERIT_ELEMENT(AQH_EVENT_SUBSCRIPTION) - GWEN_LIST_ELEMENT(AQH_EVENT_SUBSCRIPTION) - - int eventType; - uint64_t objectId; - - AQH_EVENT_SUBSCRIPTION_HANDLER_FN handlerFn; -}; - - - -#endif - - diff --git a/aqhome/events/eventtimer.c b/aqhome/events/eventtimer.c deleted file mode 100644 index 104c26d..0000000 --- a/aqhome/events/eventtimer.c +++ /dev/null @@ -1,194 +0,0 @@ -/**************************************************************************** - * This file is part of the project Gwenhywfar. - * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "./eventtimer_p.h" - -#include - - - -GWEN_INHERIT_FUNCTIONS(AQH_EVENT_TIMER) -GWEN_LIST_FUNCTIONS(AQH_EVENT_TIMER, AQH_EventTimer) - - - - -AQH_EVENT_TIMER *AQH_EventTimer_new() -{ - AQH_EVENT_TIMER *evt; - - GWEN_NEW_OBJECT(AQH_EVENT_TIMER, evt); - GWEN_INHERIT_INIT(AQH_EVENT_TIMER, evt); - GWEN_LIST_INIT(AQH_EVENT_TIMER, evt); - - return evt; -} - - - -void AQH_EventTimer_free(AQH_EVENT_TIMER *evt) -{ - if (evt) { - GWEN_LIST_FINI(AQH_EVENT_TIMER, evt); - GWEN_INHERIT_FINI(AQH_EVENT_TIMER, evt); - - GWEN_FREE_OBJECT(evt); - } -} - - - -uint32_t AQH_EventTimer_GetFlags(const AQH_EVENT_TIMER *evt) -{ - return evt?evt->flags:0; -} - - - -void AQH_EventTimer_SetFlags(AQH_EVENT_TIMER *evt, uint32_t f) -{ - if (evt) - evt->flags=f; -} - - - -void AQH_EventTimer_AddFlags(AQH_EVENT_TIMER *evt, uint32_t f) -{ - if (evt) - evt->flags|=f; -} - - - -void AQH_EventTimer_SubFlags(AQH_EVENT_TIMER *evt, uint32_t f) -{ - if (evt) - evt->flags&=~f; -} - - - -int AQH_EventTimer_GetTimerType(const AQH_EVENT_TIMER *evt) -{ - return evt?evt->timerType:0; -} - - - -void AQH_EventTimer_SetTimerType(AQH_EVENT_TIMER *evt, int i) -{ - if (evt) - evt->timerType=i; -} - - - -uint64_t AQH_EventTimer_GetId(const AQH_EVENT_TIMER *evt) -{ - return evt?evt->id:0; -} - - - -void AQH_EventTimer_SetId(AQH_EVENT_TIMER *evt, uint64_t i) -{ - if (evt) - evt->id=i; -} - - - -uint64_t AQH_EventTimer_GetCurrentValue(const AQH_EVENT_TIMER *evt) -{ - return evt?evt->currentValue:0; -} - - - -void AQH_EventTimer_SetCurrentValue(AQH_EVENT_TIMER *evt, uint64_t i) -{ - if (evt) - evt->currentValue=i; -} - - - -uint64_t AQH_EventTimer_GetReloadOrAlarmValue(const AQH_EVENT_TIMER *evt) -{ - return evt?evt->reloadOrAlarmValue:0; -} - - - -void AQH_EventTimer_SetReloadOrAlarmValue(AQH_EVENT_TIMER *evt, uint64_t i) -{ - if (evt) - evt->reloadOrAlarmValue=i; -} - - - -int AQH_EventTimer_GetEventType(const AQH_EVENT_TIMER *evt) -{ - return evt?evt->eventType:0; -} - - - -void AQH_EventTimer_SetEventType(AQH_EVENT_TIMER *evt, int i) -{ - if (evt) - evt->eventType=i; -} - - - -int AQH_EventTimer_CheckWhetherTickTriggers(AQH_EVENT_TIMER *evt, uint64_t t) -{ - if (evt && evt->flags & AQH_EVENT_TIMER_FLAGS_RUNNING) { - if (evt->timerType==AQH_EventTimerType_CountDown) { - if (evt->currentValue>0) { - evt->currentValue--; - if (evt->currentValue==0) { - if (evt->flags & AQH_EVENT_TIMER_FLAGS_RESTART) { - DBG_INFO(AQH_LOGDOMAIN, "Timer %lu expired, restarting", (unsigned long int) (evt->id)); - evt->currentValue=evt->reloadOrAlarmValue; - } - else { - DBG_INFO(AQH_LOGDOMAIN, "Timer %lu expired", (unsigned long int) (evt->id)); - evt->flags&=~AQH_EVENT_TIMER_FLAGS_RUNNING; - } - return 1; - } - } - } - else if (evt->timerType==AQH_EventTimerType_Alarm) { - if (t>=evt->reloadOrAlarmValue) { - evt->flags&=~AQH_EVENT_TIMER_FLAGS_RUNNING; - return 1; - } - } - else { - DBG_INFO(AQH_LOGDOMAIN, "Unknown timer type %d", evt->timerType); - } - } - - return 0; -} - - - - - - - diff --git a/aqhome/events/eventtimer.h b/aqhome/events/eventtimer.h deleted file mode 100644 index 61d11ab..0000000 --- a/aqhome/events/eventtimer.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** - * This file is part of the project Gwenhywfar. - * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_EVENT_TIMER_H -#define AQH_EVENT_TIMER_H - - -#include "aqhome/api.h" - -#include -#include - - -enum { - AQH_EventTimerType_CountDown=0, - AQH_EventTimerType_Alarm -}; - - -#define AQH_EVENT_TIMER_FLAGS_RUNNING 0x0001 -#define AQH_EVENT_TIMER_FLAGS_RESTART 0x0002 -#define AQH_EVENT_TIMER_FLAGS_DELETE_IF_TRIGGERED 0x0004 - - - -typedef struct AQH_EVENT_TIMER AQH_EVENT_TIMER; -GWEN_INHERIT_FUNCTION_LIB_DEFS(AQH_EVENT_TIMER, AQHOME_API) -GWEN_LIST_FUNCTION_LIB_DEFS(AQH_EVENT_TIMER, AQH_EventTimer, AQHOME_API) - - -AQHOME_API AQH_EVENT_TIMER *AQH_EventTimer_new(); -AQHOME_API void AQH_EventTimer_free(AQH_EVENT_TIMER *evt); - -AQHOME_API uint32_t AQH_EventTimer_GetFlags(const AQH_EVENT_TIMER *evt); -AQHOME_API void AQH_EventTimer_SetFlags(AQH_EVENT_TIMER *evt, uint32_t f); -AQHOME_API void AQH_EventTimer_AddFlags(AQH_EVENT_TIMER *evt, uint32_t f); -AQHOME_API void AQH_EventTimer_SubFlags(AQH_EVENT_TIMER *evt, uint32_t f); - -AQHOME_API int AQH_EventTimer_GetTimerType(const AQH_EVENT_TIMER *evt); -AQHOME_API void AQH_EventTimer_SetTimerType(AQH_EVENT_TIMER *evt, int i); - -AQHOME_API uint64_t AQH_EventTimer_GetId(const AQH_EVENT_TIMER *evt); -AQHOME_API void AQH_EventTimer_SetId(AQH_EVENT_TIMER *evt, uint64_t i); - -AQHOME_API uint64_t AQH_EventTimer_GetCurrentValue(const AQH_EVENT_TIMER *evt); -AQHOME_API void AQH_EventTimer_SetCurrentValue(AQH_EVENT_TIMER *evt, uint64_t i); - -AQHOME_API uint64_t AQH_EventTimer_GetReloadOrAlarmValue(const AQH_EVENT_TIMER *evt); -AQHOME_API void AQH_EventTimer_SetReloadOrAlarmValue(AQH_EVENT_TIMER *evt, uint64_t i); - -AQHOME_API int AQH_EventTimer_GetEventType(const AQH_EVENT_TIMER *evt); -AQHOME_API void AQH_EventTimer_SetEventType(AQH_EVENT_TIMER *evt, int i); - - -AQHOME_API int AQH_EventTimer_CheckWhetherTickTriggers(AQH_EVENT_TIMER *evt, uint64_t t); - - -#endif - - diff --git a/aqhome/events/eventtimer_p.h b/aqhome/events/eventtimer_p.h deleted file mode 100644 index 329425d..0000000 --- a/aqhome/events/eventtimer_p.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - * This file is part of the project Gwenhywfar. - * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_EVENT_TIMER_P_H -#define AQH_EVENT_TIMER_P_H - - -#include "aqhome/events/eventtimer.h" - - - -struct AQH_EVENT_TIMER { - GWEN_INHERIT_ELEMENT(AQH_EVENT_TIMER) - GWEN_LIST_ELEMENT(AQH_EVENT_TIMER) - - uint32_t flags; - int timerType; - uint64_t id; - uint64_t currentValue; - uint64_t reloadOrAlarmValue; - - int eventType; -}; - - - -#endif - - diff --git a/aqhome/http/0BUILD b/aqhome/http/0BUILD deleted file mode 100644 index 8695dd0..0000000 --- a/aqhome/http/0BUILD +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - $(gwenhywfar_cflags) - -I$(topsrcdir) - -I$(topbuilddir) - - - - --include=$(builddir) - --include=$(srcdir) - - - - - - $(visibility_cflags) - - - - --api=AQHOME_API - - - - - - - - - - - - - - - - - - $(local/built_headers_pub) - - - - - endpoint_http.h - httpservice.h - httpservice_conf.h - httpservice_http.h - httprequest.h - urlhandler.h - content.h - content_files.h - - - - - endpoint_http_p.h - httpservice_p.h - httprequest_p.h - urlhandler_p.h - content_p.h - content_files_p.h - - - - - $(local/typefiles) - - endpoint_http.c - httpservice.c - httpservice_conf.c - httpservice_http.c - httprequest.c - urlhandler.c - content.c - content_files.c - - - - - - - - - - - - - - - - diff --git a/aqhome/http/content.c b/aqhome/http/content.c deleted file mode 100644 index ea9a254..0000000 --- a/aqhome/http/content.c +++ /dev/null @@ -1,117 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -//#define DISABLE_DEBUGLOG - - -#include "aqhome/http/content_p.h" - -#include - - - - -GWEN_INHERIT_FUNCTIONS(AQH_HTTP_CONTENT) -GWEN_TREE2_FUNCTIONS(AQH_HTTP_CONTENT, AQH_HttpContent) - - - - - -AQH_HTTP_CONTENT *AQH_HttpContent_new(const char *name) -{ - AQH_HTTP_CONTENT *cp; - - GWEN_NEW_OBJECT(AQH_HTTP_CONTENT, cp); - GWEN_INHERIT_INIT(AQH_HTTP_CONTENT, cp); - GWEN_TREE2_INIT(AQH_HTTP_CONTENT, cp, AQH_HttpContent); - - cp->name=name?strdup(name):NULL; - - return cp; -} - - - -void AQH_HttpContent_free(AQH_HTTP_CONTENT *cp) -{ - if (cp) { - GWEN_TREE2_FINI(AQH_HTTP_CONTENT, cp, AQH_HttpContent); - GWEN_INHERIT_FINI(AQH_HTTP_CONTENT, cp); - - free(cp->name); - - GWEN_FREE_OBJECT(cp); - } -} - - - -const char *AQH_HttpContent_GetName(const AQH_HTTP_CONTENT *cp) -{ - return cp?cp->name:NULL; -} - - - -int AQH_HttpContent_AddOpeningContent(AQH_HTTP_CONTENT *cp, int mode, GWEN_BUFFER *buffer) -{ - return (cp && cp->addOpeningContentFn)?(cp->addOpeningContentFn(cp, mode, buffer)):0; -} - - - -int AQH_HttpContent_AddClosingContent(AQH_HTTP_CONTENT *cp, int mode, GWEN_BUFFER *buffer) -{ - return (cp && cp->addClosingContentFn)?(cp->addClosingContentFn(cp, mode, buffer)):0; -} - - - -void AQH_HttpContent_SetAddOpeningContentFn(AQH_HTTP_CONTENT *cp, AQH_HTTP_CONTENT_ADD_OPENING_CONTENT_FN f) -{ - if (cp) - cp->addOpeningContentFn=f; -} - - - -void AQH_HttpContent_SetAddClosingContentFn(AQH_HTTP_CONTENT *cp, AQH_HTTP_CONTENT_ADD_CLOSING_CONTENT_FN f) -{ - if (cp) - cp->addClosingContentFn=f; -} - - - -AQH_HTTP_CONTENT *AQH_HttpContent_Tree2_FindChildByName(AQH_HTTP_CONTENT *parent, const char *name) -{ - if (parent) { - AQH_HTTP_CONTENT *c; - - c=AQH_HttpContent_Tree2_GetFirstChild(parent); - while(c) { - const char *s; - - s=AQH_HttpContent_GetName(c); - if (s && *s && strcasecmp(s, name)==0) - return c; - c=AQH_HttpContent_Tree2_GetNext(c); - } - } - - return NULL; -} - - - - diff --git a/aqhome/http/content.h b/aqhome/http/content.h deleted file mode 100644 index d6adfa9..0000000 --- a/aqhome/http/content.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQHOME_HTTP_CONTENT_H -#define AQHOME_HTTP_CONTENT_H - - -#include - -#include -#include -#include - - -#define AQH_HTTP_CONTENT_MODE_DESKTOP 0 -#define AQH_HTTP_CONTENT_MODE_MOBILE 1 - - - -#ifdef __cplusplus -extern "C" { -#endif - - - -typedef struct AQH_HTTP_CONTENT AQH_HTTP_CONTENT; -GWEN_INHERIT_FUNCTION_LIB_DEFS(AQH_HTTP_CONTENT, AQHOME_API) -GWEN_TREE2_FUNCTION_LIB_DEFS(AQH_HTTP_CONTENT, AQH_HttpContent, AQHOME_API) - - -typedef int (*AQH_HTTP_CONTENT_ADD_OPENING_CONTENT_FN)(AQH_HTTP_CONTENT *cp, int mode, GWEN_BUFFER *buffer); -typedef int (*AQH_HTTP_CONTENT_ADD_CLOSING_CONTENT_FN)(AQH_HTTP_CONTENT *cp, int mode, GWEN_BUFFER *buffer); - - -AQHOME_API AQH_HTTP_CONTENT *AQH_HttpContent_new(const char *name); -AQHOME_API void AQH_HttpContent_free(AQH_HTTP_CONTENT *cp); - -AQHOME_API const char *AQH_HttpContent_GetName(const AQH_HTTP_CONTENT *cp); - - -AQHOME_API int AQH_HttpContent_AddOpeningContent(AQH_HTTP_CONTENT *cp, int mode, GWEN_BUFFER *buffer); -AQHOME_API int AQH_HttpContent_AddClosingContent(AQH_HTTP_CONTENT *cp, int mode, GWEN_BUFFER *buffer); - - -AQHOME_API void AQH_HttpContent_SetAddOpeningContentFn(AQH_HTTP_CONTENT *cp, AQH_HTTP_CONTENT_ADD_OPENING_CONTENT_FN f); -AQHOME_API void AQH_HttpContent_SetAddClosingContentFn(AQH_HTTP_CONTENT *cp, AQH_HTTP_CONTENT_ADD_CLOSING_CONTENT_FN f); - -AQHOME_API AQH_HTTP_CONTENT *AQH_HttpContent_Tree2_FindChildByName(AQH_HTTP_CONTENT *parent, const char *name); - - -#ifdef __cplusplus -} -#endif - - - -#endif - diff --git a/aqhome/http/content_files.c b/aqhome/http/content_files.c deleted file mode 100644 index 7f50c08..0000000 --- a/aqhome/http/content_files.c +++ /dev/null @@ -1,143 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -//#define DISABLE_DEBUGLOG - - -#include "aqhome/http/content_files_p.h" - -#include -#include - - - -GWEN_INHERIT(AQH_HTTP_CONTENT, AQH_HTTP_CONTENT_FILES) - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static void _freeData(void *bp, void *p); -static int _addOpeningContent(AQH_HTTP_CONTENT *cp, int mode, GWEN_BUFFER *buffer); -static int _addClosingContent(AQH_HTTP_CONTENT *cp, int mode, GWEN_BUFFER *buffer); - - - -/* ------------------------------------------------------------------------------------------------ - * implementations - * ------------------------------------------------------------------------------------------------ - */ - -AQH_HTTP_CONTENT *AQH_HttpContentFiles_new(const char *name, const char *headerFilename, const char *footerFilename) -{ - AQH_HTTP_CONTENT *cp; - AQH_HTTP_CONTENT_FILES *xcp; - - cp=AQH_HttpContent_new(name); - GWEN_NEW_OBJECT(AQH_HTTP_CONTENT_FILES, xcp); - GWEN_INHERIT_SETDATA(AQH_HTTP_CONTENT, AQH_HTTP_CONTENT_FILES, cp, xcp, _freeData); - - xcp->headerFilename=(headerFilename && *headerFilename)?strdup(headerFilename):NULL; - xcp->footerFilename=(footerFilename && *footerFilename)?strdup(footerFilename):NULL; - - AQH_HttpContent_SetAddOpeningContentFn(cp, _addOpeningContent); - AQH_HttpContent_SetAddClosingContentFn(cp, _addClosingContent); - - return cp; -} - - - -void _freeData(void *bp, void *p) -{ - AQH_HTTP_CONTENT_FILES *xcp; - - xcp=(AQH_HTTP_CONTENT_FILES*) p; - - free(xcp->footerData); - free(xcp->headerData); - - free(xcp->footerFilename); - free(xcp->headerFilename); - GWEN_FREE_OBJECT(xcp); -} - - - -int _addOpeningContent(AQH_HTTP_CONTENT *cp, int mode, GWEN_BUFFER *buffer) -{ - if (cp) { - AQH_HTTP_CONTENT_FILES *xcp; - - xcp=GWEN_INHERIT_GETDATA(AQH_HTTP_CONTENT, AQH_HTTP_CONTENT_FILES, cp); - if (xcp) { - if (xcp->headerData==NULL) { - if (xcp->headerFilename) { - int rv; - GWEN_BUFFER *fileBuffer; - - fileBuffer=GWEN_Buffer_new(0, 256, 0, 1); - rv=GWEN_SyncIo_Helper_ReadFile(xcp->headerFilename, fileBuffer); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error reading header file \"%s\": %d", xcp->headerFilename, rv); - GWEN_Buffer_free(fileBuffer); - return rv; - } - xcp->headerData=strdup(GWEN_Buffer_GetStart(fileBuffer)); - GWEN_Buffer_free(fileBuffer); - } - } - if (xcp->headerData) - GWEN_Buffer_AppendString(buffer, xcp->headerData); - } - } - - return 0; -} - - - -int _addClosingContent(AQH_HTTP_CONTENT *cp, int mode, GWEN_BUFFER *buffer) -{ - if (cp) { - AQH_HTTP_CONTENT_FILES *xcp; - - xcp=GWEN_INHERIT_GETDATA(AQH_HTTP_CONTENT, AQH_HTTP_CONTENT_FILES, cp); - if (xcp) { - if (xcp->footerData==NULL) { - if (xcp->footerFilename) { - int rv; - GWEN_BUFFER *fileBuffer; - - fileBuffer=GWEN_Buffer_new(0, 256, 0, 1); - rv=GWEN_SyncIo_Helper_ReadFile(xcp->footerFilename, fileBuffer); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error reading footer file \"%s\": %d", xcp->footerFilename, rv); - GWEN_Buffer_free(fileBuffer); - return rv; - } - xcp->footerData=strdup(GWEN_Buffer_GetStart(fileBuffer)); - GWEN_Buffer_free(fileBuffer); - } - if (xcp->footerData) - GWEN_Buffer_AppendString(buffer, xcp->footerData); - } - } - } - - return 0; -} - - - diff --git a/aqhome/http/content_files.h b/aqhome/http/content_files.h deleted file mode 100644 index aeef760..0000000 --- a/aqhome/http/content_files.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQHOME_HTTP_CONTENT_FILES_H -#define AQHOME_HTTP_CONTENT_FILES_H - - -#include -#include - - - -#ifdef __cplusplus -extern "C" { -#endif - - - -AQHOME_API AQH_HTTP_CONTENT *AQH_HttpContentFiles_new(const char *name, const char *headerFilename, const char *footerFilename); - - - -#ifdef __cplusplus -} -#endif - - - -#endif diff --git a/aqhome/http/content_files_p.h b/aqhome/http/content_files_p.h deleted file mode 100644 index 9c3487d..0000000 --- a/aqhome/http/content_files_p.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQHOME_HTTP_CONTENT_FILES_P_H -#define AQHOME_HTTP_CONTENT_FILES_P_H - - -#include "aqhome/http/content_files.h" - - - -typedef struct AQH_HTTP_CONTENT_FILES AQH_HTTP_CONTENT_FILES; -struct AQH_HTTP_CONTENT_FILES { - char *headerFilename; - char *footerFilename; - - char *headerData; - char *footerData; -}; - - - -#endif - diff --git a/aqhome/http/content_p.h b/aqhome/http/content_p.h deleted file mode 100644 index 1553449..0000000 --- a/aqhome/http/content_p.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQHOME_HTTP_CONTENT_P_H -#define AQHOME_HTTP_CONTENT_P_H - - -#include "aqhome/http/content.h" - - -struct AQH_HTTP_CONTENT { - GWEN_INHERIT_ELEMENT(AQH_HTTP_CONTENT); - GWEN_TREE2_ELEMENT(AQH_HTTP_CONTENT); - - char *name; - AQH_HTTP_CONTENT_ADD_OPENING_CONTENT_FN addOpeningContentFn; - AQH_HTTP_CONTENT_ADD_CLOSING_CONTENT_FN addClosingContentFn; -}; - - - - -#endif - diff --git a/aqhome/http/endpoint_http.c b/aqhome/http/endpoint_http.c deleted file mode 100644 index 3cdd296..0000000 --- a/aqhome/http/endpoint_http.c +++ /dev/null @@ -1,661 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -//#define DISABLE_DEBUGLOG - - -#include "aqhome/http/endpoint_http_p.h" - - -#include -#include - -#include -#include -#include - - - -#define AQH_ENDPOINT_HTTP_NAME "http" -#define AQH_ENDPOINT_HTTP_BUFFERSIZE 1024 - -#define AQH_ENDPOINT_HTTP_BOOKMARK_HEADER 0 -#define AQH_ENDPOINT_HTTP_BOOKMARK_BODY 1 - - - -GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP) - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static void GWENHYWFAR_CB _freeData(void *bp, void *p); -static void _addSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_UNUSED GWEN_SOCKETSET *xSet); -static void _checkSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet); -static int _writeCurrentMessage(GWEN_MSG_ENDPOINT *ep); -static int _readCurrentMessage(GWEN_MSG_ENDPOINT *ep); -static int _distributeBufferContent(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPtr, int bufferLen); -static int _distributeBufferInCommandMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPtr, int bufferLen); -static int _distributeBufferInStatusMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPtr, int bufferLen); -static int _distributeBufferInHeaderMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPtr, int bufferLen); -static int _distributeBufferInBodyMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPtr, int bufferLen); -static int _distributeBufferAsLine(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPtr, int bufferLen); -static void _finishMessageAndStartNext(GWEN_MSG_ENDPOINT *ep); -static void _abortMessage(GWEN_MSG_ENDPOINT *ep); -static int _parseHeader(char *bufferPtr, GWEN_DB_NODE *db); -static int _parseCommand(const char *buffer, GWEN_DB_NODE *db); - - - -/* ------------------------------------------------------------------------------------------------ - * implementations - * ------------------------------------------------------------------------------------------------ - */ - -void AQH_HttpEndpoint_Extend(GWEN_MSG_ENDPOINT *ep, uint32_t flags) -{ - if (ep) { - AQH_ENDPOINT_HTTP *xep; - - GWEN_NEW_OBJECT(AQH_ENDPOINT_HTTP, xep); - GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep, xep, _freeData); - xep->readMode=AQH_EndpointHttpd_ReadMode_Command; - xep->flags=flags; - - xep->addSocketsFn=GWEN_MsgEndpoint_SetAddSocketsFn(ep, _addSockets); - xep->checkSocketsFn=GWEN_MsgEndpoint_SetCheckSocketsFn(ep, _checkSockets); - } -} - - - -void _freeData(void *bp, void *p) -{ - AQH_ENDPOINT_HTTP *xep; - - xep=(AQH_ENDPOINT_HTTP*) p; - - GWEN_DB_Group_free(xep->dbCurrentReadHeader); - GWEN_DB_Group_free(xep->dbCurrentReadCommand); - GWEN_Buffer_free(xep->currentReadBuffer); - - GWEN_FREE_OBJECT(xep); -} - - - -void _addSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_UNUSED GWEN_SOCKETSET *xSet) -{ - if (ep) { - AQH_ENDPOINT_HTTP *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep); - if (xep) { - if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) { - GWEN_SOCKET *sk; - - sk=GWEN_MsgEndpoint_GetSocket(ep); - if (sk) { - DBG_DEBUG(AQH_LOGDOMAIN, "Endpoint %s: Adding socket %d to read set", - GWEN_MsgEndpoint_GetName(ep), - GWEN_Socket_GetSocketInt(sk)); - GWEN_SocketSet_AddSocket(readSet, sk); - if (GWEN_MsgEndpoint_HaveMessageToSend(ep)) { - DBG_DEBUG(AQH_LOGDOMAIN, "Endpoint %s: Adding socket %d to write set", - GWEN_MsgEndpoint_GetName(ep), - GWEN_Socket_GetSocketInt(sk)); - GWEN_SocketSet_AddSocket(writeSet, sk); - } - } /* if socket */ - } - else if (xep->addSocketsFn) { - DBG_DEBUG(AQH_LOGDOMAIN, "Endpoint %s: Not connected, calling base function", GWEN_MsgEndpoint_GetName(ep)); - xep->addSocketsFn(ep, readSet, writeSet, xSet); - } - } /* if (xep) */ - } /* if (ep) */ -} - - - -void _checkSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet) -{ - if (ep) { - AQH_ENDPOINT_HTTP *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep); - if (xep) { - int rv; - - if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) { - GWEN_SOCKET *sk; - - sk=GWEN_MsgEndpoint_GetSocket(ep); - if (sk) { - if (GWEN_SocketSet_HasSocket(writeSet, sk)) { - DBG_DEBUG(AQH_LOGDOMAIN, "Endpoint %s: Has socket in write set", GWEN_MsgEndpoint_GetName(ep)); - rv=_writeCurrentMessage(ep); - if (rv<0 && rv!=GWEN_ERROR_TIMEOUT) { - DBG_INFO(AQH_LOGDOMAIN, - "Endpoint %s: Error writing current message (%d), disconnecting", - GWEN_MsgEndpoint_GetName(ep), - rv); - _abortMessage(ep); - GWEN_MsgEndpoint_Disconnect(ep); - return; - } - } - - if (GWEN_SocketSet_HasSocket(readSet, sk)) { - DBG_DEBUG(AQH_LOGDOMAIN, "Endpoint %s: Has socket in read set", GWEN_MsgEndpoint_GetName(ep)); - rv=_readCurrentMessage(ep); - if (rv<0 && rv!=GWEN_ERROR_TIMEOUT) { - DBG_INFO(AQH_LOGDOMAIN, - "Endpoint %s: Error reading current message (%d), disconnecting", - GWEN_MsgEndpoint_GetName(ep), - rv); - _abortMessage(ep); - GWEN_MsgEndpoint_Disconnect(ep); - return; - } - } - } - } /* if connected */ - else if (xep->checkSocketsFn) { - DBG_DEBUG(AQH_LOGDOMAIN, "Endpoint %s: Not connected, calling base function", GWEN_MsgEndpoint_GetName(ep)); - xep->checkSocketsFn(ep, readSet, writeSet, xSet); - } - } - } -} - - - -int _writeCurrentMessage(GWEN_MSG_ENDPOINT *ep) -{ - GWEN_MSG *msg; - - DBG_DEBUG(AQH_LOGDOMAIN, "Writing to endpoint %s", GWEN_MsgEndpoint_GetName(ep)); - msg=GWEN_MsgEndpoint_GetFirstSendMessage(ep); - if (msg) { - uint8_t pos; - int remaining; - int rv; - - pos=GWEN_Msg_GetCurrentPos(msg); - remaining=GWEN_Msg_GetRemainingBytes(msg); - if (remaining>0) { - const uint8_t *buf; - - /* start new message */ - buf=GWEN_Msg_GetBuffer(msg)+pos; - rv=GWEN_MsgEndpoint_WriteToSocket(ep, buf, remaining); - if (rv<0) { - if (rv==GWEN_ERROR_TIMEOUT) - return rv; - DBG_ERROR(AQH_LOGDOMAIN, "Error on write() (%d)", rv); - return rv; - } - GWEN_Msg_IncCurrentPos(msg, rv); - if (rv==remaining) { - DBG_DEBUG(AQH_LOGDOMAIN, "Message completely sent"); - /* end current message */ - GWEN_Msg_List_Del(msg); - GWEN_Msg_free(msg); - } - } - } - else { - DBG_DEBUG(AQH_LOGDOMAIN, "Nothing to send"); - } - return 0; -} - - - - -int _readCurrentMessage(GWEN_MSG_ENDPOINT *ep) -{ - int rv; - uint8_t buffer[AQH_ENDPOINT_HTTP_BUFFERSIZE]; - - DBG_DEBUG(AQH_LOGDOMAIN, "Reading from endpoint %s", GWEN_MsgEndpoint_GetName(ep)); - rv=GWEN_MsgEndpoint_ReadFromSocket(ep, buffer, sizeof(buffer)); - if (rv<0 && rv!=GWEN_ERROR_TIMEOUT) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - else if (rv==0) { - DBG_INFO(AQH_LOGDOMAIN, "EOF met on read()"); - return GWEN_ERROR_IO; - } - - rv=_distributeBufferContent(ep, buffer, rv); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - return 0; -} - - - -int _distributeBufferContent(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPtr, int bufferLen) -{ - if (ep) { - AQH_ENDPOINT_HTTP *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep); - if (xep) { - int rv; - if (xep->currentReadBuffer==NULL) - xep->currentReadBuffer=GWEN_Buffer_new(0, 256, 0, 1); - - while(bufferLen) { - switch(xep->readMode) { - case AQH_EndpointHttpd_ReadMode_Command: - rv=_distributeBufferInCommandMode(ep, bufferPtr, bufferLen); - break; - case AQH_EndpointHttpd_ReadMode_Status: - rv=_distributeBufferInStatusMode(ep, bufferPtr, bufferLen); - break; - case AQH_EndpointHttpd_ReadMode_Headers: - rv=_distributeBufferInHeaderMode(ep, bufferPtr, bufferLen); - break; - case AQH_EndpointHttpd_ReadMode_Body: - rv=_distributeBufferInBodyMode(ep, bufferPtr, bufferLen); - break; - default: - DBG_ERROR(AQH_LOGDOMAIN, "Invalid read mode %d", xep->readMode); - return GWEN_ERROR_GENERIC; - } - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - else if (rv==0) { - DBG_INFO(AQH_LOGDOMAIN, "No bytes used? SNH!"); - return GWEN_ERROR_INTERNAL; - } - bufferPtr+=rv; - bufferLen-=rv; - } /* while */ - return 0; - } /* if (xep) */ - } /* if (ep) */ - return GWEN_ERROR_GENERIC; -} - - - -int _distributeBufferInCommandMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPtr, int bufferLen) -{ - int rv; - - rv=_distributeBufferAsLine(ep, bufferPtr, bufferLen); - if (rv<0) { - AQH_ENDPOINT_HTTP *xep; - const char *s; - - /* line complete */ - DBG_DEBUG(AQH_LOGDOMAIN, "Command line complete"); - rv=-rv; - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep); - - xep->dbCurrentReadCommand=GWEN_DB_Group_new("command"); - - if (_parseCommand(GWEN_Buffer_GetStart(xep->currentReadBuffer), xep->dbCurrentReadCommand)<0) { - DBG_INFO(AQH_LOGDOMAIN, "Error parsing command line [%s]", GWEN_Buffer_GetStart(xep->currentReadBuffer)); - return GWEN_ERROR_BAD_DATA; - } - DBG_DEBUG(AQH_LOGDOMAIN, "Command line received: %s", GWEN_Buffer_GetStart(xep->currentReadBuffer)); - s=GWEN_DB_GetCharValue(xep->dbCurrentReadCommand, "protocol", 0, "HTTP/0.9"); - if (s && *s && strcasecmp(s, "HTTP/0.9")==0) { - DBG_INFO(AQH_LOGDOMAIN, "HTTP 0.9, no header, message finished"); - _finishMessageAndStartNext(ep); - return rv; - } - DBG_DEBUG(AQH_LOGDOMAIN, - "Command line complete, advancing to header read mode (start: %d)", - GWEN_Buffer_GetPos(xep->currentReadBuffer)); - xep->readMode=AQH_EndpointHttpd_ReadMode_Headers; - xep->currentHeaderPos=GWEN_Buffer_GetPos(xep->currentReadBuffer); - } - else { - DBG_DEBUG(AQH_LOGDOMAIN, "Line not yet finished (%d)", rv); - } - - return rv; -} - - - -int _distributeBufferInStatusMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPtr, int bufferLen) -{ - int rv; - - rv=_distributeBufferAsLine(ep, bufferPtr, bufferLen); - if (rv<0) { - AQH_ENDPOINT_HTTP *xep; - - /* line complete, TODO: parse status/command line */ - rv=-rv; - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep); - DBG_DEBUG(AQH_LOGDOMAIN, "Line complete, advancing to header read mode"); - xep->readMode=AQH_EndpointHttpd_ReadMode_Headers; - xep->currentBodyPos=GWEN_Buffer_GetPos(xep->currentReadBuffer); - } - - return rv; -} - - - -int _distributeBufferInHeaderMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPtr, int bufferLen) -{ - int rv; - - rv=_distributeBufferAsLine(ep, bufferPtr, bufferLen); - if (rv<0) { - AQH_ENDPOINT_HTTP *xep; - int lineLength; - - /* line complete, parse status/command line */ - rv=-rv; - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep); - - lineLength=GWEN_Buffer_GetPos(xep->currentReadBuffer)-xep->lastLineStartPos; - xep->lastLineStartPos=GWEN_Buffer_GetPos(xep->currentReadBuffer); - if (lineLength==2) { - char *copyOfHeader; - int contentLength; - - /* Empty line received, TODO: parse header */ - DBG_DEBUG(AQH_LOGDOMAIN, "Empty header line received, end of header reached (header pos: %d).", xep->currentHeaderPos); - copyOfHeader=strdup(GWEN_Buffer_GetStart(xep->currentReadBuffer)+xep->currentHeaderPos); - xep->dbCurrentReadHeader=GWEN_DB_Group_new("header"); - if (_parseHeader(copyOfHeader, xep->dbCurrentReadHeader)<0) { - DBG_INFO(AQH_LOGDOMAIN, "Error parsing HTTP header"); - free(copyOfHeader); - return GWEN_ERROR_BAD_DATA; - } - free(copyOfHeader); - contentLength=GWEN_DB_GetIntValue(xep->dbCurrentReadHeader, "Content-Length", 0, -1); - if (contentLength==0 || contentLength==-1) { - DBG_DEBUG(AQH_LOGDOMAIN, "Message has no body, done"); - _finishMessageAndStartNext(ep); - } - else { - xep->currentBodyPos=GWEN_Buffer_GetPos(xep->currentReadBuffer); - xep->currentBodySize=contentLength; - xep->remainingBodySize=contentLength; - xep->readMode=AQH_EndpointHttpd_ReadMode_Body; - } - } - } - - return rv; -} - - - -int _distributeBufferInBodyMode(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPtr, int bufferLen) -{ - AQH_ENDPOINT_HTTP *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep); - if (xep->remainingBodySize>0) { - int len; - - len=bufferLen; - if (len>xep->remainingBodySize) - len=xep->remainingBodySize; - if (len) { - GWEN_Buffer_AppendBytes(xep->currentReadBuffer, (const char*) bufferPtr, len); - xep->remainingBodySize-=len; - if (xep->remainingBodySize==0) { - DBG_DEBUG(AQH_LOGDOMAIN, "Body completely received"); - _finishMessageAndStartNext(ep); - } - return len; - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "No bytes left to read, SNH!"); - return GWEN_ERROR_INTERNAL; - } - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "No body size, aborting"); - return GWEN_ERROR_GENERIC; - } -} - - - -/* return negative number of bytes handled when LF encountered (i.e. line done), positive value otherwise */ -int _distributeBufferAsLine(GWEN_MSG_ENDPOINT *ep, const uint8_t *bufferPtr, int bufferLen) -{ - AQH_ENDPOINT_HTTP *xep; - const char *s; - int i; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep); - - s=(const char*) bufferPtr; - i=0; - while(icurrentReadBuffer, (const char*) bufferPtr, i); - if (*s==10) { - DBG_DEBUG(AQH_LOGDOMAIN, "Received full line (added %d bytes from %d)", i, bufferLen); - i=-i; - } - return i; -} - - - -void _finishMessageAndStartNext(GWEN_MSG_ENDPOINT *ep) -{ - AQH_ENDPOINT_HTTP *xep; - GWEN_MSG *msg; - GWEN_DB_NODE *dbParsedData; - - DBG_DEBUG(AQH_LOGDOMAIN, "Message completely received."); - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep); - - msg=GWEN_Msg_fromBytes((const uint8_t*)GWEN_Buffer_GetStart(xep->currentReadBuffer), GWEN_Buffer_GetUsedBytes(xep->currentReadBuffer)); - if (xep->currentBodySize) { - GWEN_Msg_SetParsedPayloadOffset(msg, xep->currentBodyPos); - GWEN_Msg_SetParsedPayloadSize(msg, xep->currentBodySize); - } - dbParsedData=GWEN_DB_Group_new("parsedData"); - if (xep->dbCurrentReadCommand) - GWEN_DB_AddGroup(dbParsedData, xep->dbCurrentReadCommand); - if (xep->dbCurrentReadHeader) - GWEN_DB_AddGroup(dbParsedData, xep->dbCurrentReadHeader); - GWEN_Msg_SetDbParsedInfo(msg, dbParsedData); - - GWEN_MsgEndpoint_AddReceivedMessage(ep, msg); - - GWEN_Buffer_Reset(xep->currentReadBuffer); - xep->currentHeaderPos=0; - xep->currentBodyPos=0; - xep->currentBodySize=0; - xep->remainingBodySize=0; - xep->lastLineStartPos=0; - xep->dbCurrentReadCommand=NULL; - xep->dbCurrentReadHeader=NULL; - - if (xep->flags & AQH_ENDPOINT_HTTP_FLAGS_PASSIVE) { - DBG_DEBUG(AQH_LOGDOMAIN, "Passive connection"); - xep->readMode=AQH_EndpointHttpd_ReadMode_Command; - } - else { - DBG_DEBUG(AQH_LOGDOMAIN, "Active connection"); - xep->readMode=AQH_EndpointHttpd_ReadMode_Status; - } -} - - - -void _abortMessage(GWEN_MSG_ENDPOINT *ep) -{ - AQH_ENDPOINT_HTTP *xep; - - DBG_DEBUG(AQH_LOGDOMAIN, "Aborting message (if any)."); - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_HTTP, ep); - - if (xep->currentReadBuffer) - GWEN_Buffer_Reset(xep->currentReadBuffer); - xep->currentHeaderPos=0; - xep->currentBodyPos=0; - xep->currentBodySize=0; - xep->remainingBodySize=0; - xep->lastLineStartPos=0; - if (xep->dbCurrentReadCommand) - GWEN_DB_Group_free(xep->dbCurrentReadCommand); - xep->dbCurrentReadCommand=NULL; - if (xep->dbCurrentReadHeader) - GWEN_DB_Group_free(xep->dbCurrentReadHeader); - xep->dbCurrentReadHeader=NULL; - - xep->readMode=AQH_EndpointHttpd_ReadMode_Aborted; -} - - - -int _parseHeader(char *bufferPtr, GWEN_DB_NODE *db) -{ - char *p; - - /* resolve line continuations */ - p=bufferPtr; - while (*p) { - p=strchr(p, 10); - if (p) { - if (p[1]==32 || p[1]==9) - /* found a continuation */ - *p=32; - p++; - } - } - - /* parse every line */ - p=bufferPtr; - while (p && *p) { - char *pNext; - char *pVarBegin; - char *pVarEnd; - - /* find end of line */ - pNext=strchr(p, 13); - if (pNext) { - *pNext=0; - pNext++; - } - /* skip LF */ - if (*p==10) - p++; - while (*p && (*p==32 || *p==9)) - p++; - if (*p) { - pVarBegin=p; - while (*p && *p!=':' && *p>32 && *p<127) - p++; - pVarEnd=p; - if (*p!=':') { - DBG_INFO(AQH_LOGDOMAIN, "No separator after variable name in received header (var: [%s])", pVarBegin); - return GWEN_ERROR_BAD_DATA; - } - *pVarEnd=0; - p++; - - while (*p && (*p==32 || *p==9)) - p++; - if (*p) { - DBG_DEBUG(AQH_LOGDOMAIN, "Setting header variable: [%s] = [%s]", pVarBegin, p); - GWEN_DB_SetCharValue(db, GWEN_PATH_FLAGS_CREATE_VAR, pVarBegin, p); - } - } - p=pNext; - } - - return 0; -} - - - -int _parseCommand(const char *buffer, GWEN_DB_NODE *db) -{ - char *tmp; - char *p; - char *s; - - tmp=strdup(buffer); - /* get end of line (marked by CR/LF) */ - s=strchr(tmp, 13); - if (s) - *s=0; - s=tmp; - - /* read command */ - p=strchr(s, ' '); - if (!p) { - DBG_ERROR(AQH_LOGDOMAIN, "Bad format of HTTP request (%s)", buffer); - free(tmp); - return GWEN_ERROR_BAD_DATA; - } - *p=0; - p++; - - GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "command", s); - s=p; - - /* read URL */ - p=strchr(s, ' '); - if (!p) { - DBG_ERROR(AQH_LOGDOMAIN, "Bad format of HTTP request (%s)", buffer); - free(tmp); - return GWEN_ERROR_BAD_DATA; - } - *p=0; - p++; - - GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "url", s); - s=p; - - if (*s==0) { - /* no protocol information follows, so we assume HTTP/0.9 */ - DBG_ERROR(AQH_LOGDOMAIN, "Bad request (not in HTTP>=1.0)"); - free(tmp); - return GWEN_ERROR_BAD_DATA; - } - else { - GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "protocol", s); - } - - free(tmp); - return 0; -} - - - - - diff --git a/aqhome/http/endpoint_http.h b/aqhome/http/endpoint_http.h deleted file mode 100644 index 3e4cebf..0000000 --- a/aqhome/http/endpoint_http.h +++ /dev/null @@ -1,28 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_ENDPOINT_HTTP_H -#define AQH_ENDPOINT_HTTP_H - - -#include - -#include - - -#define AQH_ENDPOINT_HTTP_FLAGS_PASSIVE 0x0001 - - - -AQHOME_API void AQH_HttpEndpoint_Extend(GWEN_MSG_ENDPOINT *ep, uint32_t flags); - - - - -#endif - diff --git a/aqhome/http/endpoint_http_p.h b/aqhome/http/endpoint_http_p.h deleted file mode 100644 index 048c76f..0000000 --- a/aqhome/http/endpoint_http_p.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_ENDPOINT_HTTP_P_H -#define AQH_ENDPOINT_HTTP_P_H - - - -#include "aqhome/http/endpoint_http.h" - -#include -#include - - - -enum { - AQH_EndpointHttpd_ReadMode_Aborted=-1, - AQH_EndpointHttpd_ReadMode_Command=0, - AQH_EndpointHttpd_ReadMode_Status, - AQH_EndpointHttpd_ReadMode_Headers, - AQH_EndpointHttpd_ReadMode_Body -}; - - - -typedef struct AQH_ENDPOINT_HTTP AQH_ENDPOINT_HTTP; -struct AQH_ENDPOINT_HTTP { - int readMode; - - uint32_t flags; - - GWEN_MSG_ENDPOINT_ADDSOCKETS_FN addSocketsFn; - GWEN_MSG_ENDPOINT_CHECKSOCKETS_FN checkSocketsFn; - - GWEN_BUFFER *currentReadBuffer; - GWEN_DB_NODE *dbCurrentReadCommand; - GWEN_DB_NODE *dbCurrentReadHeader; - int currentHeaderPos; - int currentBodyPos; - int currentBodySize; - int remainingBodySize; - int lastLineStartPos; -}; - - - -#endif - diff --git a/aqhome/http/httprequest.c b/aqhome/http/httprequest.c deleted file mode 100644 index ed4537b..0000000 --- a/aqhome/http/httprequest.c +++ /dev/null @@ -1,730 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -//#define DISABLE_DEBUGLOG - - -#include "./httprequest_p.h" - -#include -#include - -#include - - -GWEN_TREE2_FUNCTIONS(AQH_HTTP_REQUEST, AQH_HttpRequest); - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static int _getParsedDbInfo(AQH_HTTP_REQUEST *rq, const GWEN_MSG *msg); -static int _inspectReceivedMessage(AQH_HTTP_REQUEST *rq, const GWEN_MSG *msg); -static int _inspectMsgCommand(AQH_HTTP_REQUEST *rq, const GWEN_MSG *msg); -static void _inspectMsgHeader(AQH_HTTP_REQUEST *rq, const GWEN_MSG *msg); -static int _inspectMsgBody(AQH_HTTP_REQUEST *rq, const GWEN_MSG *msg); -static GWEN_DB_NODE *_extractCookies(GWEN_DB_NODE *dbHeader); -static void _setCookieValue(GWEN_DB_NODE *dbCookies, - const char *nameStart, int nameLen, - const char *valueStart, int valueLen, - uint32_t dbFlags); -static int _parsePostBody(const char *s, int contentLength, GWEN_DB_NODE *dbBody); -static int _unescapeUrlEncoded(const char *src, unsigned int srclen, char *buffer, unsigned int maxsize); - - - -/* ------------------------------------------------------------------------------------------------ - * implementations - * ------------------------------------------------------------------------------------------------ - */ - -AQH_HTTP_REQUEST *AQH_HttpRequest_new(GWEN_MSG_ENDPOINT *endpoint, const GWEN_MSG *receivedMsg) -{ - AQH_HTTP_REQUEST *rq; - int rv; - - GWEN_NEW_OBJECT(AQH_HTTP_REQUEST, rq); - GWEN_TREE2_INIT(AQH_HTTP_REQUEST, rq, AQH_HttpRequest); - - rq->endpoint=endpoint; - rq->receivedMsg=receivedMsg; - - rv=_inspectReceivedMessage(rq, receivedMsg); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - AQH_HttpRequest_free(rq); - return NULL; - } - return rq; -} - - - -void AQH_HttpRequest_free(AQH_HTTP_REQUEST *rq) -{ - if (rq) { - GWEN_TREE2_FINI(AQH_HTTP_REQUEST, rq, AQH_HttpRequest); - free(rq->sessionId); - free(rq->moduleName); - free(rq->responseText); - GWEN_Msg_free(rq->responseMsg); - GWEN_StringList_free(rq->urlPathMembers); - GWEN_Url_free(rq->url); - GWEN_DB_Group_free(rq->dbPostBody); - - GWEN_FREE_OBJECT(rq); - } -} - - - -GWEN_MSG_ENDPOINT *AQH_HttpRequest_GetEndpoint(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->endpoint):NULL; -} - - - -const GWEN_MSG *AQH_HttpRequest_GetReceivedMsg(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->receivedMsg):NULL; -} - - - -const char *AQH_HttpRequest_GetCommand(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->command):NULL; -} - - - -const char *AQH_HttpRequest_GetProtocol(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->protocol):NULL; -} - - - -GWEN_URL *AQH_HttpRequest_GetUrl(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->url):NULL; -} - - - -void AQH_HttpRequest_SetUrl(AQH_HTTP_REQUEST *rq, GWEN_URL *url) -{ - if (rq) { - GWEN_Url_free(rq->url); - rq->url=url; - } -} - - - -const char *AQH_HttpRequest_GetUrlPath(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->urlPath):NULL; -} - - - -GWEN_STRINGLIST *AQH_HttpRequest_GetUrlPathMembers(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->urlPathMembers):NULL; -} - - - -void AQH_HttpRequest_SetUrlPathMembers(AQH_HTTP_REQUEST *rq, GWEN_STRINGLIST *sl) -{ - if (rq) { - GWEN_StringList_free(rq->urlPathMembers); - rq->urlPathMembers=sl; - } -} - - - -GWEN_DB_NODE *AQH_HttpRequest_GetDbCommand(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->dbCommand):NULL; -} - - - -GWEN_DB_NODE *AQH_HttpRequest_GetDbHeader(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->dbHeader):NULL; -} - - - -GWEN_DB_NODE *AQH_HttpRequest_GetDbCookies(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->dbCookies):NULL; -} - - - -GWEN_DB_NODE *AQH_HttpRequest_GetDbPostBody(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->dbPostBody):NULL; -} - - - -const char *AQH_HttpRequest_GetSessionId(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->sessionId):NULL; -} - - - -void AQH_HttpRequest_SetSessionId(AQH_HTTP_REQUEST *rq, const char *s) -{ - if (rq) { - free(rq->sessionId); - rq->sessionId=s?strdup(s):NULL; - } -} - - - -const char *AQH_HttpRequest_GetModuleName(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->moduleName):NULL; -} - - - -void AQH_HttpRequest_SetModuleName(AQH_HTTP_REQUEST *rq, const char *s) -{ - if (rq) { - free(rq->moduleName); - rq->moduleName=s?strdup(s):NULL; - } -} - - - -AQH_SESSION *AQH_HttpRequest_GetSession(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->session):NULL; -} - - - -void AQH_HttpRequest_SetSession(AQH_HTTP_REQUEST *rq, AQH_SESSION *session) -{ - if (rq) - rq->session=session; -} - - - -AQH_MODULE *AQH_HttpRequest_GetModule(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->module):NULL; -} - - - -void AQH_HttpRequest_SetModule(AQH_HTTP_REQUEST *rq, AQH_MODULE *m) -{ - if (rq) - rq->module=m; -} - - - -uint32_t AQH_HttpRequest_GetModulePerms(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->modulePerms):0; -} - - - -void AQH_HttpRequest_SetModulePerms(AQH_HTTP_REQUEST *rq, uint32_t i) -{ - if (rq) - rq->modulePerms=i; -} - - - -int AQH_HttpRequest_GetResponseCode(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->responseCode):0; -} - - - -void AQH_HttpRequest_SetResponseCode(AQH_HTTP_REQUEST *rq, int i) -{ - if (rq) - rq->responseCode=i; -} - - - -const char *AQH_HttpRequest_GetResponseText(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->responseText):NULL; -} - - - -void AQH_HttpRequest_SetResponseText(AQH_HTTP_REQUEST *rq, const char *s) -{ - if (rq) { - free(rq->responseText); - rq->responseText=s?strdup(s):NULL; - } -} - - - -GWEN_MSG *AQH_HttpRequest_GetResponseMsg(const AQH_HTTP_REQUEST *rq) -{ - return rq?(rq->responseMsg):NULL; -} - - - -GWEN_MSG *AQH_HttpRequest_TakeResponseMsg(AQH_HTTP_REQUEST *rq) -{ - if (rq) { - GWEN_MSG *msg; - - msg=rq->responseMsg; - rq->responseMsg=NULL; - return msg; - } - return NULL; -} - - - -void AQH_HttpRequest_SetResponseMsg(AQH_HTTP_REQUEST *rq, GWEN_MSG *msg) -{ - if (rq && msg) { - GWEN_Msg_free(rq->responseMsg); - rq->responseMsg=msg; - } -} - - - -void AQH_HttpRequest_SetupUrlPathMembers(AQH_HTTP_REQUEST *rq) -{ - const char *path; - - path=AQH_HttpRequest_GetUrlPath(rq); - if (path && *path) { - GWEN_STRINGLIST *sl; - - if (*path=='/') /* skip leading slash */ - path++; - sl=GWEN_StringList_fromString(path, "/", 0); - if (sl==NULL) { - DBG_ERROR(NULL, "Empty url path member list"); - } - else - AQH_HttpRequest_SetUrlPathMembers(rq, sl); - } -} - - - -int _inspectReceivedMessage(AQH_HTTP_REQUEST *rq, const GWEN_MSG *msg) -{ - int rv; - - rv=_getParsedDbInfo(rq, msg); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - rv=_inspectMsgCommand(rq, msg); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - _inspectMsgHeader(rq, msg); - - rv=_inspectMsgBody(rq, msg); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - return 0; -} - - - -int _getParsedDbInfo(AQH_HTTP_REQUEST *rq, const GWEN_MSG *msg) -{ - GWEN_DB_NODE *dbParsedInfo; - GWEN_DB_NODE *db; - - dbParsedInfo=GWEN_Msg_GetDbParsedInfo(msg); - if (dbParsedInfo==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "No parsed info db, msg probably not generated by HTTP endpoint module"); - return GWEN_ERROR_GENERIC; - } - - db=GWEN_DB_GetGroup(dbParsedInfo, GWEN_PATH_FLAGS_PATHMUSTEXIST, "command"); - if (db==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "No parsed command db, msg probably not generated by HTTP endpoint module"); - return GWEN_ERROR_GENERIC; - } - rq->dbCommand=db; - - db=GWEN_DB_GetGroup(dbParsedInfo, GWEN_PATH_FLAGS_PATHMUSTEXIST, "header"); - if (db==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "No parsed header db, msg probably not generated by HTTP endpoint module or no header recvd, ignoring"); - } - rq->dbHeader=db; - - return 0; -} - - - -int _inspectMsgCommand(AQH_HTTP_REQUEST *rq, const GWEN_MSG *msg) -{ - const char *s; - - s=GWEN_DB_GetCharValue(rq->dbCommand, "command", 0, NULL); - if (!(s && *s)) { - DBG_ERROR(AQH_LOGDOMAIN, "No command in request"); - return GWEN_ERROR_GENERIC; - } - rq->command=s; - - s=GWEN_DB_GetCharValue(rq->dbCommand, "protocol", 0, NULL); - if (!(s && *s)) { - DBG_ERROR(AQH_LOGDOMAIN, "No protocol in request"); - return GWEN_ERROR_GENERIC; - } - rq->protocol=s; - - s=GWEN_DB_GetCharValue(rq->dbCommand, "url", 0, NULL); - if (!(s && *s)) { - DBG_ERROR(AQH_LOGDOMAIN, "No url in request"); - return GWEN_ERROR_GENERIC; - } - - rq->url=GWEN_Url_fromCommandString(s); - if (rq->url==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid URL [%s]", s); - return GWEN_ERROR_GENERIC; - } - - s=GWEN_Url_GetPath(rq->url); - if (!(s && *s)) { - DBG_ERROR(AQH_LOGDOMAIN, "Empty url in request, assuming \"/\""); - s="/"; - } - rq->urlPath=s; - - return 0; -} - - - -void _inspectMsgHeader(AQH_HTTP_REQUEST *rq, const GWEN_MSG *msg) -{ - if (rq->dbHeader) - rq->dbCookies=_extractCookies(rq->dbHeader); - if (rq->dbCookies) { - const char *s; - - s=GWEN_DB_GetCharValue(rq->dbCookies, AQH_HTTP_REQUEST_SESSIONCOOKIE, 0, NULL); - if (s && *s) { - DBG_INFO(AQH_LOGDOMAIN, "Sessionid: %s", s); - AQH_HttpRequest_SetSessionId(rq, s); - } - } - -} - - - -int _inspectMsgBody(AQH_HTTP_REQUEST *rq, const GWEN_MSG *msg) -{ - int rv; - - rq->recvdBodySize=GWEN_Msg_GetParsedPayloadSize(msg); - if (rq->recvdBodySize>0) - rq->recvdBodyPtr=GWEN_Msg_GetConstBuffer(msg)+GWEN_Msg_GetParsedPayloadOffset(msg); - - if (rq->dbHeader && rq->recvdBodySize>0 && strcasecmp(rq->command, "POST")==0) { - const char *s; - - /* check whether we need to parse POST body */ - s=GWEN_DB_GetCharValue(rq->dbHeader, "content-type", 0, NULL); - if (s && strcasecmp(s, "application/x-www-form-urlencoded")==0) { - rq->dbPostBody=GWEN_DB_Group_new("post"); - rv=_parsePostBody((const char*) (rq->recvdBodyPtr), rq->recvdBodySize, rq->dbPostBody); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - } - } - - return 0; -} - - - -GWEN_DB_NODE *_extractCookies(GWEN_DB_NODE *dbHeader) -{ - int i; - GWEN_DB_NODE *dbCookies; - - dbCookies=GWEN_DB_GetGroup(dbHeader, 0, "cookies"); - for (i=0; ; i++) { - const char *sCookie; - - sCookie=GWEN_DB_GetCharValue(dbHeader, "Cookie", i, NULL); - if (sCookie && *sCookie) { - const char *s; - - s=sCookie; - while(*s) { - while(*s && *s<33) - s++; - - if (*s) { - const char *nameStart; - int nameLen; - - nameStart=s++; - while(*s && *s!='=') - s++; - if (*s=='=') { - nameLen=s-nameStart; - s++; - while(*s && *s<33) - s++; - if (*s) { - const char *valueStart; - int valueLen; - - valueStart=s; - while(*s && *s!=';') - s++; - valueLen=s-valueStart; - - _setCookieValue(dbCookies, nameStart, nameLen, valueStart, valueLen, 0); - - if (*s) - s++; - } - } - } - } /* while(*s) */ - } /* if (sCookie && *sCookie) */ - else - break; - } /* for */ - return dbCookies; -} - - - -void _setCookieValue(GWEN_DB_NODE *dbCookies, const char *nameStart, int nameLen, const char *valueStart, int valueLen, uint32_t dbFlags) -{ - if (nameLen && valueLen) { - int i; - char *sName; - char *sValue; - - for (i=nameLen-1; i>0; i--) { - if (nameStart[i]>32) - break; - } - sName=GWEN_Text_strndup(nameStart, i+1); - - for (i=valueLen-1; i>0; i--) { - if (valueStart[i]>32) - break; - } - sValue=GWEN_Text_strndup(valueStart, i+1); - - DBG_INFO(AQH_LOGDOMAIN, "Received Cookie: [%s]=[%s]", sName, sValue); - GWEN_DB_SetCharValue(dbCookies, dbFlags, sName, sValue); - free(sValue); - free(sName); - } -} - - - -int _parsePostBody(const char *s, int contentLength, GWEN_DB_NODE *dbBody) -{ - while(contentLength>0) { - const char *sNameStart; - int nameLen; - - while((contentLength>0) && (*s<33)) { - contentLength--; - s++; - } - sNameStart=s; - while((contentLength>0) && (*s!='=') && (*s!='&')) { - contentLength--; - s++; - } - nameLen=s-sNameStart; - - if ((contentLength>0) && (*s=='=')) { - const char *sValueStart; - int valueLen; - - s++; - contentLength--; - while((contentLength>0) && (*s<33)) { - s++; - contentLength--; - } - sValueStart=s; - while((contentLength>0) && (*s!='&')) { - contentLength--; - s++; - } - valueLen=s-sValueStart; - - if (nameLen && valueLen) { - char sNameBuf[32]; - char sValueBuf[64]; - - if (_unescapeUrlEncoded(sNameStart, nameLen, sNameBuf, sizeof(sNameBuf))>=0 && - _unescapeUrlEncoded(sValueStart, valueLen, sValueBuf, sizeof(sValueBuf))>=0) - GWEN_DB_SetCharValue(dbBody, 0, sNameBuf, sValueBuf); - else { - DBG_ERROR(NULL, "Either name or value invalid in body, aborting"); - return GWEN_ERROR_BAD_DATA; - } - } - if ((contentLength>0) && (*s=='&')) { - contentLength--; - s++; - } - } - } /* while */ - return 0; -} - - - -int _unescapeUrlEncoded(const char *src, unsigned int srclen, char *buffer, unsigned int maxsize) -{ - unsigned int size; - - size=0; - - while (srclen>0 && *src) { - unsigned char x; - - x=(unsigned char)*src; - if ( - (x>='A' && x<='Z') || - (x>='a' && x<='z') || - (x>='0' && x<='9') || - x==' ' || - x=='.' || - x==',' || - x=='.' || - x=='*' || - x=='?' || - x=='+' || - x=='-' || - x=='_' - ) { - if (size<(maxsize-1)) { - buffer[size++]=(x=='+')?' ':x; - } - else { - DBG_ERROR(GWEN_LOGDOMAIN, "Buffer too small"); - return GWEN_ERROR_BUFFER_OVERFLOW; - } - } - else { - if (*src=='%') { - unsigned char d1, d2; - unsigned char c; - - if (srclen<3) { - DBG_ERROR(GWEN_LOGDOMAIN, "Incomplete escape sequence (EOLN met)"); - return GWEN_ERROR_BAD_DATA; - } - /* skip '%' */ - src++; - if (!(*src) || !isxdigit((int)*src)) { - DBG_ERROR(GWEN_LOGDOMAIN, "Incomplete escape sequence (no digits)"); - return GWEN_ERROR_BAD_DATA; - } - /* read first digit */ - d1=(unsigned char)(toupper(*src)); - - /* get second digit */ - src++; - if (!(*src) || !isxdigit((int)*src)) { - DBG_ERROR(GWEN_LOGDOMAIN, "Incomplete escape sequence (only 1 digit)"); - return GWEN_ERROR_BAD_DATA; - } - d2=(unsigned char)(toupper(*src)); - /* compute character */ - d1-='0'; - if (d1>9) - d1-=7; - c=(d1<<4)&0xf0; - d2-='0'; - if (d2>9) - d2-=7; - c+=(d2&0xf); - /* store character */ - if (size<(maxsize-1)) - buffer[size++]=(char)c; - else { - DBG_ERROR(GWEN_LOGDOMAIN, "Buffer too small"); - return GWEN_ERROR_BUFFER_OVERFLOW; - } - srclen-=2; - } - else { - DBG_ERROR(GWEN_LOGDOMAIN, "Found non-alphanum characters in escaped string (\"%s\")", src); - return GWEN_ERROR_BAD_DATA; - } - } - srclen--; - src++; - } /* while */ - - buffer[size]=0; - return 0; -} - - - - diff --git a/aqhome/http/httprequest.h b/aqhome/http/httprequest.h deleted file mode 100644 index cf98821..0000000 --- a/aqhome/http/httprequest.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_HTTP_REQUEST_H -#define AQH_HTTP_REQUEST_H - - -#include "aqhome/service/session.h" -#include "aqhome/service/module.h" - -#include -#include -#include -#include - - -#define AQH_HTTP_REQUEST_SESSIONCOOKIE "sessionid" - - -typedef struct AQH_HTTP_REQUEST AQH_HTTP_REQUEST; -GWEN_TREE2_FUNCTION_LIB_DEFS(AQH_HTTP_REQUEST, AQH_HttpRequest, AQHOME_API); - -AQHOME_API AQH_HTTP_REQUEST *AQH_HttpRequest_new(GWEN_MSG_ENDPOINT *endpoint, const GWEN_MSG *receivedMsg); -AQHOME_API void AQH_HttpRequest_free(AQH_HTTP_REQUEST *rq); - -AQHOME_API GWEN_MSG_ENDPOINT *AQH_HttpRequest_GetEndpoint(const AQH_HTTP_REQUEST *rq); - -AQHOME_API const GWEN_MSG *AQH_HttpRequest_GetReceivedMsg(const AQH_HTTP_REQUEST *rq); - -AQHOME_API const char *AQH_HttpRequest_GetCommand(const AQH_HTTP_REQUEST *rq); - -AQHOME_API const char *AQH_HttpRequest_GetProtocol(const AQH_HTTP_REQUEST *rq); - -AQHOME_API GWEN_URL *AQH_HttpRequest_GetUrl(const AQH_HTTP_REQUEST *rq); -AQHOME_API void AQH_HttpRequest_SetUrl(AQH_HTTP_REQUEST *rq, GWEN_URL *url); - -AQHOME_API const char *AQH_HttpRequest_GetUrlPath(const AQH_HTTP_REQUEST *rq); - -AQHOME_API GWEN_STRINGLIST *AQH_HttpRequest_GetUrlPathMembers(const AQH_HTTP_REQUEST *rq); -AQHOME_API void AQH_HttpRequest_SetUrlPathMembers(AQH_HTTP_REQUEST *rq, GWEN_STRINGLIST *sl); - -AQHOME_API GWEN_DB_NODE *AQH_HttpRequest_GetDbCommand(const AQH_HTTP_REQUEST *rq); -AQHOME_API GWEN_DB_NODE *AQH_HttpRequest_GetDbHeader(const AQH_HTTP_REQUEST *rq); -AQHOME_API GWEN_DB_NODE *AQH_HttpRequest_GetDbCookies(const AQH_HTTP_REQUEST *rq); -AQHOME_API GWEN_DB_NODE *AQH_HttpRequest_GetDbPostBody(const AQH_HTTP_REQUEST *rq); - - -AQHOME_API const char *AQH_HttpRequest_GetSessionId(const AQH_HTTP_REQUEST *rq); -AQHOME_API void AQH_HttpRequest_SetSessionId(AQH_HTTP_REQUEST *rq, const char *s); - -AQHOME_API const char *AQH_HttpRequest_GetModuleName(const AQH_HTTP_REQUEST *rq); -AQHOME_API void AQH_HttpRequest_SetModuleName(AQH_HTTP_REQUEST *rq, const char *s); - -AQHOME_API AQH_SESSION *AQH_HttpRequest_GetSession(const AQH_HTTP_REQUEST *rq); -AQHOME_API void AQH_HttpRequest_SetSession(AQH_HTTP_REQUEST *rq, AQH_SESSION *session); - -AQHOME_API AQH_MODULE *AQH_HttpRequest_GetModule(const AQH_HTTP_REQUEST *rq); -AQHOME_API void AQH_HttpRequest_SetModule(AQH_HTTP_REQUEST *rq, AQH_MODULE *m); - -AQHOME_API uint32_t AQH_HttpRequest_GetModulePerms(const AQH_HTTP_REQUEST *rq); -AQHOME_API void AQH_HttpRequest_SetModulePerms(AQH_HTTP_REQUEST *rq, uint32_t i); - - -AQHOME_API int AQH_HttpRequest_GetResponseCode(const AQH_HTTP_REQUEST *rq); -AQHOME_API void AQH_HttpRequest_SetResponseCode(AQH_HTTP_REQUEST *rq, int i); - -AQHOME_API const char *AQH_HttpRequest_GetResponseText(const AQH_HTTP_REQUEST *rq); -AQHOME_API void AQH_HttpRequest_SetResponseText(AQH_HTTP_REQUEST *rq, const char *s); - -AQHOME_API GWEN_MSG *AQH_HttpRequest_GetResponseMsg(const AQH_HTTP_REQUEST *rq); -AQHOME_API GWEN_MSG *AQH_HttpRequest_TakeResponseMsg(AQH_HTTP_REQUEST *rq); -AQHOME_API void AQH_HttpRequest_SetResponseMsg(AQH_HTTP_REQUEST *rq, GWEN_MSG *msg); - -AQHOME_API void AQH_HttpRequest_SetupUrlPathMembers(AQH_HTTP_REQUEST *rq); - - -#endif - - - diff --git a/aqhome/http/httprequest_p.h b/aqhome/http/httprequest_p.h deleted file mode 100644 index 3adde4f..0000000 --- a/aqhome/http/httprequest_p.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_HTTP_REQUEST_P_H -#define AQH_HTTP_REQUEST_P_H - - -#include "aqhome/http/httprequest.h" - - - -typedef struct AQH_HTTP_REQUEST AQH_HTTP_REQUEST; -struct AQH_HTTP_REQUEST { - GWEN_TREE2_ELEMENT(AQH_HTTP_REQUEST) - - GWEN_MSG_ENDPOINT *endpoint; - - /* received stuff */ - const GWEN_MSG *receivedMsg; /* don't free */ - - const char *command; /* don't free */ - const char *protocol; /* don't free */ - const char *urlPath; /* don't free */ - GWEN_URL *url; - - GWEN_STRINGLIST *urlPathMembers; - - GWEN_DB_NODE *dbCommand; /* don't free */ - GWEN_DB_NODE *dbHeader; /* don't free */ - GWEN_DB_NODE *dbCookies; /* don't free */ - - uint32_t recvdBodySize; - const uint8_t *recvdBodyPtr; - - /* derived stuff */ - char *sessionId; - char *moduleName; - - AQH_SESSION *session; /* don't free */ - AQH_MODULE *module; /* don't free */ - uint32_t modulePerms; - - GWEN_DB_NODE *dbPostBody; - - - /* response stuff */ - int responseCode; - char *responseText; - GWEN_MSG *responseMsg; -}; - - - -#endif - - - diff --git a/aqhome/http/httpservice.c b/aqhome/http/httpservice.c deleted file mode 100644 index 3868cd7..0000000 --- a/aqhome/http/httpservice.c +++ /dev/null @@ -1,259 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -//#define DISABLE_DEBUGLOG - - -#include "aqhome/http/httpservice_p.h" - -#include -#include -#include -#include - - - -GWEN_INHERIT(AQH_SERVICE, AQH_HTTP_SERVICE) - - -static void GWENHYWFAR_CB _freeData(void *bp, void *p); - - - - -AQH_SERVICE *AQH_HttpService_new(const char *configFolder, const char *sourceFolder) -{ - AQH_SERVICE *sv; - - sv=AQH_Service_new(); - AQH_HttpService_Extend(sv, configFolder, sourceFolder); - - return sv; -} - - - -void AQH_HttpService_Extend(AQH_SERVICE *sv, const char *configFolder, const char *sourceFolder) -{ - AQH_HTTP_SERVICE *xsv; - - GWEN_NEW_OBJECT(AQH_HTTP_SERVICE, xsv); - GWEN_INHERIT_SETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv, xsv, _freeData); - - AQH_HttpService_SetConfigFolder(sv, configFolder); - AQH_HttpService_SetSourceFolder(sv, sourceFolder); - - xsv->moduleMutex=GWEN_Mutex_new(); - xsv->userMutex=GWEN_Mutex_new(); - xsv->sessionMutex=GWEN_Mutex_new(); - - xsv->urlHandlerList=AQH_HttpUrlHandler_List_new(sv); - -} - - - -void _freeData(void *bp, void *p) -{ - AQH_HTTP_SERVICE *xsv; - - xsv=(AQH_HTTP_SERVICE*) p; - - AQH_HttpUrlHandler_List_free(xsv->urlHandlerList); - - GWEN_Mutex_free(xsv->moduleMutex); - GWEN_Mutex_free(xsv->userMutex); - GWEN_Mutex_free(xsv->sessionMutex); - - free(xsv->configFolder); - free(xsv->sourceFolder); - free(xsv->siteHeader); - free(xsv->siteFooter); - GWEN_FREE_OBJECT(xsv); -} - - - -const char *AQH_HttpService_GetConfigFolder(const AQH_SERVICE *sv) -{ - if (sv) { - AQH_HTTP_SERVICE *xsv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv) - return xsv->configFolder; - } - return NULL; -} - - - -void AQH_HttpService_SetConfigFolder(AQH_SERVICE *sv, const char *s) -{ - if (sv) { - AQH_HTTP_SERVICE *xsv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv) { - free(xsv->configFolder); - xsv->configFolder=s?strdup(s):NULL; - } - } -} - - - -const char *AQH_HttpService_GetSourceFolder(const AQH_SERVICE *sv) -{ - if (sv) { - AQH_HTTP_SERVICE *xsv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv) - return xsv->sourceFolder; - } - return NULL; -} - - - -void AQH_HttpService_SetSourceFolder(AQH_SERVICE *sv, const char *s) -{ - if (sv) { - AQH_HTTP_SERVICE *xsv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv) { - free(xsv->sourceFolder); - xsv->sourceFolder=s?strdup(s):NULL; - } - } -} - - - -uint32_t AQH_HttpService_GetNextModuleId(AQH_SERVICE *sv) -{ - if (sv) { - AQH_HTTP_SERVICE *xsv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv) { - return ++(xsv->lastModuleId); - } - } - return 0; -} - - - -uint32_t AQH_HttpService_GetNextUserId(AQH_SERVICE *sv) -{ - if (sv) { - AQH_HTTP_SERVICE *xsv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv) { - return ++(xsv->lastUserId); - } - } - return 0; -} - - - -int AQH_HttpService_GetMaxSessionAgeInSecs(const AQH_SERVICE *sv) -{ - if (sv) { - AQH_HTTP_SERVICE *xsv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv) { - return xsv->maxSessionAgeInSecs; - } - } - return 0; -} - - - -void AQH_HttpService_SetMaxSessionAgeInSecs(AQH_SERVICE *sv, int i) -{ - if (sv) { - AQH_HTTP_SERVICE *xsv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv) - xsv->maxSessionAgeInSecs=i; - } -} - - - -const char *AQH_HttpService_GetSiteHeader(const AQH_SERVICE *sv) -{ - if (sv) { - AQH_HTTP_SERVICE *xsv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv) - return xsv->siteHeader; - } - return NULL; -} - - - -void AQH_HttpService_SetSiteHeader(AQH_SERVICE *sv, const char *s) -{ - if (sv) { - AQH_HTTP_SERVICE *xsv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv) { - free(xsv->siteHeader); - xsv->siteHeader=s?strdup(s):NULL; - } - } -} - - - -const char *AQH_HttpService_GetSiteFooter(const AQH_SERVICE *sv) -{ - if (sv) { - AQH_HTTP_SERVICE *xsv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv) - return xsv->siteFooter; - } - return NULL; -} - - - -void AQH_HttpService_SetSiteFooter(AQH_SERVICE *sv, const char *s) -{ - if (sv) { - AQH_HTTP_SERVICE *xsv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv) { - free(xsv->siteFooter); - xsv->siteFooter=s?strdup(s):NULL; - } - } -} - - - diff --git a/aqhome/http/httpservice.h b/aqhome/http/httpservice.h deleted file mode 100644 index c3e1da4..0000000 --- a/aqhome/http/httpservice.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_HTTP_SERVICE_H -#define AQH_HTTP_SERVICE_H - - - -#include "aqhome/service/service.h" - -#include "aqhome/http/httprequest.h" -#include "aqhome/http/urlhandler.h" - -#include -#include -#include -#include -#include - - - - -AQHOME_API AQH_SERVICE *AQH_HttpService_new(const char *configFolder, const char *sourceFolder); -AQHOME_API void AQH_HttpService_Extend(AQH_SERVICE *sv, const char *configFolder, const char *sourceFolder); - - -AQHOME_API const char *AQH_HttpService_GetConfigFolder(const AQH_SERVICE *sv); -AQHOME_API void AQH_HttpService_SetConfigFolder(AQH_SERVICE *sv, const char *s); - - -AQHOME_API const char *AQH_HttpService_GetSourceFolder(const AQH_SERVICE *sv); -AQHOME_API void AQH_HttpService_SetSourceFolder(AQH_SERVICE *sv, const char *s); - -AQHOME_API const char *AQH_HttpService_GetSiteHeader(const AQH_SERVICE *sv); -AQHOME_API void AQH_HttpService_SetSiteHeader(AQH_SERVICE *sv, const char *s); - - -AQHOME_API const char *AQH_HttpService_GetSiteFooter(const AQH_SERVICE *sv); -AQHOME_API void AQH_HttpService_SetSiteFooter(AQH_SERVICE *sv, const char *s); - - -AQHOME_API uint32_t AQH_HttpService_GetNextModuleId(AQH_SERVICE *sv); -AQHOME_API uint32_t AQH_HttpService_GetNextUserId(AQH_SERVICE *sv); - -AQHOME_API int AQH_HttpService_GetMaxSessionAgeInSecs(const AQH_SERVICE *sv); -AQHOME_API void AQH_HttpService_SetMaxSessionAgeInSecs(AQH_SERVICE *sv, int i); - - -#endif - - - diff --git a/aqhome/http/httpservice_conf.c b/aqhome/http/httpservice_conf.c deleted file mode 100644 index 15da098..0000000 --- a/aqhome/http/httpservice_conf.c +++ /dev/null @@ -1,1271 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -//#define DISABLE_DEBUGLOG - - -#include "aqhome/http/httpservice_conf.h" -#include "aqhome/http/httpservice_p.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - - - -#define AQH_HTTP_SERVICE_FILE_CONFIG "service.conf" -#define AQH_HTTP_SERVICE_DIR_MODS "modules" -#define AQH_HTTP_SERVICE_DIR_USERS "users" -#define AQH_HTTP_SERVICE_DIR_SESSIONS "sessions" - - -#ifdef GWEN_INHERIT_REF - GWEN_INHERIT_REF(AQH_SERVICE, AQH_HTTP_SERVICE) -#else - extern uint32_t AQH_HTTP_SERVICE_ID; -#endif - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static void _calculateUserPerms(AQH_SERVICE *sv, AQH_USER *user); -static void _calculateModuleUserPerms(AQH_SERVICE *sv, AQH_MODULE_PERMS *p); -static AQH_MODULE *_ensureModule(AQH_SERVICE *sv, const char *modName); -static AQH_USER *_ensureUser(AQH_SERVICE *sv, const char *alias); -static AQH_SESSION *_ensureSession(AQH_SERVICE *sv, const char *sessionUid); -static GWEN_BUFFER *_getConfigFilePath(const AQH_SERVICE *sv, const char *fileName); -static GWEN_BUFFER *_getModuleFilePath(const AQH_SERVICE *sv, const char *modName); -static GWEN_BUFFER *_getUserFilePath(const AQH_SERVICE *sv, const char *userAlias); -static GWEN_BUFFER *_getSessionFilePath(const AQH_SERVICE *sv, const char *sessionUid); -static GWEN_BUFFER *_getSessionFolder(const AQH_SERVICE *sv); -static int _checkUser(const AQH_USER *user, int ignoreMissingId); -static int _checkSession(const AQH_SESSION *session); -static int _checkModule(const AQH_MODULE *m, int ignoreMissingId); -static int _checkRoleList(const AQH_ROLE_LIST *roleList, int ignoreMissingId); -static int _writeDbFile(const char *fname, GWEN_DB_NODE *db); -static AQH_SESSION_LIST *_readAllSessionsIntoList(const AQH_SERVICE *sv); -static AQH_SESSION *_readSessionFromFile(const char *filename); - - - -/* ------------------------------------------------------------------------------------------------ - * implementations - * ------------------------------------------------------------------------------------------------ - */ - -int AQH_HttpService_LoadConfig(AQH_SERVICE *sv) -{ - AQH_HTTP_SERVICE *xsv; - GWEN_BUFFER *nameBuf; - int rv; - GWEN_DB_NODE *db; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Not a AQH_HttpService object"); - return GWEN_ERROR_INVALID; - } - - db=GWEN_DB_Group_new("service"); - - nameBuf=_getConfigFilePath(sv, AQH_HTTP_SERVICE_FILE_CONFIG); - rv=GWEN_DB_ReadFile(db, GWEN_Buffer_GetStart(nameBuf), GWEN_DB_FLAGS_DEFAULT); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Buffer_free(nameBuf); - GWEN_DB_Group_free(db); - return rv; - } - GWEN_Buffer_free(nameBuf); - - xsv->lastModuleId=GWEN_DB_GetIntValue(db, "lastModuleId", 0, 0); - xsv->lastUserId=GWEN_DB_GetIntValue(db, "lastUserId", 0, 0); - xsv->maxSessionAgeInSecs=GWEN_DB_GetIntValue(db, "maxSessionAgeInSecs", 0, AQH_HTTP_SERVICE_DEFAULT_MAXSESSIONAGE); - - GWEN_DB_Group_free(db); - - return 0; -} - - - -int AQH_HttpService_SaveConfig(const AQH_SERVICE *sv) -{ - AQH_HTTP_SERVICE *xsv; - int rv; - GWEN_BUFFER *nameBuf; - GWEN_DB_NODE *db; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Not a AQH_HttpService object"); - return GWEN_ERROR_INVALID; - } - - db=GWEN_DB_Group_new("service"); - GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "lastModuleId", xsv->lastModuleId); - GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "lastUserId", xsv->lastUserId); - GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "maxSessionAgeInSecs", xsv->maxSessionAgeInSecs); - - nameBuf=_getConfigFilePath(sv, AQH_HTTP_SERVICE_FILE_CONFIG); - rv=_writeDbFile(GWEN_Buffer_GetStart(nameBuf), db); - GWEN_Buffer_free(nameBuf); - GWEN_DB_Group_free(db); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - return 0; -} - - - -AQH_MODULE *AQH_HttpService_GetModule(AQH_SERVICE *sv, const char *modName) -{ - AQH_HTTP_SERVICE *xsv; - AQH_MODULE *m; - int rv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Not a AQH_HttpService object"); - return NULL; - } - - rv=GWEN_Mutex_Lock(xsv->moduleMutex); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error obtaining lock on module mutex"); - return NULL; - } - - m=_ensureModule(sv, modName); - - rv=GWEN_Mutex_Unlock(xsv->moduleMutex); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error releasing lock on module mutex"); - return NULL; - } - - if (m==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "here"); - return NULL; - } - - return m; -} - - - -AQH_USER *AQH_HttpService_GetUser(AQH_SERVICE *sv, const char *alias) -{ - AQH_HTTP_SERVICE *xsv; - AQH_USER *user; - int rv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Not a AQH_HttpService object"); - return NULL; - } - - rv=GWEN_Mutex_Lock(xsv->userMutex); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error obtaining lock on user mutex"); - return NULL; - } - - user=_ensureUser(sv, alias); - - rv=GWEN_Mutex_Unlock(xsv->userMutex); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error releasing lock on user mutex"); - return NULL; - } - - if (user==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "here"); - return NULL; - } - - return user; -} - - - -int AQH_HttpService_WriteUser(const AQH_SERVICE *sv, const AQH_USER *user) -{ - AQH_HTTP_SERVICE *xsv; - int rv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Not a AQH_HttpService object"); - return GWEN_ERROR_INVALID; - } - - rv=GWEN_Mutex_Lock(xsv->userMutex); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error obtaining lock on user mutex"); - return rv; - } - - rv=AQH_HttpService_SaveUser(sv, user); - if (rv<0) { - GWEN_Mutex_Unlock(xsv->userMutex); - DBG_ERROR(AQH_LOGDOMAIN, "Error saving user \"%s\" (%d)", AQH_User_GetAlias(user), rv); - return rv; - } - - rv=GWEN_Mutex_Unlock(xsv->userMutex); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error releasing lock on user mutex"); - return rv; - } - - return 0; -} - - - - -AQH_SESSION *AQH_HttpService_GetSession(AQH_SERVICE *sv, const char *sessionUid) -{ - AQH_HTTP_SERVICE *xsv; - AQH_SESSION *session; - int rv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Not a AQH_HttpService object"); - return NULL; - } - - rv=GWEN_Mutex_Lock(xsv->sessionMutex); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error obtaining lock on session mutex"); - return NULL; - } - - session=_ensureSession(sv, sessionUid); - - rv=GWEN_Mutex_Unlock(xsv->sessionMutex); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error releasing lock on session mutex"); - return NULL; - } - - if (session==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "here"); - return NULL; - } - - return session; -} - - - -int AQH_HttpService_LockSessions(AQH_SERVICE *sv) -{ - AQH_HTTP_SERVICE *xsv; - int rv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Not a AQH_HttpService object"); - return GWEN_ERROR_GENERIC; - } - - rv=GWEN_Mutex_Lock(xsv->sessionMutex); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error obtaining lock on session mutex"); - return rv; - } - - return 0; -} - - - -int AQH_HttpService_UnlockSessions(AQH_SERVICE *sv) -{ - AQH_HTTP_SERVICE *xsv; - int rv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Not a AQH_HttpService object"); - return GWEN_ERROR_GENERIC; - } - - rv=GWEN_Mutex_Unlock(xsv->sessionMutex); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error releasing lock on session mutex"); - return rv; - } - - return 0; -} - - - -int AQH_HttpService_CleanupSessions(AQH_SERVICE *sv, int maxAgeInSecs) -{ - time_t tNow; - AQH_SESSION_LIST *sessionList; - int rv; - - rv=AQH_HttpService_LockSessions(sv); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "Error locking sessions (%d)", rv); - return rv; - } - - tNow=time(NULL); - - sessionList=AQH_Service_GetSessionList(sv); - if (sessionList) { - AQH_SESSION *session; - - session=AQH_Session_List_First(sessionList); - while(session) { - AQH_SESSION *next; - const GWEN_TIMESTAMP *ts; - - next=AQH_Session_List_Next(session); - - ts=AQH_Session_GetTimestampLastAccess(session); - if (ts==NULL) - ts=AQH_Session_GetTimestampCreation(session); - if (ts) { - time_t diff; - - diff=tNow-GWEN_Timestamp_toTimeT(ts); - if (((int)diff)>maxAgeInSecs) { - DBG_INFO(AQH_LOGDOMAIN, "Session \"%s\" expired (%d secs)", AQH_Session_GetUid(session), (int) diff); - rv=AQH_HttpService_DelSession(sv, session); /* frees session!! */ - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - } - } - } - - session=next; - } - } - - rv=AQH_HttpService_UnlockSessions(sv); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "Error unlocking sessions (%d)", rv); - return rv; - } - return 0; -} - - -void AQH_HttpService_LoadAllSessions(AQH_SERVICE *sv) -{ - AQH_SESSION_LIST *sessionList; - - sessionList=_readAllSessionsIntoList(sv); - if (sessionList) { - AQH_SESSION *session; - - while( (session=AQH_Session_List_First(sessionList)) ) { - const char *sessionUid; - const char *userAlias; - - AQH_Session_List_Del(session); - sessionUid=AQH_Session_GetUid(session); - userAlias=AQH_Session_GetUserAlias(session); - if (userAlias && *userAlias) { - AQH_USER *user; - - user=AQH_HttpService_GetUser(sv, userAlias); - if (user==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "User \"%s\" for session \"%s\" not available", userAlias, sessionUid); - AQH_Session_free(session); - } - else { - DBG_INFO(AQH_LOGDOMAIN, "Adding session \"%s\" (user=%s)", sessionUid, userAlias); - AQH_Session_SetUser(session, user); - AQH_Service_AddSession(sv, session); - } - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "Session has no user, not adding"); - AQH_Session_free(session); - } - } /* while */ - AQH_Session_List_free(sessionList); - } -} - - - -AQH_MODULE *AQH_HttpService_LoadModule(const AQH_SERVICE *sv, const char *modName) -{ - GWEN_BUFFER *nameBuf; - int rv; - GWEN_DB_NODE *db; - AQH_MODULE *m; - - db=GWEN_DB_Group_new("user"); - - nameBuf=_getModuleFilePath(sv, modName); - rv=GWEN_DB_ReadFile(db, GWEN_Buffer_GetStart(nameBuf), GWEN_DB_FLAGS_DEFAULT); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Buffer_free(nameBuf); - GWEN_DB_Group_free(db); - return NULL; - } - GWEN_Buffer_free(nameBuf); - - m=AQH_Module_fromDb(db); - if (m==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Error loading module \"%s\" from config group", modName); - GWEN_DB_Group_free(db); - return NULL; - } - GWEN_DB_Group_free(db); - - rv=_checkModule(m, 0); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "Invalid data for module \"%s\"", modName); - AQH_Module_free(m); - return NULL; - } - - return m; -} - - - -int AQH_HttpService_SaveModule(const AQH_SERVICE *sv, const AQH_MODULE *m) -{ - int rv; - const char *modName; - GWEN_BUFFER *nameBuf; - GWEN_DB_NODE *db; - - rv=_checkModule(m, 0); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - db=GWEN_DB_Group_new("module"); - rv=AQH_Module_toDb(m, db); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_DB_Group_free(db); - return rv; - } - - modName=AQH_Module_GetName(m); - nameBuf=_getModuleFilePath(sv, modName); - rv=_writeDbFile(GWEN_Buffer_GetStart(nameBuf), db); - GWEN_Buffer_free(nameBuf); - GWEN_DB_Group_free(db); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - return 0; -} - - - -int AQH_HttpService_AddModule(AQH_SERVICE *sv, AQH_MODULE *m) -{ - int rv; - uint32_t id; - AQH_ROLE_LIST *roleList; - AQH_ROLE *r; - - rv=_checkModule(m, 1); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Not adding invalid module (%d)", rv); - return rv; - } - - /* assign module id */ - id=AQH_HttpService_GetNextModuleId(sv); - AQH_Module_SetId(m, id); - - /* assign role ids */ - roleList=AQH_Module_GetRoleList(m); - id=1; - r=AQH_Role_List_First(roleList); - while(r) { - AQH_Role_SetId(r, id++); - r=AQH_Role_List_Next(r); - } - - rv=AQH_HttpService_SaveModule(sv, m); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error saving module module \"%s\" (%d)", AQH_Module_GetName(m), rv); - return rv; - } - - AQH_Service_AddModule(sv, m); - return 0; -} - - - -AQH_USER *AQH_HttpService_LoadUser(const AQH_SERVICE *sv, const char *userAlias) -{ - GWEN_BUFFER *nameBuf; - int rv; - GWEN_DB_NODE *db; - AQH_USER *user; - - db=GWEN_DB_Group_new("user"); - - nameBuf=_getUserFilePath(sv, userAlias); - rv=GWEN_DB_ReadFile(db, GWEN_Buffer_GetStart(nameBuf), GWEN_DB_FLAGS_DEFAULT); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Buffer_free(nameBuf); - GWEN_DB_Group_free(db); - return NULL; - } - GWEN_Buffer_free(nameBuf); - - user=AQH_User_fromDb(db); - if (user==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Error loading user \"%s\" from config group", userAlias); - GWEN_DB_Group_free(db); - return NULL; - } - GWEN_DB_Group_free(db); - - rv=_checkUser(user, 0); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "Invalid data for user \"%s\"", userAlias); - AQH_User_free(user); - return NULL; - } - - return user; -} - - - -int AQH_HttpService_SaveUser(const AQH_SERVICE *sv, const AQH_USER *user) -{ - int rv; - const char *sAlias; - GWEN_BUFFER *nameBuf; - GWEN_DB_NODE *db; - - rv=_checkUser(user, 0); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - db=GWEN_DB_Group_new("user"); - rv=AQH_User_toDb(user, db); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_DB_Group_free(db); - return rv; - } - - sAlias=AQH_User_GetAlias(user); - nameBuf=_getUserFilePath(sv, sAlias); - rv=_writeDbFile(GWEN_Buffer_GetStart(nameBuf), db); - GWEN_Buffer_free(nameBuf); - GWEN_DB_Group_free(db); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - return 0; -} - - - -int AQH_HttpService_AddUser(AQH_SERVICE *sv, AQH_USER *user) -{ - int rv; - uint32_t id; - - rv=_checkUser(user, 0); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - /* assign user id */ - id=AQH_HttpService_GetNextUserId(sv); - AQH_User_SetId(user, id); - - rv=AQH_HttpService_SaveUser(sv, user); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - AQH_Service_AddUser(sv, user); - - return 0; -} - - - -int AQH_HttpService_DelUser(AQH_SERVICE *sv, AQH_USER *user) -{ - const char *sAlias; - GWEN_BUFFER *nameBuf; - uint32_t userId; - - sAlias=AQH_User_GetAlias(user); - userId=AQH_User_GetId(user); - nameBuf=_getUserFilePath(sv, sAlias); - unlink(GWEN_Buffer_GetStart(nameBuf)); - GWEN_Buffer_free(nameBuf); - AQH_Service_DelUser(sv, userId); - return 0; -} - - - -AQH_SESSION *AQH_HttpService_LoadSession(const AQH_SERVICE *sv, const char *sessionUid) -{ - GWEN_BUFFER *nameBuf; - int rv; - AQH_SESSION *session; - - nameBuf=_getSessionFilePath(sv, sessionUid); - if (nameBuf==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "here"); - return NULL; - } - session=_readSessionFromFile(GWEN_Buffer_GetStart(nameBuf)); - if (session==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Error loading session \"%s\" from config group", sessionUid); - GWEN_Buffer_free(nameBuf); - return NULL; - } - GWEN_Buffer_free(nameBuf); - - rv=_checkSession(session); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "Invalid data for session \"%s\"", sessionUid); - AQH_Session_free(session); - return NULL; - } - - return session; -} - - - -int AQH_HttpService_SaveSession(const AQH_SERVICE *sv, const AQH_SESSION *session) -{ - int rv; - const char *sUid; - GWEN_BUFFER *nameBuf; - GWEN_DB_NODE *db; - - rv=_checkSession(session); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - db=GWEN_DB_Group_new("user"); - rv=AQH_Session_toDb(session, db); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_DB_Group_free(db); - return rv; - } - - sUid=AQH_Session_GetUid(session); - nameBuf=_getSessionFilePath(sv, sUid); - rv=_writeDbFile(GWEN_Buffer_GetStart(nameBuf), db); - GWEN_Buffer_free(nameBuf); - GWEN_DB_Group_free(db); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - return 0; -} - - - -int AQH_HttpService_AddSession(AQH_SERVICE *sv, AQH_SESSION *session) -{ - int rv; - - rv=_checkSession(session); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - rv=AQH_HttpService_SaveSession(sv, session); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - AQH_Service_AddSession(sv, session); - - return 0; -} - - - -int AQH_HttpService_DelSession(AQH_SERVICE *sv, AQH_SESSION *session) -{ - const char *uid; - GWEN_BUFFER *nameBuf; - - uid=AQH_Session_GetUid(session); - nameBuf=_getSessionFilePath(sv, uid); - unlink(GWEN_Buffer_GetStart(nameBuf)); - GWEN_Buffer_free(nameBuf); - AQH_Service_DelSession(sv, uid); - return 0; -} - - - -GWEN_STRINGLIST *AQH_HttpService_GetFolderFileList(const char *folder, const char *mask, int senseCase) -{ - GWEN_STRINGLIST *sl; - int rv; - - sl=GWEN_StringList_new(); - GWEN_StringList_SetSenseCase(sl, senseCase); - - rv=GWEN_Directory_GetFileEntries(folder, sl, mask); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_StringList_free(sl); - return NULL; - } - if (GWEN_StringList_Count(sl)<1) { - DBG_INFO(AQH_LOGDOMAIN, "Empty string list"); - GWEN_StringList_free(sl); - return NULL; - } - - return sl; -} - - - -AQH_MODULE *_ensureModule(AQH_SERVICE *sv, const char *modName) -{ - AQH_MODULE *module; - - module=AQH_Service_GetModuleByName(sv, modName); - if (module) - return module; - - module=AQH_HttpService_LoadModule(sv, modName); - if (module==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Could not load module \"%s\"", modName); - return NULL; - } - AQH_Service_AddModule(sv, module); - - return module; -} - - - -AQH_USER *_ensureUser(AQH_SERVICE *sv, const char *alias) -{ - AQH_USER *user; - - user=AQH_Service_GetUserByAlias(sv, alias); - if (user) - return user; - - user=AQH_HttpService_LoadUser(sv, alias); - if (user==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Could not load user \"%s\"", alias); - return NULL; - } - _calculateUserPerms(sv, user); - - AQH_Service_AddUser(sv, user); - return user; -} - - - -AQH_SESSION *_ensureSession(AQH_SERVICE *sv, const char *sessionUid) -{ - AQH_SESSION *session; - - session=AQH_Service_GetSessionByUid(sv, sessionUid); - if (session) - return session; - - session=AQH_HttpService_LoadSession(sv, sessionUid); - if (session) { - AQH_USER *user; - - user=AQH_HttpService_GetUser(sv, AQH_Session_GetUserAlias(session)); - if (user==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "User \"%s\" for session \"%s\" not available", AQH_Session_GetUserAlias(session), sessionUid); - AQH_Session_free(session); - return NULL; - } - AQH_Session_SetUser(session, user); - AQH_Service_AddSession(sv, session); - } - - if (session==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Could not load session \"%s\"", sessionUid); - return NULL; - } - - return session; -} - - - -GWEN_BUFFER *_getConfigFilePath(const AQH_SERVICE *sv, const char *fileName) -{ - const char *configFolder; - - configFolder=AQH_HttpService_GetConfigFolder(sv); - if (!(configFolder && *configFolder)) { - DBG_ERROR(AQH_LOGDOMAIN, "No config folder given"); - return NULL; - } - else { - GWEN_BUFFER *nameBuf; - - nameBuf=GWEN_Buffer_new(0, 256, 0, 1); - GWEN_Buffer_AppendString(nameBuf, configFolder); - GWEN_Buffer_AppendString(nameBuf, GWEN_DIR_SEPARATOR_S); - GWEN_Buffer_AppendString(nameBuf, fileName); - return nameBuf; - } -} - - - - -GWEN_BUFFER *_getModuleFilePath(const AQH_SERVICE *sv, const char *modName) -{ - const char *configFolder; - - configFolder=AQH_HttpService_GetConfigFolder(sv); - if (!(configFolder && *configFolder)) { - DBG_ERROR(AQH_LOGDOMAIN, "No config folder given"); - return NULL; - } - else { - GWEN_BUFFER *nameBuf; - - nameBuf=GWEN_Buffer_new(0, 256, 0, 1); - GWEN_Buffer_AppendString(nameBuf, configFolder); - GWEN_Buffer_AppendString(nameBuf, GWEN_DIR_SEPARATOR_S AQH_HTTP_SERVICE_DIR_MODS GWEN_DIR_SEPARATOR_S); - GWEN_Text_EscapeToBuffer(modName, nameBuf); - GWEN_Buffer_AppendString(nameBuf, ".conf"); - return nameBuf; - } -} - - - - -GWEN_BUFFER *_getUserFilePath(const AQH_SERVICE *sv, const char *userAlias) -{ - const char *configFolder; - - configFolder=AQH_HttpService_GetConfigFolder(sv); - if (!(configFolder && *configFolder)) { - DBG_ERROR(AQH_LOGDOMAIN, "No config folder given"); - return NULL; - } - else { - GWEN_BUFFER *nameBuf; - - nameBuf=GWEN_Buffer_new(0, 256, 0, 1); - GWEN_Buffer_AppendString(nameBuf, configFolder); - GWEN_Buffer_AppendString(nameBuf, GWEN_DIR_SEPARATOR_S AQH_HTTP_SERVICE_DIR_USERS GWEN_DIR_SEPARATOR_S); - GWEN_Text_EscapeToBuffer(userAlias, nameBuf); - GWEN_Buffer_AppendString(nameBuf, ".conf"); - return nameBuf; - } -} - - - -GWEN_BUFFER *_getSessionFilePath(const AQH_SERVICE *sv, const char *sessionUid) -{ - GWEN_BUFFER *nameBuf; - - nameBuf=_getSessionFolder(sv); - if (nameBuf) { - GWEN_Buffer_AppendString(nameBuf, GWEN_DIR_SEPARATOR_S); - GWEN_Text_EscapeToBuffer(sessionUid, nameBuf); - GWEN_Buffer_AppendString(nameBuf, ".conf"); - return nameBuf; - } - return NULL; -} - - - -int _checkUser(const AQH_USER *user, int ignoreMissingId) -{ - const char *s; - - if (!ignoreMissingId) { - uint32_t id; - - id=AQH_User_GetId(user); - if (id==0) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid user: no id"); - return GWEN_ERROR_BAD_DATA; - } - } - - s=AQH_User_GetAlias(user); - if (!(s && *s)) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid user: no alias"); - return GWEN_ERROR_BAD_DATA; - } - s=AQH_User_GetHashedPassword(user); - if (!(s && *s)) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid user: no password"); - return GWEN_ERROR_BAD_DATA; - } - s=AQH_User_GetEmail(user); - if (!(s && *s)) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid user: no email"); - return GWEN_ERROR_BAD_DATA; - } - - return 0; -} - - - -int _checkSession(const AQH_SESSION *session) -{ - const char *s; - - s=AQH_Session_GetUid(session); - if (!(s && *s)) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid session: no uid"); - return GWEN_ERROR_BAD_DATA; - } - - s=AQH_Session_GetUserAlias(session); - if (!(s && *s)) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid session: no user alias"); - return GWEN_ERROR_BAD_DATA; - } - - if (AQH_Session_GetTimestampCreation(session)==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid session: no creation time"); - return GWEN_ERROR_BAD_DATA; - } - - return 0; -} - - - -int _checkModule(const AQH_MODULE *m, int ignoreMissingId) -{ - const char *s; - const AQH_ROLE_LIST *roleList; - int rv; - - if (!ignoreMissingId) { - if (AQH_Module_GetId(m)==0) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid module: missing id"); - return GWEN_ERROR_BAD_DATA; - } - } - - s=AQH_Module_GetName(m); - if (!(s && *s)) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid module: missing name"); - return GWEN_ERROR_BAD_DATA; - } - - roleList=AQH_Module_GetRoleList(m); - if (roleList==NULL || AQH_Role_List_GetCount(roleList)<1) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid module: empty or missing role list"); - return GWEN_ERROR_BAD_DATA; - } - rv=_checkRoleList(roleList, ignoreMissingId); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid module %s: invalid role definition", AQH_Module_GetName(m)); - return rv; - } - - return 0; -} - - - -int _checkRoleList(const AQH_ROLE_LIST *roleList, int ignoreMissingId) -{ - const AQH_ROLE *r; - - r=AQH_Role_List_First(roleList); - while(r) { - const char *s; - - if (!ignoreMissingId) { - if (AQH_Role_GetId(r)==0) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid role: missing id"); - return GWEN_ERROR_BAD_DATA; - } - } - - s=AQH_Role_GetName(r); - if (!(s && *s)) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid role: missing name"); - return GWEN_ERROR_BAD_DATA; - } - - r=AQH_Role_List_Next(r); - } - - return 0; -} - - - -void _calculateUserPerms(AQH_SERVICE *sv, AQH_USER *user) -{ - AQH_MODULE_PERMS_LIST *permList; - - permList=AQH_User_GetModulePermList(user); - if (permList) { - AQH_MODULE_PERMS *p; - - p=AQH_ModulePerms_List_First(permList); - while(p) { - _calculateModuleUserPerms(sv, p); - p=AQH_ModulePerms_List_Next(p); - } - } - AQH_User_AddRuntimeFlags(user, AQH_USER_RTFLAGS_PERMSCALC); -} - - - -void _calculateModuleUserPerms(AQH_SERVICE *sv, AQH_MODULE_PERMS *p) -{ - uint32_t perms=0; - uint32_t addPerms=0; - uint32_t delPerms=0; - const AQH_MODULE *m; - - m=AQH_Service_GetModuleById(sv, AQH_ModulePerms_GetModuleId(p)); - if (m==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Module \"%d\" not found, ignoring", AQH_ModulePerms_GetModuleId(p)); - } - else { - const AQH_ROLE_LIST *roleList; - - roleList=AQH_Module_GetRoleList(m); - if (roleList) { - int i, j; - - j=AQH_ModulePerms_GetRoleArrayArraySize(); - for(i=0; i0) { - AQH_ROLE *r; - - r=AQH_Role_List_GetById(roleList, roleId); - if (r==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Role %d not found in module \"%s\", ignoring", roleId, AQH_Module_GetName(m)); - } - else { - DBG_INFO(AQH_LOGDOMAIN, "Module \"%s\": adding perms for role \"%s\"", AQH_Module_GetName(m), AQH_Role_GetName(r)); - perms|=AQH_Role_GetPerms(r); - addPerms|=AQH_Role_GetExplAddPerms(r); - delPerms|=AQH_Role_GetExplDelPerms(r); - } - } - } - } - } - perms|=addPerms; - perms&=~delPerms; - AQH_ModulePerms_SetPerms(p, perms); -} - - - -int _writeDbFile(const char *fname, GWEN_DB_NODE *db) -{ - GWEN_BUFFER *tmpFilenameBuf; - int rv; - - tmpFilenameBuf=GWEN_Buffer_new(0, 256, 0, 1); - GWEN_Buffer_AppendString(tmpFilenameBuf, fname); - GWEN_Buffer_AppendString(tmpFilenameBuf, ".tmp"); - unlink(GWEN_Buffer_GetStart(tmpFilenameBuf)); - rv=GWEN_DB_WriteFile(db, GWEN_Buffer_GetStart(tmpFilenameBuf), GWEN_DB_FLAGS_DEFAULT); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error writing db file \"%s\": %d", GWEN_Buffer_GetStart(tmpFilenameBuf), rv); - GWEN_Buffer_free(tmpFilenameBuf); - return rv; - } - if (rename(GWEN_Buffer_GetStart(tmpFilenameBuf), fname)<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error renaming tmp file to \"%s\": %d (%s)", fname, errno, strerror(errno)); - GWEN_Buffer_free(tmpFilenameBuf); - return GWEN_ERROR_IO; - } - unlink(GWEN_Buffer_GetStart(tmpFilenameBuf)); - GWEN_Buffer_free(tmpFilenameBuf); - return 0; -} - - - -GWEN_BUFFER *_getSessionFolder(const AQH_SERVICE *sv) -{ - const char *configFolder; - - configFolder=AQH_HttpService_GetConfigFolder(sv); - if (!(configFolder && *configFolder)) { - DBG_ERROR(AQH_LOGDOMAIN, "No config folder given"); - return NULL; - } - else { - GWEN_BUFFER *nameBuf; - - nameBuf=GWEN_Buffer_new(0, 256, 0, 1); - GWEN_Buffer_AppendString(nameBuf, configFolder); - GWEN_Buffer_AppendString(nameBuf, GWEN_DIR_SEPARATOR_S AQH_HTTP_SERVICE_DIR_SESSIONS); - return nameBuf; - } -} - - - -AQH_SESSION_LIST *_readAllSessionsIntoList(const AQH_SERVICE *sv) -{ - GWEN_BUFFER *folderBuf; - - folderBuf=_getSessionFolder(sv); - if (folderBuf) { - GWEN_STRINGLIST *fileList; - - fileList=AQH_HttpService_GetFolderFileList(GWEN_Buffer_GetStart(folderBuf), "*.conf", 1); - if (fileList) { - AQH_SESSION_LIST *sessionList; - uint32_t pos; - GWEN_STRINGLISTENTRY *se; - - sessionList=AQH_Session_List_new(); - GWEN_Buffer_AppendString(folderBuf, GWEN_DIR_SEPARATOR_S); - pos=GWEN_Buffer_GetPos(folderBuf); - se=GWEN_StringList_FirstEntry(fileList); - while(se) { - const char *s; - - s=GWEN_StringListEntry_Data(se); - if (s && *s) { - AQH_SESSION *session; - - GWEN_Buffer_AppendString(folderBuf, s); - session=_readSessionFromFile(GWEN_Buffer_GetStart(folderBuf)); - if (session==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "here"); - } - else { - AQH_Session_List_Add(session, sessionList); - } - GWEN_Buffer_Crop(folderBuf, 0, pos); - } - se=GWEN_StringListEntry_Next(se); - } - if (AQH_Session_List_GetCount(sessionList)<1) { - DBG_INFO(NULL, "Empty session list"); - AQH_Session_List_free(sessionList); - GWEN_StringList_free(fileList); - GWEN_Buffer_free(folderBuf); - return NULL; - } - GWEN_StringList_free(fileList); - GWEN_Buffer_free(folderBuf); - return sessionList; - } - GWEN_Buffer_free(folderBuf); - } - return NULL; -} - - - -AQH_SESSION *_readSessionFromFile(const char *filename) -{ - int rv; - GWEN_DB_NODE *db; - AQH_SESSION *session; - - db=GWEN_DB_Group_new("session"); - - rv=GWEN_DB_ReadFile(db, filename, GWEN_DB_FLAGS_DEFAULT); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_DB_Group_free(db); - return NULL; - } - - session=AQH_Session_fromDb(db); - if (session==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Error loading session from file \"%s\"", filename); - GWEN_DB_Group_free(db); - return NULL; - } - GWEN_DB_Group_free(db); - return session; -} - - - - - - - diff --git a/aqhome/http/httpservice_conf.h b/aqhome/http/httpservice_conf.h deleted file mode 100644 index 5924dbf..0000000 --- a/aqhome/http/httpservice_conf.h +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_HTTP_SERVICE_CONF_H -#define AQH_HTTP_SERVICE_CONF_H - - - -#include "aqhome/service/service.h" - -#include -#include -#include -#include - - - -#define AQH_HTTP_SERVICE_ADMINUSER "admin" - - - -AQHOME_API int AQH_HttpService_LoadConfig(AQH_SERVICE *sv); -AQHOME_API int AQH_HttpService_SaveConfig(const AQH_SERVICE *sv); - -AQHOME_API AQH_MODULE *AQH_HttpService_GetModule(AQH_SERVICE *sv, const char *modName); -AQHOME_API AQH_USER *AQH_HttpService_GetUser(AQH_SERVICE *sv, const char *alias); -AQHOME_API int AQH_HttpService_WriteUser(const AQH_SERVICE *sv, const AQH_USER *user); - -AQHOME_API AQH_SESSION *AQH_HttpService_GetSession(AQH_SERVICE *sv, const char *sessionUid); -AQHOME_API int AQH_HttpService_LockSessions(AQH_SERVICE *sv); -AQHOME_API int AQH_HttpService_UnlockSessions(AQH_SERVICE *sv); -AQHOME_API int AQH_HttpService_CleanupSessions(AQH_SERVICE *sv, int maxAgeInSecs); - -AQHOME_API AQH_MODULE *AQH_HttpService_LoadModule(const AQH_SERVICE *sv, const char *modName); -AQHOME_API int AQH_HttpService_SaveModule(const AQH_SERVICE *sv, const AQH_MODULE *m); -AQHOME_API int AQH_HttpService_AddModule(AQH_SERVICE *sv, AQH_MODULE *m); - -AQHOME_API AQH_USER *AQH_HttpService_LoadUser(const AQH_SERVICE *sv, const char *userAlias); -AQHOME_API int AQH_HttpService_SaveUser(const AQH_SERVICE *sv, const AQH_USER *user); -AQHOME_API int AQH_HttpService_AddUser(AQH_SERVICE *sv, AQH_USER *user); -AQHOME_API int AQH_HttpService_DelUser(AQH_SERVICE *sv, AQH_USER *user); - -AQHOME_API AQH_SESSION *AQH_HttpService_LoadSession(const AQH_SERVICE *sv, const char *sessionUid); -AQHOME_API int AQH_HttpService_SaveSession(const AQH_SERVICE *sv, const AQH_SESSION *session); -AQHOME_API int AQH_HttpService_AddSession(AQH_SERVICE *sv, AQH_SESSION *session); -AQHOME_API int AQH_HttpService_DelSession(AQH_SERVICE *sv, AQH_SESSION *session); -AQHOME_API void AQH_HttpService_LoadAllSessions(AQH_SERVICE *sv); - - -AQHOME_API GWEN_STRINGLIST *AQH_HttpService_GetFolderFileList(const char *folder, const char *mask, int senseCase); - -#endif - - - diff --git a/aqhome/http/httpservice_http.c b/aqhome/http/httpservice_http.c deleted file mode 100644 index b737233..0000000 --- a/aqhome/http/httpservice_http.c +++ /dev/null @@ -1,412 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -//#define DISABLE_DEBUGLOG - - -#include "aqhome/http/httpservice_http.h" -#include "aqhome/http/httpservice_conf.h" -#include "aqhome/http/httpservice_p.h" -#include "aqhome/http/urlhandler.h" - -#include -#include -#include -#include - - - -#ifdef GWEN_INHERIT_REF - GWEN_INHERIT_REF(AQH_SERVICE, AQH_HTTP_SERVICE) -#else - extern uint32_t AQH_HTTP_SERVICE_ID; -#endif - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static void _writeDefaultResponseHeaderToBuffer(AQH_SERVICE *sv, int contentLength, GWEN_BUFFER *buf); -static GWEN_BUFFER *_getPageFilePath(const AQH_SERVICE *sv, const char *langFolder, const char *fileName); -static AQH_HTTP_URLHANDLER *_findMatchingUrlHandler(AQH_SERVICE *sv, const char *path); - - - -/* ------------------------------------------------------------------------------------------------ - * implementations - * ------------------------------------------------------------------------------------------------ - */ - - -GWEN_MSG *AQH_HttpService_HandleHttpRequest(AQH_SERVICE *sv, GWEN_MSG_ENDPOINT *endpoint, const GWEN_MSG *msgReceived) -{ - AQH_HTTP_SERVICE *xsv; - AQH_HTTP_REQUEST *rq; - const char *s; - const char *cmd; - const char *protocol; - AQH_SESSION *session=NULL; - GWEN_MSG *msgResponse; - int rv; - AQH_HTTP_URLHANDLER *uh; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Not a AQH_HttpService object"); - return NULL; - } - - rq=AQH_HttpRequest_new(endpoint, msgReceived); - if (rq==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "Could not create valie request from incoming message"); - return AQH_HttpService_CreateResponseMsg(sv, 500, "Internal server error", "HTTP/1.1", NULL); - } - - cmd=AQH_HttpRequest_GetCommand(rq); - protocol=AQH_HttpRequest_GetProtocol(rq); - -#if 0 - s=AQH_HttpRequest_GetModuleName(rq); - if (s && *s) { - m=AQH_HttpService_GetModule(sv, s); - if (m==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "Module \"%s\" not found", s); - } - else - AQH_HttpRequest_SetModule(rq, m); - } -#endif - - s=AQH_HttpRequest_GetSessionId(rq); - if (s && *s) { - session=AQH_HttpService_GetSession(sv, s); - if (session==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "Session \"%s\" not found", s); - } - else { - GWEN_TIMESTAMP *ts; - - DBG_INFO(AQH_LOGDOMAIN, "Found session \"%s\"", s); - ts=GWEN_Timestamp_NowInLocalTime(); - AQH_Session_SetTimestampLastAccess(session, ts); - GWEN_Timestamp_free(ts); - AQH_Session_AddRuntimeFlags(session, AQH_SESSION_RTFLAGS_MODIFIED); - AQH_HttpRequest_SetSession(rq, session); - } - } - - s=AQH_HttpRequest_GetUrlPath(rq); - DBG_INFO(AQH_LOGDOMAIN, "Received \"%s\" request for url \"%s\"", cmd?cmd:"", s); - uh=_findMatchingUrlHandler(sv, s); - if (uh==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "No matching handler found for url \"%s\"", s); - AQH_HttpRequest_free(rq); - return AQH_HttpService_CreateResponseMsg(sv, 404, "Not found", protocol?protocol:"http/1.1", NULL); - } - - rv=AQH_HttpUrlHandler_HandleMessage(uh, rq); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "Error handling request"); - AQH_HttpRequest_free(rq); - return AQH_HttpService_CreateResponseMsg(sv, 500, "Internal server error", protocol?protocol:"http/1.1", NULL); - } - msgResponse=AQH_HttpRequest_TakeResponseMsg(rq); - AQH_HttpRequest_free(rq); - return msgResponse; -} - - - -void AQH_HttpService_AddUrlHandler(AQH_SERVICE *sv, AQH_HTTP_URLHANDLER *urlHandler) -{ - AQH_HTTP_SERVICE *xsv; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Not a AQH_HttpService object"); - } - else { - AQH_HttpUrlHandler_List_Add(urlHandler, xsv->urlHandlerList); - } -} - - - -void AQH_HttpService_SetRequestPerms(AQH_SERVICE *sv, AQH_HTTP_REQUEST *rq) -{ - AQH_MODULE *m; - AQH_SESSION *session; - - AQH_HttpRequest_SetModulePerms(rq, 0); - m=AQH_HttpRequest_GetModule(rq); - session=AQH_HttpRequest_GetSession(rq); - if (m) { - DBG_INFO(AQH_LOGDOMAIN, "Presetting module's guest perms"); - AQH_HttpRequest_SetModulePerms(rq, AQH_Module_GetGuestPerms(m)); - if (session) { - AQH_USER * user; - - user=AQH_Session_GetUser(session); - if (user) { - AQH_MODULE_PERMS_LIST *permsList; - - permsList=AQH_User_GetModulePermList(user); - if (permsList) { - AQH_MODULE_PERMS *userPerms; - - userPerms=AQH_ModulePerms_List_GetByModuleId(AQH_User_GetModulePermList(user), AQH_Module_GetId(m)); - if (userPerms) { - DBG_INFO(AQH_LOGDOMAIN, "Using user perms for module"); - AQH_HttpRequest_SetModulePerms(rq, AQH_ModulePerms_GetPerms(userPerms)); - } - } - else { - DBG_INFO(AQH_LOGDOMAIN, "No module perms list in user, using module's guest perms"); - } - } - else { - DBG_INFO(AQH_LOGDOMAIN, "Session but no user, SNH!"); - } - } - else { - DBG_INFO(AQH_LOGDOMAIN, "No session, using module's guest perms"); - } - } - else { - DBG_INFO(AQH_LOGDOMAIN, "No module, no perms"); - } -} - - - -void AQH_HttpService_AddStatusLine(AQH_SERVICE *sv, int code, const char *msg, const char *proto, GWEN_BUFFER *buf) -{ - GWEN_Buffer_AppendArgs(buf, "%s %03d %s \r\n", proto?proto:"HTTP/1.1", code, msg?msg:""); -} - - - -void AQH_HttpService_AddHeader(AQH_SERVICE *sv, GWEN_DB_NODE *dbHeader, GWEN_BUFFER *buf) -{ - GWEN_DB_NODE *dbVar; - - dbVar=GWEN_DB_GetFirstVar(dbHeader); - while (dbVar) { - GWEN_DB_NODE *dbVal; - - /* only handle first value */ - dbVal=GWEN_DB_GetFirstValue(dbVar); - if (dbVal) { - const char *sVar; - - sVar=GWEN_DB_VariableName(dbVar); - if (sVar && *sVar) { - GWEN_DB_NODE_TYPE vtype; - - vtype=GWEN_DB_GetValueType(dbVal); - if (vtype==GWEN_DB_NodeType_ValueChar) { - const char *sValue; - - sValue=GWEN_DB_GetCharValueFromNode(dbVal); - if (sValue) - GWEN_Buffer_AppendArgs(buf, "%s: %s\r\n", sVar, sValue); - } /* if char */ - else if (vtype==GWEN_DB_NodeType_ValueInt) { - int i; - - i=GWEN_DB_GetIntValueFromNode(dbVal); - if (i!=-1 || strcasecmp(sVar, "Content-Length")==0) - GWEN_Buffer_AppendArgs(buf, "%s: %d\r\n", sVar, i); - } /* if int */ - else { - DBG_INFO(AQH_LOGDOMAIN, "Variable type %d of var [%s] not supported, ignoring", vtype, sVar); - } - } /* if sVar */ - } - dbVar=GWEN_DB_GetNextVar(dbVar); - } - - /* finalize header */ - GWEN_Buffer_AppendString(buf, "\r\n"); -} - - - -GWEN_MSG *AQH_HttpService_CreateResponseMsg(AQH_SERVICE *sv, int code, const char *text, const char *protocol, const char *page) -{ - GWEN_BUFFER *buf; - GWEN_MSG *msg; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - AQH_HttpService_AddStatusLine(sv, code, text, protocol, buf); - _writeDefaultResponseHeaderToBuffer(sv, (page && *page)?strlen(page):0, buf); - - if (page && *page) - GWEN_Buffer_AppendString(buf, page); - - msg=GWEN_Msg_fromBytes((const uint8_t*)GWEN_Buffer_GetStart(buf), GWEN_Buffer_GetUsedBytes(buf)); - GWEN_Buffer_free(buf); - return msg; -} - - - -GWEN_MSG *AQH_HttpService_CreateRedirectingResponseMsg(AQH_SERVICE *sv, const char *protocol, const char *newPage) -{ - GWEN_BUFFER *buf; - GWEN_MSG *msg; - GWEN_DB_NODE *db; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - AQH_HttpService_AddStatusLine(sv, 303, "OK, redirecting to content", protocol, buf); - db=GWEN_DB_Group_new("header"); - GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "Connection", "Keep-Alive"); - GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "Content-Type", "text/html; charset=utf-8"); - GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "Location", newPage); - GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "Content-Length", 0); - AQH_HttpService_AddHeader(sv, db, buf); - GWEN_DB_Group_free(db); - - msg=GWEN_Msg_fromBytes((const uint8_t*)GWEN_Buffer_GetStart(buf), GWEN_Buffer_GetUsedBytes(buf)); - GWEN_Buffer_free(buf); - return msg; -} - - - -int AQH_HttpService_AddFile(AQH_SERVICE *sv, GWEN_UNUSED AQH_SESSION *session, const char *fname, GWEN_BUFFER *buf) -{ - if (fname && *fname) { - int rv; - GWEN_BUFFER *nameBuf; - - nameBuf=_getPageFilePath(sv, NULL, fname); - - rv=GWEN_SyncIo_Helper_ReadFile(GWEN_Buffer_GetStart(nameBuf), buf); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error reading file \"%s\": %d", fname, rv); - GWEN_Buffer_free(nameBuf); - return rv; - } - GWEN_Buffer_free(nameBuf); - } - - return 0; -} - - - -void AQH_HttpService_SetupModuleAndPerms(AQH_SERVICE *sv, AQH_HTTP_REQUEST *rq, const char *modulName) -{ - AQH_SESSION *session; - AQH_MODULE *m; - - AQH_HttpRequest_SetModuleName(rq, modulName); - m=AQH_HttpService_GetModule(sv, modulName); - if (m==NULL) { - DBG_ERROR(NULL, "Module \"%s\" not found", modulName); - AQH_HttpRequest_SetModulePerms(rq, 0); - } - else { - AQH_HttpRequest_SetModule(rq, m); - } - - session=AQH_HttpRequest_GetSession(rq); - if (session) { - AQH_USER *u; - - u=AQH_Session_GetUser(session); - if (u) { - if (strcasecmp(AQH_User_GetAlias(u), AQH_HTTP_SERVICE_ADMINUSER)==0) { - DBG_ERROR(NULL, "special admin user, full access granted"); - AQH_HttpRequest_SetModulePerms(rq, 0xffffffff); - return; - } - } - } - AQH_HttpService_SetRequestPerms(sv, rq); -} - - - -GWEN_BUFFER *_getPageFilePath(const AQH_SERVICE *sv, const char *langFolder, const char *fileName) -{ - const char *sourceFolder; - - sourceFolder=AQH_HttpService_GetSourceFolder(sv); - if (!(sourceFolder && *sourceFolder)) { - DBG_ERROR(AQH_LOGDOMAIN, "No source folder given"); - return NULL; - } - else { - GWEN_BUFFER *nameBuf; - - nameBuf=GWEN_Buffer_new(0, 256, 0, 1); - GWEN_Buffer_AppendString(nameBuf, sourceFolder); - GWEN_Buffer_AppendString(nameBuf, GWEN_DIR_SEPARATOR_S); - if (langFolder && *langFolder) { - GWEN_Buffer_AppendString(nameBuf, langFolder); - GWEN_Buffer_AppendString(nameBuf, GWEN_DIR_SEPARATOR_S); - } - GWEN_Text_EscapeToBufferTolerant(fileName, nameBuf); - return nameBuf; - } -} - - - - - - -void _writeDefaultResponseHeaderToBuffer(AQH_SERVICE *sv, int contentLength, GWEN_BUFFER *buf) -{ - GWEN_DB_NODE *db; - - db=GWEN_DB_Group_new("header"); - GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "Connection", "Keep-Alive"); - GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "Content-Type", "text/html; charset=utf-8"); - GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "Content-Length", contentLength); - - AQH_HttpService_AddHeader(sv, db, buf); - GWEN_DB_Group_free(db); -} - - - -AQH_HTTP_URLHANDLER *_findMatchingUrlHandler(AQH_SERVICE *sv, const char *path) -{ - AQH_HTTP_SERVICE *xsv; - AQH_HTTP_URLHANDLER *uh; - - xsv=GWEN_INHERIT_GETDATA(AQH_SERVICE, AQH_HTTP_SERVICE, sv); - if (xsv==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Not a AQH_HttpService object"); - return NULL; - } - - uh=AQH_HttpUrlHandler_List_First(xsv->urlHandlerList); - while(uh) { - if (AQH_HttpUrlHandler_UrlMatches(uh, path)) { - DBG_INFO(AQH_LOGDOMAIN, "Found matching url handler for \"%s\"", path); - return uh; - } - uh=AQH_HttpUrlHandler_List_Next(uh); - } - DBG_INFO(AQH_LOGDOMAIN, "No matching url handler for \"%s\"", path); - return NULL; -} - - - diff --git a/aqhome/http/httpservice_http.h b/aqhome/http/httpservice_http.h deleted file mode 100644 index b8c0892..0000000 --- a/aqhome/http/httpservice_http.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_HTTP_SERVICE_HTTP_H -#define AQH_HTTP_SERVICE_HTTP_H - - -#include "aqhome/service/service.h" -#include "aqhome/http/httprequest.h" -#include "aqhome/http/urlhandler.h" - -#include -#include -#include - - -#define AQH_HTTP_SERVICE_SESSIONCOOKIE "sessionid" - - -AQHOME_API GWEN_MSG *AQH_HttpService_HandleHttpRequest(AQH_SERVICE *sv, GWEN_MSG_ENDPOINT *endpoint, const GWEN_MSG *msgReceived); - -AQHOME_API void AQH_HttpService_AddUrlHandler(AQH_SERVICE *sv, AQH_HTTP_URLHANDLER *urlHandler); - - -/** - * Set modulname in request, get and set matching module and determine the calling users permissions in regard - * to the selected module. - */ -AQHOME_API void AQH_HttpService_SetupModuleAndPerms(AQH_SERVICE *sv, AQH_HTTP_REQUEST *rq, const char *modulName); - - -/** - * Set permissions for this request according to session, user and module. - * - * The members session and module must have been set before calling this function. - */ -AQHOME_API void AQH_HttpService_SetRequestPerms(AQH_SERVICE *sv, AQH_HTTP_REQUEST *rq); - - -AQHOME_API void AQH_HttpService_AddStatusLine(AQH_SERVICE *sv, int code, const char *msg, const char *proto, GWEN_BUFFER *buf); -AQHOME_API void AQH_HttpService_AddHeader(AQH_SERVICE *sv, GWEN_DB_NODE *dbHeader, GWEN_BUFFER *buf); - -AQHOME_API int AQH_HttpService_ParsePostBody(AQH_SERVICE *sv, const GWEN_MSG *msgReceived, GWEN_DB_NODE *dbBody); - - -AQHOME_API GWEN_MSG *AQH_HttpService_CreateResponseMsg(AQH_SERVICE *sv, - int code, const char *text, const char *protocol, - const char *page); - -AQHOME_API GWEN_MSG *AQH_HttpService_CreateRedirectingResponseMsg(AQH_SERVICE *sv, const char *protocol, const char *newPage); - - -AQHOME_API int AQH_HttpService_AddFile(AQH_SERVICE *sv, AQH_SESSION *session, const char *fname, GWEN_BUFFER *buf); - - -#endif - - - diff --git a/aqhome/http/httpservice_login.c b/aqhome/http/httpservice_login.c deleted file mode 100644 index 59e848e..0000000 --- a/aqhome/http/httpservice_login.c +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include "aqhome/http/httpservice_login.h" -#include "aqhome/http/httpservice_p.h" - -#include -#include -#include -#include - - - -/* - Login process: - - GET: send a login page - - POST: - - get USER and PASS - - look for user (maybe add virtual function to load a user?) - - check password - - if all okay: - - create session - - add header "set-cookie" - - redirect to main page - */ - -GWEN_MSG *AQH_HttpService_HandleLoginUrl(AQH_SERVICE *sv, const GWEN_MSG *msgReceived, const GWEN_URL *url) -{ - -} - - - - - diff --git a/aqhome/http/httpservice_login.h b/aqhome/http/httpservice_login.h deleted file mode 100644 index 186c725..0000000 --- a/aqhome/http/httpservice_login.h +++ /dev/null @@ -1,30 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_HTTP_SERVICE_LOGIN_H -#define AQH_HTTP_SERVICE_LOGIN_H - - - -#include "aqhome/http/httpservice.h" - -#include -#include -#include -#include - - - -AQHOME_API GWEN_MSG *AQH_HttpService_HandleLoginUrl(AQH_SERVICE *sv, const GWEN_MSG *msgReceived, const GWEN_URL *url); - - - -#endif - - - diff --git a/aqhome/http/httpservice_p.h b/aqhome/http/httpservice_p.h deleted file mode 100644 index 0426c50..0000000 --- a/aqhome/http/httpservice_p.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_HTTP_SERVICE_P_H -#define AQH_HTTP_SERVICE_P_H - - -#include "aqhome/http/httpservice.h" - - -#define AQH_HTTP_SERVICE_DEFAULT_MAXSESSIONAGE 600 /* 10m */ - - -typedef struct AQH_HTTP_SERVICE AQH_HTTP_SERVICE; -struct AQH_HTTP_SERVICE { - char *sourceFolder; - char *configFolder; - - char *siteHeader; - char *siteFooter; - - uint32_t lastModuleId; - uint32_t lastUserId; - - int maxSessionAgeInSecs; - - GWEN_MUTEX *moduleMutex; - GWEN_MUTEX *userMutex; - GWEN_MUTEX *sessionMutex; - - AQH_HTTP_URLHANDLER_LIST *urlHandlerList; -}; - - - -#endif - - - diff --git a/aqhome/http/urlhandler.c b/aqhome/http/urlhandler.c deleted file mode 100644 index 4e131e8..0000000 --- a/aqhome/http/urlhandler.c +++ /dev/null @@ -1,261 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -//#define DISABLE_DEBUGLOG - - -#include "./urlhandler_p.h" -#include "aqhome/http/httpservice_http.h" - -#include -#include -#include - - - -GWEN_INHERIT_FUNCTIONS(AQH_HTTP_URLHANDLER) -GWEN_LIST_FUNCTIONS(AQH_HTTP_URLHANDLER, AQH_HttpUrlHandler) - - - -static int _addContentHeaders(AQH_HTTP_CONTENT *c, int m, GWEN_BUFFER *dbuf); -static int _addContentFooters(AQH_HTTP_CONTENT *c, int m, GWEN_BUFFER *dbuf); - - - - -AQH_HTTP_URLHANDLER *AQH_HttpUrlHandler_new(AQH_SERVICE *sv) -{ - AQH_HTTP_URLHANDLER *uh; - - GWEN_NEW_OBJECT(AQH_HTTP_URLHANDLER, uh); - GWEN_INHERIT_INIT(AQH_HTTP_URLHANDLER, uh); - GWEN_LIST_INIT(AQH_HTTP_URLHANDLER, uh); - uh->urlPatternList=GWEN_StringList_new(); - uh->httpService=sv; - - return uh; -} - - - -void AQH_HttpUrlHandler_free(AQH_HTTP_URLHANDLER *uh) -{ - if (uh) { - GWEN_LIST_FINI(AQH_HTTP_URLHANDLER, uh); - GWEN_INHERIT_FINI(AQH_HTTP_URLHANDLER, uh); - - free(uh->folder); - GWEN_StringList_free(uh->urlPatternList); - GWEN_FREE_OBJECT(uh); - } -} - - - -AQH_SERVICE *AQH_HttpUrlHandler_GetHttpService(const AQH_HTTP_URLHANDLER *uh) -{ - return uh?uh->httpService:NULL; -} - - - -AQH_HTTP_CONTENT *AQH_HttpUrlHandler_GetContentProvider(const AQH_HTTP_URLHANDLER *uh) -{ - return uh?uh->httpContentProvider:NULL; -} - - - -void AQH_HttpUrlHandler_SetContentProvider(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_CONTENT *cp) -{ - if (uh) - uh->httpContentProvider=cp; -} - - - -void AQH_HttpUrlHandler_AddUrlPattern(AQH_HTTP_URLHANDLER *uh, const char *s) -{ - if (uh && s && *s) - GWEN_StringList_AppendString(uh->urlPatternList, s, 0, 1); -} - - - -const char *AQH_HttpUrlHandler_GetFolder(const AQH_HTTP_URLHANDLER *uh) -{ - return uh?uh->folder:NULL; -} - - - -void AQH_HttpUrlHandler_SetFolder(AQH_HTTP_URLHANDLER *uh, const char *s) -{ - if (uh) { - free(uh->folder); - uh->folder=s?strdup(s):NULL; - } -} - - - -int AQH_HttpUrlHandler_UrlMatches(const AQH_HTTP_URLHANDLER *uh, const char *s) -{ - if (uh && s && *s) { - GWEN_STRINGLISTENTRY *se; - - se=GWEN_StringList_FirstEntry(uh->urlPatternList); - while(se) { - const char *pattern; - - pattern=GWEN_StringListEntry_Data(se); - if (GWEN_Text_ComparePattern(s, pattern, 0)!=-1) - return 1; - se=GWEN_StringListEntry_Next(se); - } - } - return 0; -} - - - -void AQH_HttpUrlHandler_SetHandleFn(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_URLHANDLER_HANDLE_FN fn) -{ - if (uh) - uh->handleFn=fn; -} - - - -int AQH_HttpUrlHandler_HandleMessage(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq) -{ - if (uh && uh->handleFn) - return uh->handleFn(uh, rq); - return 0; -} - - - -int AQH_HttpUrlHandler_AddContentHeaders(AQH_HTTP_URLHANDLER *uh, int m, GWEN_BUFFER *dbuf) -{ - return _addContentHeaders(uh->httpContentProvider, m, dbuf); -} - - - -int AQH_HttpUrlHandler_AddContentFooters(AQH_HTTP_URLHANDLER *uh, int m, GWEN_BUFFER *dbuf) -{ - return _addContentFooters(uh->httpContentProvider, m, dbuf); -} - - - -GWEN_MSG *AQH_HttpUrlHandler_CreatePageMessage(AQH_HTTP_URLHANDLER *uh, - AQH_HTTP_REQUEST *rq, - const char *statusTextColor, const char *statusMsg, - int withHeadersAndFooters, - GWEN_DB_NODE *dbValues, - AQH_HTTP_URLHANDLER_WRITEPAGE_CB cb) -{ - GWEN_BUFFER *pageBuf; - int rv; - GWEN_MSG *msgOut=NULL; - const char *protocol; - - protocol=AQH_HttpRequest_GetProtocol(rq); - pageBuf=GWEN_Buffer_new(0, 256, 0, 1); - if (withHeadersAndFooters) { - rv=AQH_HttpUrlHandler_AddContentHeaders(uh, AQH_HTTP_CONTENT_MODE_DESKTOP, pageBuf); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error adding headers"); - GWEN_Buffer_free(pageBuf); - return AQH_HttpService_CreateResponseMsg(uh->httpService, 500, "Internal Error", protocol, NULL); - } - } - - if (statusMsg) - GWEN_Buffer_AppendArgs(pageBuf, "

%s

", statusTextColor?statusTextColor:"black", statusMsg); - if (cb) { - rv=cb(uh, rq, dbValues, pageBuf); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error adding headers"); - GWEN_Buffer_free(pageBuf); - return AQH_HttpService_CreateResponseMsg(uh->httpService, 500, "Internal Error", protocol, NULL); - } - } - - if (withHeadersAndFooters) { - rv=AQH_HttpUrlHandler_AddContentFooters(uh, AQH_HTTP_CONTENT_MODE_DESKTOP, pageBuf); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error adding footers"); - GWEN_Buffer_free(pageBuf); - return AQH_HttpService_CreateResponseMsg(uh->httpService, 500, "Internal Error", protocol, NULL); - } - } - - msgOut=AQH_HttpService_CreateResponseMsg(uh->httpService, 200, "OK", protocol, GWEN_Buffer_GetStart(pageBuf)); - GWEN_Buffer_free(pageBuf); - return msgOut; -} - - - -int _addContentHeaders(AQH_HTTP_CONTENT *c, int m, GWEN_BUFFER *dbuf) -{ - AQH_HTTP_CONTENT *parent; - int rv; - - parent=AQH_HttpContent_Tree2_GetParent(c); - if (parent) { - rv=_addContentHeaders(parent, m, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "Error adding content headers for \"%s\"", AQH_HttpContent_GetName(parent)); - return rv; - } - } - rv=AQH_HttpContent_AddOpeningContent(c, m, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "Error adding content headers for \"%s\"", AQH_HttpContent_GetName(c)); - return rv; - } - - return 0; -} - - - -int _addContentFooters(AQH_HTTP_CONTENT *c, int m, GWEN_BUFFER *dbuf) -{ - AQH_HTTP_CONTENT *parent; - int rv; - - rv=AQH_HttpContent_AddClosingContent(c, m, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "Error adding content footers for \"%s\"", AQH_HttpContent_GetName(c)); - return rv; - } - - parent=AQH_HttpContent_Tree2_GetParent(c); - if (parent) { - rv=_addContentFooters(parent, m, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "Error adding content footers for \"%s\"", AQH_HttpContent_GetName(parent)); - return rv; - } - } - - return 0; -} - - - diff --git a/aqhome/http/urlhandler.h b/aqhome/http/urlhandler.h deleted file mode 100644 index 80ededc..0000000 --- a/aqhome/http/urlhandler.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_HTTP_URLHANDLER_H -#define AQH_HTTP_URLHANDLER_H - - -#include -#include -#include -#include - -#include -#include -#include -#include - - -typedef struct AQH_HTTP_URLHANDLER AQH_HTTP_URLHANDLER; -GWEN_INHERIT_FUNCTION_LIB_DEFS(AQH_HTTP_URLHANDLER, AQHOME_API) -GWEN_LIST_FUNCTION_LIB_DEFS(AQH_HTTP_URLHANDLER, AQH_HttpUrlHandler, AQHOME_API) - - -typedef int (*AQH_HTTP_URLHANDLER_HANDLE_FN)(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq); - -AQHOME_API AQH_HTTP_URLHANDLER *AQH_HttpUrlHandler_new(AQH_SERVICE *sv); -AQHOME_API void AQH_HttpUrlHandler_free(AQH_HTTP_URLHANDLER *uh); - -AQHOME_API AQH_SERVICE *AQH_HttpUrlHandler_GetHttpService(const AQH_HTTP_URLHANDLER *uh); - -AQHOME_API void AQH_HttpUrlHandler_AddUrlPattern(AQH_HTTP_URLHANDLER *uh, const char *s); -AQHOME_API int AQH_HttpUrlHandler_UrlMatches(const AQH_HTTP_URLHANDLER *uh, const char *s); - -AQHOME_API AQH_HTTP_CONTENT *AQH_HttpUrlHandler_GetContentProvider(const AQH_HTTP_URLHANDLER *uh); -AQHOME_API void AQH_HttpUrlHandler_SetContentProvider(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_CONTENT *cp); - -AQHOME_API const char *AQH_HttpUrlHandler_GetFolder(const AQH_HTTP_URLHANDLER *uh); -AQHOME_API void AQH_HttpUrlHandler_SetFolder(AQH_HTTP_URLHANDLER *uh, const char *s); - -AQHOME_API void AQH_HttpUrlHandler_SetHandleFn(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_URLHANDLER_HANDLE_FN fn); - -AQHOME_API int AQH_HttpUrlHandler_AddContentHeaders(AQH_HTTP_URLHANDLER *uh, int m, GWEN_BUFFER *dbuf); -AQHOME_API int AQH_HttpUrlHandler_AddContentFooters(AQH_HTTP_URLHANDLER *uh, int m, GWEN_BUFFER *dbuf); - - -AQHOME_API int AQH_HttpUrlHandler_HandleMessage(AQH_HTTP_URLHANDLER *uh, AQH_HTTP_REQUEST *rq); - - - -typedef int (*AQH_HTTP_URLHANDLER_WRITEPAGE_CB)(AQH_HTTP_URLHANDLER *uh, - AQH_HTTP_REQUEST *rq, - GWEN_DB_NODE *dbValues, - GWEN_BUFFER *pageBuf); -AQHOME_API GWEN_MSG *AQH_HttpUrlHandler_CreatePageMessage(AQH_HTTP_URLHANDLER *uh, - AQH_HTTP_REQUEST *rq, - const char *statusTextColor, const char *statusMsg, - int withHeadersAndFooters, - GWEN_DB_NODE *dbValues, - AQH_HTTP_URLHANDLER_WRITEPAGE_CB cb); - - - -#endif - - diff --git a/aqhome/http/urlhandler_p.h b/aqhome/http/urlhandler_p.h deleted file mode 100644 index edc3390..0000000 --- a/aqhome/http/urlhandler_p.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_HTTP_URLHANDLER_P_H -#define AQH_HTTP_URLHANDLER_P_H - - -#include "aqhome/http/urlhandler.h" - - -typedef struct AQH_HTTP_URLHANDLER AQH_HTTP_URLHANDLER; -struct AQH_HTTP_URLHANDLER { - GWEN_INHERIT_ELEMENT(AQH_HTTP_URLHANDLER); - GWEN_LIST_ELEMENT(AQH_HTTP_URLHANDLER); - - AQH_SERVICE *httpService; - GWEN_STRINGLIST *urlPatternList; - AQH_HTTP_CONTENT *httpContentProvider; - char *folder; - - AQH_HTTP_URLHANDLER_HANDLE_FN handleFn; -}; - - - -#endif - - - diff --git a/aqhome/ipc/0BUILD b/aqhome/ipc/0BUILD deleted file mode 100644 index 5f7fbe3..0000000 --- a/aqhome/ipc/0BUILD +++ /dev/null @@ -1,94 +0,0 @@ - - - - - - - - $(gwenhywfar_cflags) - -I$(topsrcdir) - -I$(topbuilddir) - - - - --include=$(builddir) - --include=$(srcdir) - - - - - - $(visibility_cflags) - - - - --api=AQHOME_API - - - - - - - - - - - - - - - - - - $(local/built_headers_pub) - - - - - endpoint_ipc.h - endpoint_ipcclient.h - msg_ipc_qwords.h - msg_ipc_result.h - msg_ipc_tag16.h - requests.h - - - - - endpoint_ipc_p.h - msg_ipc_tag16_p.h - - - - - $(local/typefiles) - - endpoint_ipc.c - endpoint_ipcclient.c - msg_ipc_qwords.c - msg_ipc_result.c - msg_ipc_tag16.c - requests.c - - - - - - - - - aqhipcnodes - aqhipcdata - - - - nodes - data - - - - - - - - diff --git a/aqhome/ipc/data/0BUILD b/aqhome/ipc/data/0BUILD deleted file mode 100644 index 0094a46..0000000 --- a/aqhome/ipc/data/0BUILD +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - $(gwenhywfar_cflags) - -I$(topsrcdir) - -I$(topbuilddir) - - - - --include=$(builddir) - --include=$(srcdir) - - - - - - $(visibility_cflags) - - - - --api=AQHOME_API - - - - - - - - - - - - - - - - - - $(local/built_headers_pub) - - - - - ipc_data.h - msg_data_connect.h - msg_data_datapoints.h - msg_data_devices.h - msg_data_getdata.h - msg_data_multidata.h - msg_data_values.h - msg_data_set.h - - - - - - - - - $(local/typefiles) - - ipc_data.c - msg_data_connect.c - msg_data_datapoints.c - msg_data_devices.c - msg_data_getdata.c - msg_data_multidata.c - msg_data_values.c - msg_data_set.c - - - - - - - - - - - - - - - - - diff --git a/aqhome/ipc/data/cmd_data.c b/aqhome/ipc/data/cmd_data.c deleted file mode 100644 index 462979d..0000000 --- a/aqhome/ipc/data/cmd_data.c +++ /dev/null @@ -1,44 +0,0 @@ - - - - - -GWEN_MSG *AQH_CmdDataIpc_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT *epTcp, int msgCode, int timeoutInSeconds) -{ - time_t startTime; - - startTime=time(NULL); - - for (;;) { - GWEN_MSG *msg; - time_t now; - - while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp)) ) { - uint16_t code; - - code=GWEN_IpcMsg_GetCode(msg); - if (code==msgCode) { - DBG_INFO(NULL, "Received expected IPC message"); - return msg; - } - else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) { - DBG_INFO(NULL, "Received IPC result message"); - return msg; - } - else { - DBG_INFO(NULL, "Received unexpected message %d (%x)", code, code); - } - GWEN_Msg_free(msg); - } - now=time(NULL); - if (now-startTime>timeoutInSeconds) { - DBG_INFO(NULL, "Timeout"); - break; - } - GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */ - } - - return NULL; -} - - diff --git a/aqhome/ipc/data/cmd_data_getdata.c b/aqhome/ipc/data/cmd_data_getdata.c deleted file mode 100644 index f8c0e49..0000000 --- a/aqhome/ipc/data/cmd_data_getdata.c +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - - - - -GWEN_MSG *_waitForMatchingResponse(GWEN_MSG_ENDPOINT *epTcp, int msgCode, int timeoutInSeconds); - - - - -GWEN_MSG *AQH_CmdDataIpc_RequestDatapointsMsg(GWEN_MSG_ENDPOINT *ep, - const char *valueName, uint64_t tsBegin, uint64_t tsEnd, uint64_t num, - int timeoutInSeconds) -{ - GWEN_MSG *msg; - time_t startTime; - - msg=AQH_GetDataDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_GETDATA_REQ, valueName, tsBegin, tsEnd, num); - GWEN_MsgEndpoint_AddSendMessage(ep, msg); - - msg=_waitForMatchingResponse(ep, AQH_MSGTYPE_IPC_DATA_GETDATA_RSP, timeoutInSeconds); - if (msg) { - uint16_t code; - - code=GWEN_IpcMsg_GetCode(msg); - if (code==AQH_MSGTYPE_IPC_DATA_RESULT) { - uint32_t resultCode; - - resultCode=AQH_ResultIpcMsg_GetResultCode(msg); - DBG_INFO(AQH_LOGDOMAIN, "IPC error: %d", resultCode); - GWEN_Msg_free(msg); - return NULL; - } - else if (code==AQH_MSGTYPE_IPC_DATA_GETDATA_RSP) { - int rv; - - AQH_MultiDataDataIpcMsg_Parse(msg, 0); - return msg; - } - GWEN_Msg_free(msg); - } - return NULL; -} - - - -GWEN_MSG *_waitForMatchingResponse(GWEN_MSG_ENDPOINT *epTcp, int msgCode, int timeoutInSeconds) -{ - time_t startTime; - - startTime=time(NULL); - - for (;;) { - GWEN_MSG *msg; - time_t now; - - while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp)) ) { - uint16_t code; - - code=GWEN_IpcMsg_GetCode(msg); - if (code==msgCode) { - DBG_INFO(NULL, "Received expected IPC message"); - return msg; - } - else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) { - DBG_INFO(NULL, "Received IPC result message"); - return msg; - } - else { - DBG_INFO(NULL, "Received unexpected message %d (%x), ignoring", code, code); - } - GWEN_Msg_free(msg); - } /* while */ - - now=time(NULL); - if (now-startTime>timeoutInSeconds) { - DBG_INFO(NULL, "Timeout"); - break; - } - GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */ - } - - return NULL; -} - - - diff --git a/aqhome/ipc/data/ipc_data.c b/aqhome/ipc/data/ipc_data.c deleted file mode 100644 index f76c284..0000000 --- a/aqhome/ipc/data/ipc_data.c +++ /dev/null @@ -1,502 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include -#include - -#include -#include - - -/* ------------------------------------------------------------------------------------------------ - * defines - * ------------------------------------------------------------------------------------------------ - */ - -#define AQH_IPCDATA_VALUE_TAGS_ID 0x01 -#define AQH_IPCDATA_VALUE_TAGS_DRIVER 0x02 -#define AQH_IPCDATA_VALUE_TAGS_NAMEFORDRIVER 0x03 -#define AQH_IPCDATA_VALUE_TAGS_NAMEFORSYSTEM 0x04 -#define AQH_IPCDATA_VALUE_TAGS_TYPE 0x05 -#define AQH_IPCDATA_VALUE_TAGS_UNITS 0x06 -#define AQH_IPCDATA_VALUE_TAGS_TIMEOFCREATION 0x07 -#define AQH_IPCDATA_VALUE_TAGS_DEVFORDRIVER 0x08 -#define AQH_IPCDATA_VALUE_TAGS_DEVFORSYSTEM 0x09 -#define AQH_IPCDATA_VALUE_TAGS_MODALITY 0x0a - -#define AQH_IPCDATA_DEVICE_TAGS_ID 0x01 -#define AQH_IPCDATA_DEVICE_TAGS_DRIVER 0x02 -#define AQH_IPCDATA_DEVICE_TAGS_ROOMNAME 0x03 -#define AQH_IPCDATA_DEVICE_TAGS_NAMEFORDRIVER 0x04 -#define AQH_IPCDATA_DEVICE_TAGS_NAMEFORSYSTEM 0x05 -#define AQH_IPCDATA_DEVICE_TAGS_NAMEFORGUI 0x06 -#define AQH_IPCDATA_DEVICE_TAGS_LOCATION 0x07 -#define AQH_IPCDATA_DEVICE_TAGS_DESCRIPTION 0x08 -#define AQH_IPCDATA_DEVICE_TAGS_DEVTYPE 0x09 -#define AQH_IPCDATA_DEVICE_TAGS_MANUFACTURER 0x0a -#define AQH_IPCDATA_DEVICE_TAGS_TIMEOFCREATION 0x0b - - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static void _writeValueFieldsAsTagsToBuffer(const AQH_VALUE *value, GWEN_BUFFER *buf); -static AQH_VALUE *_readValueFromTag(const uint8_t *ptr, uint32_t len); -static void _writeDeviceFieldsAsTagsToBuffer(const AQH_DEVICE *device, GWEN_BUFFER *buf); -static AQH_DEVICE *_readDeviceFromTag(const uint8_t *ptr, uint32_t len); - - - -/* ------------------------------------------------------------------------------------------------ - * code - * ------------------------------------------------------------------------------------------------ - */ - - - -int AQH_DataIpc_WriteValueListAsTagsToBuffer(unsigned int tagType, const AQH_VALUE_LIST *valueList, GWEN_BUFFER *buf) -{ - if (valueList) { - const AQH_VALUE *value; - - value=AQH_Value_List_First(valueList); - while(value) { - int rv; - - rv=AQH_DataIpc_WriteValueAsTagToBuffer(tagType, value, buf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Buffer_free(buf); - return rv; - } - - value=AQH_Value_List_Next(value); - } - } - return 0; -} - - - -int AQH_DataIpc_WriteValueAsTagToBuffer(unsigned int tagType, const AQH_VALUE *value, GWEN_BUFFER *buf) -{ - int startPos; - int rv; - - startPos=GWEN_Tag16_StartTagInBuffer(tagType, buf); - if (startPos<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", startPos); - return startPos; - } - - _writeValueFieldsAsTagsToBuffer(value, buf); - - rv=GWEN_Tag16_EndTagInBuffer(startPos, buf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - return 0; -} - - - -int AQH_DataIpc_WriteDeviceListAsTagsToBuffer(unsigned int tagType, const AQH_DEVICE_LIST *deviceList, GWEN_BUFFER *buf) -{ - if (deviceList) { - const AQH_DEVICE *device; - - device=AQH_Device_List_First(deviceList); - while(device) { - int rv; - - rv=AQH_DataIpc_WriteDeviceAsTagToBuffer(tagType, device, buf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Buffer_free(buf); - return rv; - } - - device=AQH_Device_List_Next(device); - } - } - return 0; -} - - - -int AQH_DataIpc_WriteDeviceAsTagToBuffer(unsigned int tagType, const AQH_DEVICE *device, GWEN_BUFFER *buf) -{ - int startPos; - int rv; - - startPos=GWEN_Tag16_StartTagInBuffer(tagType, buf); - if (startPos<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", startPos); - return startPos; - } - - _writeDeviceFieldsAsTagsToBuffer(device, buf); - - rv=GWEN_Tag16_EndTagInBuffer(startPos, buf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - - return 0; -} - - - -void _writeValueFieldsAsTagsToBuffer(const AQH_VALUE *value, GWEN_BUFFER *buf) -{ - const char *s; - - GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_VALUE_TAGS_ID, AQH_Value_GetId(value), buf); - - s=AQH_Value_GetDriver(value); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_DRIVER, s, buf); - - s=AQH_Value_GetName(value); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_NAMEFORDRIVER, s, buf); - - s=AQH_Value_GetNameForSystem(value); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_NAMEFORSYSTEM, s, buf); - - GWEN_Tag16_WriteUint32TagToBuffer(AQH_IPCDATA_VALUE_TAGS_TYPE, AQH_Value_GetValueType(value), buf); - - s=AQH_Value_GetValueUnits(value); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_UNITS, s, buf); - - GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_VALUE_TAGS_TIMEOFCREATION, AQH_Value_GetTimestampCreation(value), buf); - - s=AQH_Value_GetDeviceName(value); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_DEVFORDRIVER, s, buf); - - s=AQH_Value_GetDeviceNameForSystem(value); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_DEVFORSYSTEM, s, buf); - - GWEN_Tag16_WriteUint32TagToBuffer(AQH_IPCDATA_VALUE_TAGS_MODALITY, AQH_Value_GetModality(value), buf); - -} - - - - - - -AQH_VALUE_LIST *AQH_DataIpc_ReadValuesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType) -{ - AQH_VALUE_LIST *valueList; - const GWEN_TAG16 *tag; - - valueList=AQH_Value_List_new(); - tag=GWEN_Tag16_List_First(tagList); - while(tag) { - unsigned int tagType; - AQH_VALUE *value; - - tagType=GWEN_Tag16_GetTagType(tag); - if (tagType==wantedTagType) { - value=_readValueFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag)); - if (value) - AQH_Value_List_Add(value, valueList); - } - - tag=GWEN_Tag16_List_Next(tag); - } - - if (AQH_Value_List_GetCount(valueList)<1) { - AQH_Value_List_free(valueList); - return NULL; - } - - return valueList; -} - - - -AQH_VALUE *AQH_DataIpc_ReadValueFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType) -{ - if (tagList) { - const GWEN_TAG16 *tag; - - tag=GWEN_Tag16_List_FindFirstByTagType(tagList, wantedTagType); - return tag?_readValueFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag)):NULL; - } - return NULL; -} - - - -AQH_DEVICE_LIST *AQH_DataIpc_ReadDevicesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType) -{ - AQH_DEVICE_LIST *deviceList; - const GWEN_TAG16 *tag; - - deviceList=AQH_Device_List_new(); - tag=GWEN_Tag16_List_First(tagList); - while(tag) { - unsigned int tagType; - AQH_DEVICE *device; - - tagType=GWEN_Tag16_GetTagType(tag); - if (tagType==wantedTagType) { - device=_readDeviceFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag)); - if (device) - AQH_Device_List_Add(device, deviceList); - } - - tag=GWEN_Tag16_List_Next(tag); - } - - if (AQH_Device_List_GetCount(deviceList)<1) { - AQH_Device_List_free(deviceList); - return NULL; - } - - return deviceList; -} - - - -AQH_DEVICE *AQH_DataIpc_ReadDeviceFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType) -{ - if (tagList) { - const GWEN_TAG16 *tag; - - tag=GWEN_Tag16_List_FindFirstByTagType(tagList, wantedTagType); - return tag?_readDeviceFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag)):NULL; - } - return NULL; -} - - - -AQH_VALUE *_readValueFromTag(const uint8_t *ptr, uint32_t len) -{ - GWEN_TAG16_LIST *tagList; - - tagList=GWEN_Tag16_List_fromBuffer(ptr, len, 0); - if (tagList) { - GWEN_TAG16 *tag; - AQH_VALUE *value; - - value=AQH_Value_new(); - tag=GWEN_Tag16_List_First(tagList); - while(tag) { - unsigned int tagType; - char *s; - - tagType=GWEN_Tag16_GetTagType(tag); - switch(tagType) { - case AQH_IPCDATA_VALUE_TAGS_ID: - AQH_Value_SetId(value, GWEN_Tag16_GetTagDataAsUint64(tag, 0)); - break; - case AQH_IPCDATA_VALUE_TAGS_DRIVER: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Value_SetDriver(value, s); - free(s); - break; - case AQH_IPCDATA_VALUE_TAGS_NAMEFORDRIVER: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Value_SetName(value, s); - free(s); - break; - case AQH_IPCDATA_VALUE_TAGS_NAMEFORSYSTEM: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Value_SetNameForSystem(value, s); - free(s); - break; - case AQH_IPCDATA_VALUE_TAGS_TYPE: - AQH_Value_SetValueType(value, GWEN_Tag16_GetTagDataAsUint32(tag, 0)); - break; - case AQH_IPCDATA_VALUE_TAGS_UNITS: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Value_SetValueUnits(value, s); - free(s); - break; - case AQH_IPCDATA_VALUE_TAGS_TIMEOFCREATION: - AQH_Value_SetTimestampCreation(value, GWEN_Tag16_GetTagDataAsUint64(tag, 0)); - break; - case AQH_IPCDATA_VALUE_TAGS_DEVFORDRIVER: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Value_SetDeviceName(value, s); - free(s); - break; - case AQH_IPCDATA_VALUE_TAGS_DEVFORSYSTEM: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Value_SetDeviceNameForSystem(value, s); - free(s); - break; - case AQH_IPCDATA_VALUE_TAGS_MODALITY: - AQH_Value_SetModality(value, GWEN_Tag16_GetTagDataAsUint32(tag, 0)); - break; - default: - DBG_INFO(AQH_LOGDOMAIN, "Unhandled tag typ %d (%02x)", tagType, tagType); - break; - } - tag=GWEN_Tag16_List_Next(tag); - } - GWEN_Tag16_List_free(tagList); - return value; - } - - return NULL; -} - - - -void _writeDeviceFieldsAsTagsToBuffer(const AQH_DEVICE *device, GWEN_BUFFER *buf) -{ - const char *s; - - GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_DEVICE_TAGS_ID, AQH_Device_GetId(device), buf); - - s=AQH_Device_GetDriver(device); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_DRIVER, s, buf); - - s=AQH_Device_GetRoomName(device); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_ROOMNAME, s, buf); - - s=AQH_Device_GetName(device); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_NAMEFORDRIVER, s, buf); - - s=AQH_Device_GetNameForSystem(device); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_NAMEFORSYSTEM, s, buf); - - s=AQH_Device_GetNameForGui(device); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_NAMEFORGUI, s, buf); - - s=AQH_Device_GetLocation(device); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_LOCATION, s, buf); - - s=AQH_Device_GetDescription(device); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_DESCRIPTION, s, buf); - - s=AQH_Device_GetDeviceType(device); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_DEVTYPE, s, buf); - - s=AQH_Device_GetManufacturer(device); - if (s && *s) - GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_MANUFACTURER, s, buf); - - GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_DEVICE_TAGS_TIMEOFCREATION, AQH_Device_GetTimestampCreation(device), buf); -} - - - -AQH_DEVICE *_readDeviceFromTag(const uint8_t *ptr, uint32_t len) -{ - GWEN_TAG16_LIST *tagList; - - tagList=GWEN_Tag16_List_fromBuffer(ptr, len, 0); - if (tagList) { - GWEN_TAG16 *tag; - AQH_DEVICE *device; - - device=AQH_Device_new(); - tag=GWEN_Tag16_List_First(tagList); - while(tag) { - unsigned int tagType; - char *s; - - tagType=GWEN_Tag16_GetTagType(tag); - switch(tagType) { - case AQH_IPCDATA_DEVICE_TAGS_ID: - AQH_Device_SetId(device, GWEN_Tag16_GetTagDataAsUint64(tag, 0)); - break; - case AQH_IPCDATA_DEVICE_TAGS_DRIVER: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Device_SetDriver(device, s); - free(s); - break; - case AQH_IPCDATA_DEVICE_TAGS_ROOMNAME: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Device_SetRoomName(device, s); - free(s); - break; - case AQH_IPCDATA_DEVICE_TAGS_NAMEFORDRIVER: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Device_SetName(device, s); - free(s); - break; - case AQH_IPCDATA_DEVICE_TAGS_NAMEFORSYSTEM: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Device_SetNameForSystem(device, s); - free(s); - break; - case AQH_IPCDATA_DEVICE_TAGS_NAMEFORGUI: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Device_SetNameForGui(device, s); - free(s); - break; - case AQH_IPCDATA_DEVICE_TAGS_LOCATION: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Device_SetLocation(device, s); - free(s); - break; - case AQH_IPCDATA_DEVICE_TAGS_DESCRIPTION: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Device_SetDescription(device, s); - free(s); - break; - case AQH_IPCDATA_DEVICE_TAGS_DEVTYPE: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Device_SetDeviceType(device, s); - free(s); - break; - case AQH_IPCDATA_DEVICE_TAGS_MANUFACTURER: - s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL); - AQH_Device_SetManufacturer(device, s); - free(s); - break; - case AQH_IPCDATA_DEVICE_TAGS_TIMEOFCREATION: - AQH_Device_SetTimestampCreation(device, GWEN_Tag16_GetTagDataAsUint64(tag, 0)); - break; - default: - DBG_INFO(AQH_LOGDOMAIN, "Unhandled tag typ %d (%02x)", tagType, tagType); - break; - } - tag=GWEN_Tag16_List_Next(tag); - } - GWEN_Tag16_List_free(tagList); - return device; - } - - return NULL; -} - - - - diff --git a/aqhome/ipc/data/ipc_data.h b/aqhome/ipc/data/ipc_data.h deleted file mode 100644 index 1bfd893..0000000 --- a/aqhome/ipc/data/ipc_data.h +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_DATA_H -#define AQH_MSG_IPC_DATA_H - - -#include -#include -#include - -#include -#include -#include - - - -#define AQH_IPC_PROTOCOL_DATA_ID 2 -#define AQH_IPC_PROTOCOL_DATA_VERSION 1 - - -#define AQH_MSGTYPE_IPC_DATA_RESULT 0x0001 /* AQH_ResultIpcMsg */ - -#define AQH_MSGTYPE_IPC_DATA_CONNECT_REQ 0x0010 /* serviceName, userName, password */ - -#define AQH_MSGTYPE_IPC_DATA_UPDATEDATA 0x0100 /* AQH_MultiDataDataIpcMsg */ -#define AQH_MSGTYPE_IPC_DATA_DATACHANGED 0x0200 /* AQH_MultiDataDataIpcMsg */ - -#define AQH_MSGTYPE_IPC_DATA_SETDATA 0x0300 /* AQH_SetDataIpcMsg */ - -#define AQH_MSGTYPE_IPC_DATA_ADDVALUE 0x0400 /* AQH_AddValueDataIpcMsg */ - -#define AQH_MSGTYPE_IPC_DATA_GETDATA_REQ 0x0500 /* AQH_GetDataDataIpcMsg */ -#define AQH_MSGTYPE_IPC_DATA_GETDATA_RSP 0x0600 /* AQH_MultiDataDataIpcMsg */ - -#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ 0x0700 /* AQH_GetDataDataIpcMsg */ -#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP 0x0800 /* AQH_MultiDataDataIpcMsg */ - -#define AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ 0x0900 /* GWEN_IpcMsg */ -#define AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP 0x0a00 /* AQH_ValuesDataIpcMsg */ - -#define AQH_MSGTYPE_IPC_DATA_GETDEVICES_REQ 0x0b00 /* GWEN_IpcMsg */ -#define AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP 0x0c00 /* AQH_DevicesDataIpcMsg */ - -#define AQH_MSGTYPE_IPC_DATA_MODDEVICE_REQ 0x0d00 /* AQH_DevicesDataIpcMsg */ - -#define AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE 0x0e00 /* AQH_ValuesDataIpcMsg */ - - - -/* utils */ -AQHOME_API int AQH_DataIpc_WriteValueListAsTagsToBuffer(unsigned int tagType, const AQH_VALUE_LIST *valueList, GWEN_BUFFER *buf); -AQHOME_API int AQH_DataIpc_WriteValueAsTagToBuffer(unsigned int tagType, const AQH_VALUE *value, GWEN_BUFFER *buf); -AQHOME_API AQH_VALUE_LIST *AQH_DataIpc_ReadValuesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType); -AQHOME_API AQH_VALUE *AQH_DataIpc_ReadValueFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType); - -AQHOME_API int AQH_DataIpc_WriteDeviceListAsTagsToBuffer(unsigned int tagType, const AQH_DEVICE_LIST *deviceList, GWEN_BUFFER *buf); -AQHOME_API int AQH_DataIpc_WriteDeviceAsTagToBuffer(unsigned int tagType, const AQH_DEVICE *device, GWEN_BUFFER *buf); -AQHOME_API AQH_DEVICE_LIST *AQH_DataIpc_ReadDevicesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType); -AQHOME_API AQH_DEVICE *AQH_DataIpc_ReadDeviceFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType); - - - -#endif - - - diff --git a/aqhome/ipc/data/msg_data_connect.c b/aqhome/ipc/data/msg_data_connect.c deleted file mode 100644 index d3beed6..0000000 --- a/aqhome/ipc/data/msg_data_connect.c +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#include -#include - -#include -#include - - - -#define AQH_MSGDATA_CONNECT_MINSIZE GWEN_MSGIPC_OFFS_PAYLOAD - - - - -GWEN_MSG *AQH_ConnectDataIpcMsg_new(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - const char *clientId, const char *userId, const char *password, uint32_t flags) -{ - GWEN_MSG *msg; - GWEN_BUFFER *buf; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - if (clientId && *clientId) - GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_CONNECT_TAGS_CLIENTID, clientId, buf); - if (userId && *userId) - GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_CONNECT_TAGS_USERID, userId, buf); - if (password && *password) - GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_CONNECT_TAGS_PASSWORD, password, buf); - GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_CONNECT_TAGS_FLAGS, flags, buf); - - msg=AQH_Tag16IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId, - GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - return msg; -} - - - -void AQH_ConnectDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy) -{ - AQH_Tag16IpcMsg_ExtendAndParse(msg, doCopy); -} - - - -void AQH_ConnectDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_CONNECT_MINSIZE) { - char *clientId; - char *userId; - uint32_t flags; - - clientId=AQH_Tag16IpcMsg_GetTagDataAsNewString(msg, AQH_MSGDATA_CONNECT_TAGS_CLIENTID, NULL); - userId=AQH_Tag16IpcMsg_GetTagDataAsNewString(msg, AQH_MSGDATA_CONNECT_TAGS_USERID, NULL); - flags=AQH_Tag16IpcMsg_GetTagDataAsUint32(msg, AQH_MSGDATA_CONNECT_TAGS_FLAGS, 0); - - GWEN_Buffer_AppendArgs(dbuf, - "CONNECT %s (code=%d, proto=%d, proto version=%d, clientId=%s, userId=%s, flags=%08x)\n", - sText?sText:"", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg), - clientId?clientId:"", - userId?userId:"", - flags); - free(userId); - free(clientId); - } -} - - - - - - - diff --git a/aqhome/ipc/data/msg_data_connect.h b/aqhome/ipc/data/msg_data_connect.h deleted file mode 100644 index 140da5f..0000000 --- a/aqhome/ipc/data/msg_data_connect.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_DATA_CONNECT_H -#define AQH_MSG_IPC_DATA_CONNECT_H - - -#include - -#include - -#include - - -/** - * This message is used in request AQH_MSGTYPE_IPC_DATA_ADDVALUES_REQ and in response AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP. - */ - -#define AQH_MSGDATA_CONNECT_TAGS_CLIENTID 0x0001 -#define AQH_MSGDATA_CONNECT_TAGS_USERID 0x0002 -#define AQH_MSGDATA_CONNECT_TAGS_PASSWORD 0x0003 -#define AQH_MSGDATA_CONNECT_TAGS_FLAGS 0x0004 - -#define AQH_MSGDATA_CONNECT_FLAGS_WANTUPDATES 0x0001 - - - -AQHOME_API GWEN_MSG *AQH_ConnectDataIpcMsg_new(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - const char *clientId, - const char *userId, const char *password, - uint32_t flags); - -AQHOME_API void AQH_ConnectDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy); - -AQHOME_API int AQH_ConnectDataIpcMsg_IsValid(const GWEN_MSG *msg); -AQHOME_API void AQH_ConnectDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - - - - - -#endif - - - diff --git a/aqhome/ipc/data/msg_data_datapoints.c b/aqhome/ipc/data/msg_data_datapoints.c deleted file mode 100644 index 05852e0..0000000 --- a/aqhome/ipc/data/msg_data_datapoints.c +++ /dev/null @@ -1,175 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include -#include - -#include -#include - -#include - - -#define AQH_MSGDATA_DATAPOINTS_OFFS_FLAGS 0 /* 4 bytes */ -#define AQH_MSGDATA_DATAPOINTS_OFFS_NUMVALUES 4 /* 4 bytes */ - -#define AQH_MSGDATA_DATAPOINTS_OFFS_VALUEID 8 /* 8 byte */ -#define AQH_MSGDATA_DATAPOINTS_OFFS_VALUENAME 16 /* 104 byte */ -# define AQH_MSGDATA_DATAPOINTS_SIZE_VALUENAME 104 -#define AQH_MSGDATA_DATAPOINTS_OFFS_VALUEUNITS 120 /* 16 byte */ -# define AQH_MSGDATA_DATAPOINTS_SIZE_VALUEUNITS 16 -#define AQH_MSGDATA_DATAPOINTS_OFFS_VALUES 136 - - - -#define AQH_MSGDATA_DATAPOINTS_PAYLOADSIZE (AQH_MSGDATA_DATAPOINTS_OFFS_VALUES) -#define AQH_MSGDATA_DATAPOINTS_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_PAYLOADSIZE) - - - - -GWEN_MSG *AQH_DataPointsDataIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint32_t flags, - uint64_t valueId, const char *valueName, const char *units, - const uint64_t *i64Ptr, int numOfDataPoints) -{ - GWEN_MSG *msg; - int i; - - msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId, 0, NULL); - GWEN_Msg_AddUint32(msg, flags); - GWEN_Msg_AddUint32(msg, numOfDataPoints); - GWEN_Msg_AddUint64(msg, valueId); - - GWEN_Msg_AddStringWithTrailingNull(msg, valueName, AQH_MSGDATA_DATAPOINTS_SIZE_VALUENAME, 0); - GWEN_Msg_AddStringWithTrailingNull(msg, units, AQH_MSGDATA_DATAPOINTS_SIZE_VALUEUNITS, 0); - - for (i=0; i=AQH_MSGDATA_DATAPOINTS_MINSIZE) - return (const char*) (GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_VALUENAME); - return NULL; -} - - - -const char *AQH_DataPointsDataIpcMsg_GetUnits(const GWEN_MSG *msg) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_DATAPOINTS_MINSIZE) - return (const char*) (GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_VALUEUNITS); - return NULL; -} - - - -const uint64_t *AQH_DataPointsDataIpcMsg_GetDataPoints(const GWEN_MSG *msg) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_DATAPOINTS_MINSIZE) - return (const uint64_t*) (GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_VALUES); - return NULL; - -} - - - -int AQH_DataPointsDataIpcMsg_IsValid(const GWEN_MSG *msg) -{ - int msgLen; - int numValues; - const uint8_t *ptr; - - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - if (msgLen=AQH_MSGDATA_DATAPOINTS_MINSIZE) { - const char *valueName; - - valueName=AQH_DataPointsDataIpcMsg_GetValueName(msg); - GWEN_Buffer_AppendArgs(dbuf, - "DATAPOINTS %s (code=%d, proto=%d, proto version=%d, flags=0x%08x, valueName=%s, values=%d)\n", - sText?sText:"", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg), - (unsigned int)AQH_DataPointsDataIpcMsg_GetFlags(msg), - valueName?valueName:"", - AQH_DataPointsDataIpcMsg_GetNumValues(msg)); - } -} - - - - - - - diff --git a/aqhome/ipc/data/msg_data_datapoints.h b/aqhome/ipc/data/msg_data_datapoints.h deleted file mode 100644 index c21676b..0000000 --- a/aqhome/ipc/data/msg_data_datapoints.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_DATA_DATAPOINTS_H -#define AQH_MSG_IPC_DATA_DATAPOINTS_H - - -#include - -#include - -#include - - -#define AQH_MSGDATA_DATAPOINTS_FLAGS_LASTMSG 0x0001 - - - -AQHOME_API GWEN_MSG *AQH_DataPointsDataIpcMsg_new(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - uint32_t flags, - uint64_t valueId, const char *valueName, const char *units, - const uint64_t *i64Ptr, int numOfDataPoints); - -AQHOME_API uint32_t AQH_DataPointsDataIpcMsg_GetFlags(const GWEN_MSG *msg); -AQHOME_API uint32_t AQH_DataPointsDataIpcMsg_GetNumValues(const GWEN_MSG *msg); -AQHOME_API uint64_t AQH_DataPointsDataIpcMsg_GetValueId(const GWEN_MSG *msg); -AQHOME_API const char *AQH_DataPointsDataIpcMsg_GetValueName(const GWEN_MSG *msg); -AQHOME_API const char *AQH_DataPointsDataIpcMsg_GetUnits(const GWEN_MSG *msg); -AQHOME_API const uint64_t *AQH_DataPointsDataIpcMsg_GetDataPoints(const GWEN_MSG *msg); - -AQHOME_API int AQH_DataPointsDataIpcMsg_IsValid(const GWEN_MSG *msg); -AQHOME_API void AQH_DataPointsDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - - - - - - - - - - - - -#endif - - - diff --git a/aqhome/ipc/data/msg_data_devices.c b/aqhome/ipc/data/msg_data_devices.c deleted file mode 100644 index 7a6f4d4..0000000 --- a/aqhome/ipc/data/msg_data_devices.c +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -#include - - -#define AQH_MSGDATA_DEVICES_MINSIZE GWEN_MSGIPC_OFFS_PAYLOAD - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - - - -/* ------------------------------------------------------------------------------------------------ - * code - * ------------------------------------------------------------------------------------------------ - */ - -GWEN_MSG *AQH_DevicesDataIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, - uint32_t flags, const AQH_DEVICE_LIST *deviceList) -{ - GWEN_MSG *msg; - GWEN_BUFFER *buf; - int rv; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_DEVICES_TAGS_FLAGS, flags, buf); - rv=AQH_DataIpc_WriteDeviceListAsTagsToBuffer(AQH_MSGDATA_DEVICES_TAGS_DEVICE, deviceList, buf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Buffer_free(buf); - return NULL; - } - - msg=AQH_Tag16IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId, - GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - return msg; -} - - - -GWEN_MSG *AQH_DevicesDataIpcMsg_newForOneDevice(uint16_t code, uint32_t msgId, uint32_t refMsgId, - uint32_t flags, const AQH_DEVICE *device) -{ - GWEN_MSG *msg; - GWEN_BUFFER *buf; - int rv; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_DEVICES_TAGS_FLAGS, flags, buf); - rv=AQH_DataIpc_WriteDeviceAsTagToBuffer(AQH_MSGDATA_DEVICES_TAGS_DEVICE, device, buf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Buffer_free(buf); - return NULL; - } - - msg=AQH_Tag16IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId, - GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - return msg; -} - - - -void AQH_DevicesDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy) -{ - AQH_Tag16IpcMsg_ExtendAndParse(msg, doCopy); -} - - - -AQH_DEVICE_LIST *AQH_DevicesDataIpcMsg_ReadDeviceList(const GWEN_MSG *msg) -{ - const GWEN_TAG16_LIST *tagList; - - tagList=AQH_Tag16IpcMsg_GetTags(msg); - if (tagList) { - AQH_DEVICE_LIST *deviceList; - - deviceList=AQH_DataIpc_ReadDevicesFromTagList(tagList, AQH_MSGDATA_DEVICES_TAGS_DEVICE); - if (deviceList==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "No device list received"); - } - return deviceList; - } - else { - DBG_INFO(AQH_LOGDOMAIN, "No tag16 list received"); - return NULL; - } -} - - - -AQH_DEVICE *AQH_DevicesDataIpcMsg_ReadFirstDevice(const GWEN_MSG *msg) -{ - return AQH_DataIpc_ReadDeviceFromTagList(AQH_Tag16IpcMsg_GetTags(msg), AQH_MSGDATA_DEVICES_TAGS_DEVICE); -} - - - - -uint32_t AQH_DevicesDataIpcMsg_GetFlags(const GWEN_MSG *msg) -{ - return AQH_Tag16IpcMsg_GetTagDataAsUint32(msg, AQH_MSGDATA_DEVICES_TAGS_FLAGS, 0); -} - - - -void AQH_DevicesDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_DEVICES_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, - "DEVICES %s (code=%d, proto=%d, proto version=%d, flags=0x%08x)\n", - sText?sText:"", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg), - (unsigned int)AQH_DevicesDataIpcMsg_GetFlags(msg)); - } -} - - - - - - diff --git a/aqhome/ipc/data/msg_data_devices.h b/aqhome/ipc/data/msg_data_devices.h deleted file mode 100644 index 7e4f680..0000000 --- a/aqhome/ipc/data/msg_data_devices.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_DATA_DEVICES_H -#define AQH_MSG_IPC_DATA_DEVICES_H - - -#include - -#include - -#include - - -/** - * This message is used in request AQH_MSGTYPE_IPC_DATA_ADDDEVICES_REQ and in response AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP. - */ - -#define AQH_MSGDATA_DEVICES_FLAGS_LASTMSG 0x0001 - -#define AQH_MSGDATA_DEVICES_TAGS_FLAGS 0x01 -#define AQH_MSGDATA_DEVICES_TAGS_DEVICE 0xc2 - - -AQHOME_API GWEN_MSG *AQH_DevicesDataIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, - uint32_t flags, const AQH_DEVICE_LIST *deviceList); -AQHOME_API GWEN_MSG *AQH_DevicesDataIpcMsg_newForOneDevice(uint16_t code, uint32_t msgId, uint32_t refMsgId, - uint32_t flags, const AQH_DEVICE *device); - -AQHOME_API void AQH_DevicesDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy); - -AQHOME_API AQH_DEVICE_LIST *AQH_DevicesDataIpcMsg_ReadDeviceList(const GWEN_MSG *msg); -AQHOME_API AQH_DEVICE *AQH_DevicesDataIpcMsg_ReadFirstDevice(const GWEN_MSG *msg); - - -AQHOME_API uint32_t AQH_DevicesDataIpcMsg_GetFlags(const GWEN_MSG *msg); - -AQHOME_API void AQH_DevicesDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - - - - - -#endif - - - diff --git a/aqhome/ipc/data/msg_data_getdata.c b/aqhome/ipc/data/msg_data_getdata.c deleted file mode 100644 index 6765297..0000000 --- a/aqhome/ipc/data/msg_data_getdata.c +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#include -#include - -#include -#include - - - -#define AQH_MSGDATA_GETDATA_MINSIZE GWEN_MSGIPC_OFFS_PAYLOAD - - - - -GWEN_MSG *AQH_GetDataDataIpcMsg_new(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - const char *valueName, uint64_t tsBegin, uint64_t tsEnd, uint64_t num) -{ - GWEN_MSG *msg; - GWEN_BUFFER *buf; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - if (valueName && *valueName) - GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_GETDATA_TAGS_NAME, valueName, buf); - GWEN_Tag16_WriteUint64TagToBuffer(AQH_MSGDATA_GETDATA_TAGS_BEGIN, tsBegin, buf); - GWEN_Tag16_WriteUint64TagToBuffer(AQH_MSGDATA_GETDATA_TAGS_END, tsEnd, buf); - GWEN_Tag16_WriteUint64TagToBuffer(AQH_MSGDATA_GETDATA_TAGS_NUM, num, buf); - - msg=AQH_Tag16IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId, - GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - return msg; -} - - - -void AQH_GetDataDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy) -{ - AQH_Tag16IpcMsg_ExtendAndParse(msg, doCopy); -} - - - -void AQH_GetDataDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_GETDATA_MINSIZE) { - char *valueName=NULL; - uint64_t tsBegin=0; - uint64_t tsEnd=0; - - valueName=AQH_Tag16IpcMsg_GetTagDataAsNewString(msg, AQH_MSGDATA_GETDATA_TAGS_NAME, NULL); - tsBegin=AQH_Tag16IpcMsg_GetTagDataAsUint64(msg, AQH_MSGDATA_GETDATA_TAGS_BEGIN, 0); - tsEnd=AQH_Tag16IpcMsg_GetTagDataAsUint64(msg, AQH_MSGDATA_GETDATA_TAGS_END, 0); - - GWEN_Buffer_AppendArgs(dbuf, - "GETDATA %s (code=%d, proto=%d, proto version=%d, name=%s, tsBegin=%lu, tsEnd=%lu)\n", - sText?sText:"", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg), - valueName?valueName:"", - (unsigned long int) tsBegin, - (unsigned long int) tsEnd); - free(valueName); - } -} - - - - - - - diff --git a/aqhome/ipc/data/msg_data_getdata.h b/aqhome/ipc/data/msg_data_getdata.h deleted file mode 100644 index e55c389..0000000 --- a/aqhome/ipc/data/msg_data_getdata.h +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_DATA_GETDATA_H -#define AQH_MSG_IPC_DATA_GETDATA_H - - -#include - -#include - -#include - - -/** - * This message is used in request AQH_MSGTYPE_IPC_DATA_ADDVALUE_REQ. - */ - -#define AQH_MSGDATA_GETDATA_TAGS_NAME 0x0001 -#define AQH_MSGDATA_GETDATA_TAGS_BEGIN 0x0020 -#define AQH_MSGDATA_GETDATA_TAGS_END 0x0021 -#define AQH_MSGDATA_GETDATA_TAGS_NUM 0x0022 - - - -AQHOME_API GWEN_MSG *AQH_GetDataDataIpcMsg_new(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - const char *valueName, uint64_t tsBegin, uint64_t tsEnd, uint64_t num); - -AQHOME_API void AQH_GetDataDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy); - -AQHOME_API void AQH_GetDataDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - - - - - -#endif - - - diff --git a/aqhome/ipc/data/msg_data_multidata.c b/aqhome/ipc/data/msg_data_multidata.c deleted file mode 100644 index bd2b8f6..0000000 --- a/aqhome/ipc/data/msg_data_multidata.c +++ /dev/null @@ -1,160 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#include -#include - -#include -#include - - - -#define AQH_MSGDATA_MULTIDATA_MINSIZE GWEN_MSGIPC_OFFS_PAYLOAD - - - - -GWEN_MSG *AQH_MultiDataDataIpcMsg_new(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - const AQH_VALUE *value, const uint64_t *i64Ptr, int numOfDataPoints) -{ - GWEN_MSG *msg; - GWEN_BUFFER *buf; - int rv; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - - rv=AQH_DataIpc_WriteValueAsTagToBuffer(AQH_MSGDATA_MULTIDATA_TAGS_VALUE, value, buf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Buffer_free(buf); - return NULL; - } - - if (i64Ptr && numOfDataPoints) - GWEN_Tag16_WriteTagToBuffer(AQH_MSGDATA_MULTIDATA_TAGS_DATA, (const uint8_t*)i64Ptr, numOfDataPoints*2*sizeof(uint64_t), buf); - - msg=AQH_Tag16IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId, - GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - return msg; -} - - - -GWEN_MSG *AQH_MultiDataDataIpcMsg_newForOne(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - const AQH_VALUE *value, uint64_t timeStamp, double dataPoint) -{ - GWEN_MSG *msg; - GWEN_BUFFER *buf; - int rv; - union {double f; uint64_t i;} u; - uint64_t arrayToSend[2]; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - - rv=AQH_DataIpc_WriteValueAsTagToBuffer(AQH_MSGDATA_MULTIDATA_TAGS_VALUE, value, buf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Buffer_free(buf); - return NULL; - } - - arrayToSend[0]=timeStamp; - u.f=dataPoint; - arrayToSend[1]=u.i; - GWEN_Tag16_WriteTagToBuffer(AQH_MSGDATA_MULTIDATA_TAGS_DATA, (const uint8_t*) arrayToSend, 2*sizeof(uint64_t), buf); - - msg=AQH_Tag16IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId, - GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - return msg; -} - - - -void AQH_MultiDataDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy) -{ - AQH_Tag16IpcMsg_ExtendAndParse(msg, doCopy); -} - - - -AQH_VALUE *AQH_MultiDataDataIpcMsg_ReadValue(const GWEN_MSG *msg) -{ - return AQH_DataIpc_ReadValueFromTagList(AQH_Tag16IpcMsg_GetTags(msg), AQH_MSGDATA_MULTIDATA_TAGS_VALUE); -} - - - -void AQH_ValuesDataIpcMsg_GetDatapoints(const GWEN_MSG *msg, const uint64_t **pDataPtr, uint64_t *pNumberOfPoints) -{ - if (msg) { - const GWEN_TAG16 *tag; - unsigned int numberOfPoints; - const uint64_t *dataPoints; - - tag=AQH_Tag16IpcMsg_FindFirstTagByType(msg, AQH_MSGDATA_MULTIDATA_TAGS_DATA); - numberOfPoints=(tag?GWEN_Tag16_GetTagLength(tag):0)/(2*sizeof(uint64_t)); - dataPoints=tag?((const uint64_t*) GWEN_Tag16_GetTagData(tag)):NULL; - if (numberOfPoints>0 && dataPoints) { - *pDataPtr=dataPoints; - *pNumberOfPoints=numberOfPoints; - } - } -} - - - -void AQH_MultiDataDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_MULTIDATA_MINSIZE) { - const GWEN_TAG16 *tag; - AQH_VALUE *value; - const char *valueName; - const char *valueUnits; - int valueType; - unsigned int numberOfPoints=0; - - value=AQH_MultiDataDataIpcMsg_ReadValue(msg); - valueName=value?AQH_Value_GetNameForSystem(value):NULL; - valueUnits=value?AQH_Value_GetValueUnits(value):NULL; - valueType=value?AQH_Value_GetValueType(value):0; - - tag=AQH_Tag16IpcMsg_FindFirstTagByType(msg, AQH_MSGDATA_MULTIDATA_TAGS_DATA); - numberOfPoints=(tag?GWEN_Tag16_GetTagLength(tag):0)/(2*sizeof(uint64_t)); - - GWEN_Buffer_AppendArgs(dbuf, - "MULTIDATA %s (code=%d, proto=%d, proto version=%d, name=%s, units=%s, type=%d, datapoints=%u)\n", - sText?sText:"", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg), - valueName?valueName:"", - valueUnits?valueUnits:"", - valueType, - numberOfPoints); - AQH_Value_free(value); - } -} - - - - - - - diff --git a/aqhome/ipc/data/msg_data_multidata.h b/aqhome/ipc/data/msg_data_multidata.h deleted file mode 100644 index d1b5a6b..0000000 --- a/aqhome/ipc/data/msg_data_multidata.h +++ /dev/null @@ -1,48 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_DATA_MULTIDATA_H -#define AQH_MSG_IPC_DATA_MULTIDATA_H - - -#include - -#include - -#include - - -#define AQH_MSGDATA_MULTIDATA_TAGS_VALUE 0xc1 -#define AQH_MSGDATA_MULTIDATA_TAGS_DATA 0xc2 - - - -AQHOME_API GWEN_MSG *AQH_MultiDataDataIpcMsg_new(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - const AQH_VALUE *value, const uint64_t *i64Ptr, int numOfDataPoints); -AQHOME_API GWEN_MSG *AQH_MultiDataDataIpcMsg_newForOne(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - const AQH_VALUE *value, uint64_t timeStamp, double dataPoint); - -AQHOME_API void AQH_MultiDataDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy); -AQHOME_API AQH_VALUE *AQH_MultiDataDataIpcMsg_ReadValue(const GWEN_MSG *msg); -AQHOME_API AQH_VALUE *AQH_ValuesDataIpcMsg_ReadFirstValue(const GWEN_MSG *msg); -AQHOME_API void AQH_ValuesDataIpcMsg_GetDatapoints(const GWEN_MSG *msg, const uint64_t **pDataPtr, uint64_t *pNumberOfPoints); - -AQHOME_API void AQH_MultiDataDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - - - - - -#endif - - - diff --git a/aqhome/ipc/data/msg_data_set.c b/aqhome/ipc/data/msg_data_set.c deleted file mode 100644 index 689f133..0000000 --- a/aqhome/ipc/data/msg_data_set.c +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2024 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -#include - - -#define AQH_MSGDATA_SET_MINSIZE GWEN_MSGIPC_OFFS_PAYLOAD - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - - - -/* ------------------------------------------------------------------------------------------------ - * code - * ------------------------------------------------------------------------------------------------ - */ - -GWEN_MSG *AQH_SetDataIpcMsg_new(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - const AQH_VALUE *value, const char *data) -{ - GWEN_MSG *msg; - GWEN_BUFFER *buf; - int rv; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - rv=AQH_DataIpc_WriteValueAsTagToBuffer(AQH_MSGDATA_SET_TAGS_VALUE, value, buf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Buffer_free(buf); - return NULL; - } - if (data && *data) - GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_SET_TAGS_DATA, data, buf); - - - msg=AQH_Tag16IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId, - GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - return msg; -} - - - -void AQH_SetDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy) -{ - AQH_Tag16IpcMsg_ExtendAndParse(msg, doCopy); -} - - - -AQH_VALUE *AQH_SetDataIpcMsg_ReadValue(const GWEN_MSG *msg) -{ - return AQH_DataIpc_ReadValueFromTagList(AQH_Tag16IpcMsg_GetTags(msg), AQH_MSGDATA_SET_TAGS_VALUE); -} - - -char *AQH_SetDataIpcMsg_ReadData(const GWEN_MSG *msg) -{ - return AQH_Tag16IpcMsg_GetTagDataAsNewString(msg, AQH_MSGDATA_SET_TAGS_DATA, NULL); -} - - - -void AQH_SetDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_SET_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, - "SET %s (code=%d, proto=%d, proto version=%d)\n", - sText?sText:"", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg)); - } -} - - - - - - diff --git a/aqhome/ipc/data/msg_data_set.h b/aqhome/ipc/data/msg_data_set.h deleted file mode 100644 index f107477..0000000 --- a/aqhome/ipc/data/msg_data_set.h +++ /dev/null @@ -1,40 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_DATA_SET_H -#define AQH_MSG_IPC_DATA_SET_H - - -#include - -#include - -#include - - -/** - */ - -#define AQH_MSGDATA_SET_TAGS_VALUE 0xc1 -#define AQH_MSGDATA_SET_TAGS_DATA 0x02 - - -AQHOME_API GWEN_MSG *AQH_SetDataIpcMsg_new(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - const AQH_VALUE *value, const char *data); -AQHOME_API void AQH_SetDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy); -AQHOME_API AQH_VALUE *AQH_SetDataIpcMsg_ReadValue(const GWEN_MSG *msg); -AQHOME_API char *AQH_SetDataIpcMsg_ReadData(const GWEN_MSG *msg); -AQHOME_API void AQH_SetDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/ipc/data/msg_data_values.c b/aqhome/ipc/data/msg_data_values.c deleted file mode 100644 index a07d14a..0000000 --- a/aqhome/ipc/data/msg_data_values.c +++ /dev/null @@ -1,155 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -#include - - -#define AQH_MSGDATA_VALUES_MINSIZE GWEN_MSGIPC_OFFS_PAYLOAD - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - - - -/* ------------------------------------------------------------------------------------------------ - * code - * ------------------------------------------------------------------------------------------------ - */ - -GWEN_MSG *AQH_ValuesDataIpcMsg_new(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - uint32_t flags, const AQH_VALUE_LIST *valueList) -{ - GWEN_MSG *msg; - GWEN_BUFFER *buf; - int rv; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_VALUES_TAGS_FLAGS, flags, buf); - rv=AQH_DataIpc_WriteValueListAsTagsToBuffer(AQH_MSGDATA_VALUES_TAGS_VALUE, valueList, buf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Buffer_free(buf); - return NULL; - } - - msg=AQH_Tag16IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId, - GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - return msg; -} - - - -GWEN_MSG *AQH_ValuesDataIpcMsg_newForOneValue(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - uint32_t flags, const AQH_VALUE *value) -{ - GWEN_MSG *msg; - GWEN_BUFFER *buf; - int rv; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_VALUES_TAGS_FLAGS, flags, buf); - rv=AQH_DataIpc_WriteValueAsTagToBuffer(AQH_MSGDATA_VALUES_TAGS_VALUE, value, buf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Buffer_free(buf); - return NULL; - } - - msg=AQH_Tag16IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId, - GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - return msg; -} - - - -void AQH_ValuesDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy) -{ - AQH_Tag16IpcMsg_ExtendAndParse(msg, doCopy); -} - - - -AQH_VALUE_LIST *AQH_ValuesDataIpcMsg_ReadValueList(const GWEN_MSG *msg) -{ - const GWEN_TAG16_LIST *tagList; - - tagList=AQH_Tag16IpcMsg_GetTags(msg); - if (tagList) { - AQH_VALUE_LIST *valueList; - - valueList=AQH_DataIpc_ReadValuesFromTagList(tagList, AQH_MSGDATA_VALUES_TAGS_VALUE); - if (valueList==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "No value list received"); - } - return valueList; - } - else { - DBG_INFO(AQH_LOGDOMAIN, "No tag16 list received"); - return NULL; - } -} - - - -AQH_VALUE *AQH_ValuesDataIpcMsg_ReadFirstValue(const GWEN_MSG *msg) -{ - return AQH_DataIpc_ReadValueFromTagList(AQH_Tag16IpcMsg_GetTags(msg), AQH_MSGDATA_VALUES_TAGS_VALUE); -} - - - - -uint32_t AQH_ValuesDataIpcMsg_GetFlags(const GWEN_MSG *msg) -{ - return AQH_Tag16IpcMsg_GetTagDataAsUint32(msg, AQH_MSGDATA_VALUES_TAGS_FLAGS, 0); -} - - - -void AQH_ValuesDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_VALUES_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, - "VALUES %s (code=%d, proto=%d, proto version=%d, flags=0x%08x)\n", - sText?sText:"", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg), - (unsigned int)AQH_ValuesDataIpcMsg_GetFlags(msg)); - } -} - - - - - - diff --git a/aqhome/ipc/data/msg_data_values.h b/aqhome/ipc/data/msg_data_values.h deleted file mode 100644 index 038f3ef..0000000 --- a/aqhome/ipc/data/msg_data_values.h +++ /dev/null @@ -1,56 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_DATA_VALUES_H -#define AQH_MSG_IPC_DATA_VALUES_H - - -#include - -#include - -#include - - -/** - * This message is used in request AQH_MSGTYPE_IPC_DATA_ADDVALUES_REQ and in response AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP. - */ - -#define AQH_MSGDATA_VALUES_FLAGS_LASTMSG 0x0001 - -#define AQH_MSGDATA_VALUES_TAGS_FLAGS 0x01 -#define AQH_MSGDATA_VALUES_TAGS_VALUE 0xc2 - - -AQHOME_API GWEN_MSG *AQH_ValuesDataIpcMsg_new(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - uint32_t flags, const AQH_VALUE_LIST *valueList); -AQHOME_API GWEN_MSG *AQH_ValuesDataIpcMsg_newForOneValue(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - uint32_t flags, const AQH_VALUE *value); - -AQHOME_API void AQH_ValuesDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy); - -AQHOME_API AQH_VALUE_LIST *AQH_ValuesDataIpcMsg_ReadValueList(const GWEN_MSG *msg); -AQHOME_API AQH_VALUE *AQH_ValuesDataIpcMsg_ReadFirstValue(const GWEN_MSG *msg); - - -AQHOME_API uint32_t AQH_ValuesDataIpcMsg_GetFlags(const GWEN_MSG *msg); - -AQHOME_API void AQH_ValuesDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - - - - - -#endif - - - diff --git a/aqhome/ipc/endpoint_ipc.c b/aqhome/ipc/endpoint_ipc.c deleted file mode 100644 index 94ecf65..0000000 --- a/aqhome/ipc/endpoint_ipc.c +++ /dev/null @@ -1,277 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include "aqhome/ipc/endpoint_ipc_p.h" - -#include "aqhome/ipc/msg_ipc_result.h" - -#include -#include -#include - - - - -#define AQH_MSG_ENDPOINT_IPC_NAME "ipc" - - -GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC) - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static void GWENHYWFAR_CB _freeData(void *bp, void *p); - - - -/* ------------------------------------------------------------------------------------------------ - * implementations - * ------------------------------------------------------------------------------------------------ - */ - -void AQH_IpcEndpoint_Extend(GWEN_MSG_ENDPOINT *ep) -{ - AQH_ENDPOINT_IPC *xep; - - GWEN_NEW_OBJECT(AQH_ENDPOINT_IPC, xep); - GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep, xep, _freeData); -} - - - -void _freeData(GWEN_UNUSED void *bp, void *p) -{ - AQH_ENDPOINT_IPC *xep; - - xep=(AQH_ENDPOINT_IPC*) p; - - free(xep->serviceName); - free(xep->userName); - free(xep->password); - - GWEN_FREE_OBJECT(xep); -} - - - -uint32_t AQH_IpcEndpoint_GetAcceptedMsgGroups(const GWEN_MSG_ENDPOINT *ep) -{ - if (ep) { - AQH_ENDPOINT_IPC *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep); - if (xep) { - return xep->acceptedMsgGroups; - } - } - - return 0; -} - - - -void AQH_IpcEndpoint_SetAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t i) -{ - if (ep) { - AQH_ENDPOINT_IPC *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep); - if (xep) - xep->acceptedMsgGroups=i; - } -} - - - -void AQH_IpcEndpoint_AddAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t i) -{ - if (ep) { - AQH_ENDPOINT_IPC *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep); - if (xep) - xep->acceptedMsgGroups|=i; - } -} - - - -void AQH_IpcEndpoint_SubAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t i) -{ - if (ep) { - AQH_ENDPOINT_IPC *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep); - if (xep) - xep->acceptedMsgGroups&=~i; - } -} - - - -const char *AQH_IpcEndpoint_GetServiceName(const GWEN_MSG_ENDPOINT *ep) -{ - if (ep) { - AQH_ENDPOINT_IPC *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep); - if (xep) - return xep->serviceName; - } - return NULL; -} - - - -void AQH_IpcEndpoint_SetServiceName(GWEN_MSG_ENDPOINT *ep, const char *s) -{ - if (ep) { - AQH_ENDPOINT_IPC *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep); - if (xep) { - free(xep->serviceName); - xep->serviceName=s?strdup(s):NULL; - } - } -} - - - -const char *AQH_IpcEndpoint_GetUserName(const GWEN_MSG_ENDPOINT *ep) -{ - if (ep) { - AQH_ENDPOINT_IPC *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep); - if (xep) - return xep->userName; - } - return NULL; -} - - - -void AQH_IpcEndpoint_SetUserName(GWEN_MSG_ENDPOINT *ep, const char *s) -{ - if (ep) { - AQH_ENDPOINT_IPC *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep); - if (xep) { - free(xep->userName); - xep->userName=s?strdup(s):NULL; - } - } -} - - - -const char *AQH_IpcEndpoint_GetPassword(const GWEN_MSG_ENDPOINT *ep) -{ - if (ep) { - AQH_ENDPOINT_IPC *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep); - if (xep) - return xep->password; - } - return NULL; -} - - - -void AQH_IpcEndpoint_SetPassword(GWEN_MSG_ENDPOINT *ep, const char *s) -{ - if (ep) { - AQH_ENDPOINT_IPC *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep); - if (xep) { - free(xep->password); - xep->password=s?strdup(s):NULL; - } - } -} - - - -uint32_t AQH_IpcEndpoint_GetPermissions(const GWEN_MSG_ENDPOINT *ep) -{ - if (ep) { - AQH_ENDPOINT_IPC *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep); - if (xep) - return xep->permissions; - } - return 0; -} - - - -void AQH_IpcEndpoint_SetPermissions(GWEN_MSG_ENDPOINT *ep, uint32_t i) -{ - if (ep) { - AQH_ENDPOINT_IPC *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_IPC, ep); - if (xep) - xep->permissions=i; - } -} - - - - - - -GWEN_MSG_ENDPOINT *AQH_IpcEndpoint_CreateIpcTcpClient(const char *host, int port, const char *name, int groupId) -{ - GWEN_MSG_ENDPOINT *ep; - - ep=GWEN_IpcEndpoint_CreateIpcTcpClient(host, port, name?name:AQH_MSG_ENDPOINT_IPC_NAME, groupId); - AQH_IpcEndpoint_Extend(ep); - return ep; -} - - - -GWEN_MSG_ENDPOINT *AQH_IpcEndpoint_CreateIpcTcpServiceForSocket(GWEN_SOCKET *sk, const char *name, int groupId) -{ - GWEN_MSG_ENDPOINT *ep; - - ep=GWEN_IpcEndpoint_CreateIpcTcpServiceForSocket(sk, name?name:AQH_MSG_ENDPOINT_IPC_NAME, groupId); - AQH_IpcEndpoint_Extend(ep); - return ep; -} - - - -void AQH_IpcEndpoint_SendResponseResult(GWEN_MSG_ENDPOINT *ep, uint32_t refMsgId, uint16_t code, uint32_t resultCode) -{ - if (ep) { - GWEN_MSG *msgOut; - uint32_t msgId; - - msgId=GWEN_MsgEndpoint_GetNextMessageId(ep); - msgOut=AQH_ResultIpcMsg_new(code, msgId, refMsgId, resultCode); - GWEN_MsgEndpoint_AddSendMessage(ep, msgOut); - } -} - - diff --git a/aqhome/ipc/endpoint_ipc.h b/aqhome/ipc/endpoint_ipc.h deleted file mode 100644 index 444a3ba..0000000 --- a/aqhome/ipc/endpoint_ipc.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_ENDPOINT_IPC_H -#define AQH_ENDPOINT_IPC_H - - -#include - -#include - - -#define AQH_IPCENDPOINT_FLAGS_WANTUPDATES 0x0001 - -#define AQH_IPCENDPOINT_PERMS_LISTVALUES 0x0001 -#define AQH_IPCENDPOINT_PERMS_READVALUE 0x0002 -#define AQH_IPCENDPOINT_PERMS_ADDVALUE 0x0004 - -#define AQH_IPCENDPOINT_PERMS_LISTDATA 0x0010 -#define AQH_IPCENDPOINT_PERMS_READDATA 0x0020 -#define AQH_IPCENDPOINT_PERMS_ADDDATA 0x0040 -#define AQH_IPCENDPOINT_PERMS_SETDATA 0x0080 - -#define AQH_IPCENDPOINT_PERMS_LISTDEVICES 0x0100 -#define AQH_IPCENDPOINT_PERMS_READDEVICE 0x0200 -#define AQH_IPCENDPOINT_PERMS_ADDDEVICE 0x0400 -#define AQH_IPCENDPOINT_PERMS_MODDEVICE 0x0800 - - - -AQHOME_API void AQH_IpcEndpoint_Extend(GWEN_MSG_ENDPOINT *ep); - -AQHOME_API GWEN_MSG_ENDPOINT *AQH_IpcEndpoint_CreateIpcTcpClient(const char *host, int port, const char *name, int groupId); -AQHOME_API GWEN_MSG_ENDPOINT *AQH_IpcEndpoint_CreateIpcTcpServiceForSocket(GWEN_SOCKET *sk, const char *name, int groupId); - -AQHOME_API uint32_t AQH_IpcEndpoint_GetAcceptedMsgGroups(const GWEN_MSG_ENDPOINT *ep); -AQHOME_API void AQH_IpcEndpoint_SetAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t i); -AQHOME_API void AQH_IpcEndpoint_AddAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t i); -AQHOME_API void AQH_IpcEndpoint_SubAcceptedMsgGroups(GWEN_MSG_ENDPOINT *ep, uint32_t i); - -AQHOME_API const char *AQH_IpcEndpoint_GetServiceName(const GWEN_MSG_ENDPOINT *ep); -AQHOME_API void AQH_IpcEndpoint_SetServiceName(GWEN_MSG_ENDPOINT *ep, const char *s); - -AQHOME_API const char *AQH_IpcEndpoint_GetUserName(const GWEN_MSG_ENDPOINT *ep); -AQHOME_API void AQH_IpcEndpoint_SetUserName(GWEN_MSG_ENDPOINT *ep, const char *s); - -AQHOME_API const char *AQH_IpcEndpoint_GetPassword(const GWEN_MSG_ENDPOINT *ep); -AQHOME_API void AQH_IpcEndpoint_SetPassword(GWEN_MSG_ENDPOINT *ep, const char *s); - -AQHOME_API uint32_t AQH_IpcEndpoint_GetPermissions(const GWEN_MSG_ENDPOINT *ep); -AQHOME_API void AQH_IpcEndpoint_SetPermissions(GWEN_MSG_ENDPOINT *ep, uint32_t i); - -AQHOME_API void AQH_IpcEndpoint_SendResponseResult(GWEN_MSG_ENDPOINT *ep, uint32_t refMsgId, uint16_t code, uint32_t resultCode); - - -#endif - diff --git a/aqhome/ipc/endpoint_ipc_p.h b/aqhome/ipc/endpoint_ipc_p.h deleted file mode 100644 index 0b61bb8..0000000 --- a/aqhome/ipc/endpoint_ipc_p.h +++ /dev/null @@ -1,42 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_ENDPOINT_IPC_P_H -#define AQH_ENDPOINT_IPC_P_H - - -#include - -#include - -#include "aqhome/ipc/endpoint_ipc.h" - - -typedef struct AQH_ENDPOINT_IPC AQH_ENDPOINT_IPC; -struct AQH_ENDPOINT_IPC { - uint32_t acceptedMsgGroups; - char *serviceName; - char *userName; - char *password; - uint32_t permissions; -}; - - - - - -#endif - - - - - - - - - diff --git a/aqhome/ipc/endpoint_ipcclient.c b/aqhome/ipc/endpoint_ipcclient.c deleted file mode 100644 index af58472..0000000 --- a/aqhome/ipc/endpoint_ipcclient.c +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/ipc/endpoint_ipcclient.h" -#include "aqhome/ipc/data/ipc_data.h" -#include "aqhome/ipc/endpoint_ipc.h" -#include "aqhome/ipc/data/msg_data_connect.h" -#include "aqhome/ipc/msg_ipc_result.h" - -#include -#include -#include -#include - - -#define AQH_MSG_ENDPOINT_IPCCLIENT_NAME "ipc-client" - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static int _startConnect(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild); -static void _checkSockets(GWEN_MSG_ENDPOINT *ep, - GWEN_MSG_ENDPOINT *epChild, - GWEN_SOCKETSET *readSet, - GWEN_SOCKETSET *writeSet, - GWEN_SOCKETSET *xSet); - - - -/* ------------------------------------------------------------------------------------------------ - * implementations - * ------------------------------------------------------------------------------------------------ - */ - -GWEN_MSG_ENDPOINT *AQH_ClientIpcEndpoint_new(const char *name, int groupId) -{ - GWEN_MSG_ENDPOINT *ep; - - ep=GWEN_MultilayerEndpoint_new(name?name:AQH_MSG_ENDPOINT_IPCCLIENT_NAME, groupId); - GWEN_MultilayerEndpoint_SetStartConnectFn(ep, _startConnect); - GWEN_MultilayerEndpoint_SetCheckSocketsFn(ep, _checkSockets); - - return ep; -} - - - -int _startConnect(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild) -{ - if (epChild) { - int rv; - GWEN_MSG *msg; - uint32_t flagsForConnectMsg; - - flagsForConnectMsg=(GWEN_MsgEndpoint_GetFlags(ep) & AQH_ENDPOINT_IPCCLIENT_FLAGS_WANTUPDATES)?AQH_IPCENDPOINT_FLAGS_WANTUPDATES:0; - - rv=GWEN_TcpcEndpoint_StartConnect(epChild); - if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) { - DBG_INFO(AQH_LOGDOMAIN, "Error starting to connect child layer (%d)", rv); - return rv; - } - msg=AQH_ConnectDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_CONNECT_REQ, - GWEN_MsgEndpoint_GetNextMessageId(epChild), 0, - AQH_IpcEndpoint_GetServiceName(epChild), - AQH_IpcEndpoint_GetUserName(epChild), - AQH_IpcEndpoint_GetPassword(epChild), - flagsForConnectMsg); - GWEN_MsgEndpoint_AddSendMessage(epChild, msg); - GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTING); - return rv; /* result from GWEN_TcpcEndpoint_StartConnect() above */ - } - return GWEN_ERROR_GENERIC; -} - - - -void _checkSockets(GWEN_MSG_ENDPOINT *ep, - GWEN_MSG_ENDPOINT *epChild, - GWEN_SOCKETSET *readSet, - GWEN_SOCKETSET *writeSet, - GWEN_SOCKETSET *xSet) -{ - GWEN_MSG *msg; - - GWEN_MsgEndpoint_CheckSockets(epChild, readSet, writeSet, xSet); /* let base layer work */ - - msg=GWEN_MsgEndpoint_GetFirstReceivedMessage(epChild); - while(msg) { - GWEN_MSG *msgNext; - uint16_t code; - - msgNext=GWEN_Msg_List_Next(msg); - code=GWEN_IpcMsg_GetCode(msg); - if (code==AQH_MSGTYPE_IPC_DATA_RESULT) { - uint32_t resultCode; - - GWEN_Msg_List_Del(msg); /* remove from list */ - resultCode=AQH_ResultIpcMsg_GetResultCode(msg); - if (resultCode==AQH_MSG_IPC_SUCCESS) { - DBG_INFO(AQH_LOGDOMAIN, "Positive CONNECT response, connected"); - GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTED); - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "Negative CONNECT response (%d)", code); - GWEN_MsgEndpoint_Disconnect(epChild); - GWEN_MsgEndpoint_Disconnect(ep); - } - GWEN_Msg_free(msg); - break; - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "Ignoring response (%u)", code); - GWEN_Msg_free(msg); - } - msg=msgNext; - } /* while */ -} - - - - - - diff --git a/aqhome/ipc/endpoint_ipcclient.h b/aqhome/ipc/endpoint_ipcclient.h deleted file mode 100644 index 0ed01f0..0000000 --- a/aqhome/ipc/endpoint_ipcclient.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_ENDPOINT_IPCCLIENT_H -#define AQH_ENDPOINT_IPCCLIENT_H - - -#include - -#include - - -#define AQH_ENDPOINT_IPCCLIENT_FLAGS_WANTUPDATES 0x0001 - - -/** - * This class expects to later have a child endpoint derived in any form from GWEN_TcpcEndpoint and from - * AQH_IpcEndpoint. It allows for automatic connect/reconnect including automatic exchange of AQH_ConnectDataIpcMsg - * messages thereby combining physical and logical connection to a server in one class. - * - * Use this class like this: - * - * GWEN_MSG_ENDPOINT *clientEndpoint; - * GWEN_MSG_ENDPOINT *ipcBaseEndpoint; - * - * clientEndpoint=AQH_ClientIpcEndpoint_new("testClient", 0); - * ipcBaseEndpoint=AQH_IpcEndpoint_CreateIpcTcpClient("127.0.0.1", 1234, "ipcBaseClient", 0); - * AQH_IpcEndpoint_SetServiceName(ipcBaseEndpoint, "testclient"); - * AQH_IpcEndpoint_SetUserName(ipcBaseEndpoint, "testUser"); - * ... - * GWEN_MsgEndpoint_Tree2_AddChild(clientEndpoint, ipcBaseEndpoint); - * - * - */ - -AQHOME_API GWEN_MSG_ENDPOINT *AQH_ClientIpcEndpoint_new(const char *name, int groupId); - - - -#endif - diff --git a/aqhome/ipc/msg_ipc_qwords.c b/aqhome/ipc/msg_ipc_qwords.c deleted file mode 100644 index e6367d1..0000000 --- a/aqhome/ipc/msg_ipc_qwords.c +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include -#include - -#include -#include -#include - - -#define AQH_MSGDATA_QWORDS_OFFS_FLAGS 0 /* 4 bytes */ -#define AQH_MSGDATA_QWORDS_OFFS_NUMVALUES 4 /* 4 bytes */ - -#define AQH_MSGDATA_QWORDS_OFFS_VALUES 8 /* 8 byte */ - - -#define AQH_MSGDATA_QWORDS_PAYLOADSIZE (AQH_MSGDATA_QWORDS_OFFS_VALUES) -#define AQH_MSGDATA_QWORDS_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_QWORDS_PAYLOADSIZE) - - - - -GWEN_MSG *AQH_QwordsIpcMsg_new(uint8_t protoId, uint8_t protoVer, uint16_t code, - uint32_t msgId, uint32_t refMsgId, - uint32_t flags, const uint64_t *i64Ptr, int count) -{ - GWEN_MSG *msg; - int payloadSize; - int i; - - payloadSize=AQH_MSGDATA_QWORDS_PAYLOADSIZE+(count*8); - - msg=GWEN_IpcMsg_new(protoId, protoVer, code, msgId, refMsgId, payloadSize, NULL); - GWEN_Msg_AddUint32(msg, flags); - GWEN_Msg_AddUint32(msg, count); - - for(i=0; i=AQH_MSGDATA_QWORDS_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, - "QWORDS (code=%d, proto=%d, proto version=%d, flags=0x%08x, values=%d)\n", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg), - (unsigned int)AQH_QwordsIpcMsg_GetFlags(msg), - AQH_QwordsIpcMsg_GetNumValues(msg)); - } -} - - - - - - - diff --git a/aqhome/ipc/msg_ipc_qwords.h b/aqhome/ipc/msg_ipc_qwords.h deleted file mode 100644 index db9dbe9..0000000 --- a/aqhome/ipc/msg_ipc_qwords.h +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_QWORDS_H -#define AQH_MSG_IPC_QWORDS_H - - -#include -#include -#include - -#include -#include - - -AQHOME_API GWEN_MSG *AQH_QwordsIpcMsg_new(uint8_t protoId, uint8_t protoVer, uint16_t code, - uint32_t msgId, uint32_t refMsgId, - uint32_t flags, const uint64_t *i64Ptr, int count); - -AQHOME_API uint32_t AQH_QwordsIpcMsg_GetFlags(const GWEN_MSG *msg); -AQHOME_API uint32_t AQH_QwordsIpcMsg_GetNumValues(const GWEN_MSG *msg); -AQHOME_API uint64_t AQH_QwordsIpcMsg_GetValue(const GWEN_MSG *msg, int idx); -AQHOME_API int AQH_QwordsIpcMsg_IsValid(const GWEN_MSG *msg); -AQHOME_API void AQH_QwordsIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - -#endif - - - diff --git a/aqhome/ipc/msg_ipc_result.c b/aqhome/ipc/msg_ipc_result.c deleted file mode 100644 index 87299d9..0000000 --- a/aqhome/ipc/msg_ipc_result.c +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - - - -#define AQH_MSGIPC_RESULT_OFFS_RESULTCODE 0 /* 4 bytes */ - -#define AQH_MSGIPC_RESULT_PAYLOADSIZE (AQH_MSGIPC_RESULT_OFFS_RESULTCODE+4) -#define AQH_MSGIPC_RESULT_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_PAYLOADSIZE) - - - - -GWEN_MSG *AQH_ResultIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint32_t resultCode) -{ - GWEN_MSG *msg; - - msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, - msgId, refMsgId, - AQH_MSGIPC_RESULT_PAYLOADSIZE, NULL); - GWEN_Msg_AddUint32(msg, resultCode); - return msg; -} - - - -uint32_t AQH_ResultIpcMsg_GetResultCode(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE, 0); -} - - - - - -void AQH_ResultIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_RESULT_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, - "ERROR %s (code=%d, proto=%d, proto version=%d, error=%d, msgId=%d, refMsgId=%d)\n", - sText?sText:"", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg), - AQH_ResultIpcMsg_GetResultCode(msg), - GWEN_IpcMsg_GetMsgId(msg), - GWEN_IpcMsg_GetRefMsgId(msg)); - } -} - - - - - - - diff --git a/aqhome/ipc/msg_ipc_result.h b/aqhome/ipc/msg_ipc_result.h deleted file mode 100644 index 9fa685c..0000000 --- a/aqhome/ipc/msg_ipc_result.h +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_RESULT_H -#define AQH_MSG_IPC_RESULT_H - - -#include -#include -#include - -#include -#include - - -#define AQH_IPC_PROTOCOL_RESULT_ID 0 -#define AQH_IPC_PROTOCOL_RESULT_VERSION 1 - - -#define AQH_MSG_IPC_SUCCESS 0 -#define AQH_MSG_IPC_ERROR_GENERIC 1 -#define AQH_MSG_IPC_ERROR_INVALID 2 -#define AQH_MSG_IPC_ERROR_EXISTS 3 -#define AQH_MSG_IPC_ERROR_NODATA 4 -#define AQH_MSG_IPC_ERROR_BADDATA 5 -#define AQH_MSG_IPC_ERROR_PERMS 6 -#define AQH_MSG_IPC_ERROR_NOTFOUND 7 -#define AQH_MSG_IPC_ERROR_IO 8 -#define AQH_MSG_IPC_ERROR_TRYAGAIN 9 - - -AQHOME_API GWEN_MSG *AQH_ResultIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint32_t resultCode); -AQHOME_API uint32_t AQH_ResultIpcMsg_GetResultCode(const GWEN_MSG *msg); -AQHOME_API void AQH_ResultIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - -#endif - - - diff --git a/aqhome/ipc/msg_ipc_tag16.c b/aqhome/ipc/msg_ipc_tag16.c deleted file mode 100644 index 1ffd3b9..0000000 --- a/aqhome/ipc/msg_ipc_tag16.c +++ /dev/null @@ -1,255 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include "msg_ipc_tag16_p.h" - -#include -#include - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static void GWENHYWFAR_CB _freeData(void *bp, void *p); -static GWEN_TAG16_LIST *_parseTags(const GWEN_MSG *msg, int doCopy); - - - -/* ------------------------------------------------------------------------------------------------ - * implementations - * ------------------------------------------------------------------------------------------------ - */ - -GWEN_INHERIT(GWEN_MSG, AQH_MSG_IPC_TAG16); - - - -GWEN_MSG *AQH_Tag16IpcMsg_new(uint8_t protoId, uint8_t protoVer, uint16_t code, - uint32_t msgId, uint32_t refMsgId, - uint32_t payloadLen, const uint8_t *payload) -{ - GWEN_MSG *msg; - - msg=GWEN_IpcMsg_new(protoId, protoVer, code, msgId, refMsgId, payloadLen, payload); - AQH_Tag16IpcMsg_Extend(msg); - return msg; -} - - - -void AQH_Tag16IpcMsg_Extend(GWEN_MSG *msg) -{ - AQH_MSG_IPC_TAG16 *xmsg; - - GWEN_NEW_OBJECT(AQH_MSG_IPC_TAG16, xmsg); - GWEN_INHERIT_SETDATA(GWEN_MSG, AQH_MSG_IPC_TAG16, msg, xmsg, _freeData); -} - - - - -void _freeData(GWEN_UNUSED void *bp, void *p) -{ - AQH_MSG_IPC_TAG16 *xmsg; - - xmsg=(AQH_MSG_IPC_TAG16*) p; - GWEN_Tag16_List_free(xmsg->tagList); - GWEN_FREE_OBJECT(xmsg); -} - - - -GWEN_TAG16_LIST *AQH_Tag16IpcMsg_GetTags(const GWEN_MSG *msg) -{ - if (msg) { - AQH_MSG_IPC_TAG16 *xmsg; - - xmsg=GWEN_INHERIT_GETDATA(GWEN_MSG, AQH_MSG_IPC_TAG16, msg); - if (xmsg) { - return xmsg->tagList; - } - else { - DBG_INFO(AQH_LOGDOMAIN, "Not a Tag16IpcMsg message"); - return NULL; - } - } - else { - DBG_INFO(AQH_LOGDOMAIN, "NULLPOINTER"); - return NULL; - } -} - - - -void AQH_Tag16IpcMsg_ReadTags(GWEN_MSG *msg, int doCopy) -{ - if (msg) { - AQH_MSG_IPC_TAG16 *xmsg; - - xmsg=GWEN_INHERIT_GETDATA(GWEN_MSG, AQH_MSG_IPC_TAG16, msg); - if (xmsg) { - if (xmsg->tagList) { - DBG_INFO(AQH_LOGDOMAIN, "Tags already parsed"); - } - else { - xmsg->tagList=_parseTags(msg, doCopy); - if (xmsg->tagList==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "No tags received"); - } - } - } - else { - DBG_INFO(AQH_LOGDOMAIN, "Not a Tag16IpcMsg message"); - } - } - else { - DBG_INFO(AQH_LOGDOMAIN, "NULLPOINTER"); - } -} - - - -void AQH_Tag16IpcMsg_ExtendAndParse(GWEN_MSG *msg, int doCopy) -{ - if (!(GWEN_INHERIT_ISOFTYPE(GWEN_MSG, AQH_MSG_IPC_TAG16, msg))) - AQH_Tag16IpcMsg_Extend(msg); - AQH_Tag16IpcMsg_ReadTags(msg, doCopy); -} - - - -char *AQH_Tag16IpcMsg_GetTagDataAsNewString(const GWEN_MSG *msg, unsigned int tagType, const char *defaultValue) -{ - if (msg) { - AQH_MSG_IPC_TAG16 *xmsg; - - xmsg=GWEN_INHERIT_GETDATA(GWEN_MSG, AQH_MSG_IPC_TAG16, msg); - if (xmsg && xmsg->tagList) { - const GWEN_TAG16 *tag; - - tag=GWEN_Tag16_List_FindFirstByTagType(xmsg->tagList, tagType); - if (tag) - return GWEN_Tag16_GetTagDataAsNewString(tag, defaultValue); - } - } - return defaultValue?strdup(defaultValue):NULL; -} - - - -uint32_t AQH_Tag16IpcMsg_GetTagDataAsUint32(const GWEN_MSG *msg, unsigned int tagType, uint32_t defaultValue) -{ - if (msg) { - AQH_MSG_IPC_TAG16 *xmsg; - - xmsg=GWEN_INHERIT_GETDATA(GWEN_MSG, AQH_MSG_IPC_TAG16, msg); - if (xmsg && xmsg->tagList) { - const GWEN_TAG16 *tag; - - tag=GWEN_Tag16_List_FindFirstByTagType(xmsg->tagList, tagType); - return tag?GWEN_Tag16_GetTagDataAsUint32(tag, defaultValue):defaultValue; - } - } - return defaultValue; -} - - - -uint64_t AQH_Tag16IpcMsg_GetTagDataAsUint64(const GWEN_MSG *msg, unsigned int tagType, uint64_t defaultValue) -{ - if (msg) { - AQH_MSG_IPC_TAG16 *xmsg; - - xmsg=GWEN_INHERIT_GETDATA(GWEN_MSG, AQH_MSG_IPC_TAG16, msg); - if (xmsg && xmsg->tagList) { - const GWEN_TAG16 *tag; - - tag=GWEN_Tag16_List_FindFirstByTagType(xmsg->tagList, tagType); - return tag?GWEN_Tag16_GetTagDataAsUint64(tag, defaultValue):defaultValue; - } - } - return defaultValue; -} - - - -const GWEN_TAG16 *AQH_Tag16IpcMsg_FindFirstTagByType(const GWEN_MSG *msg, unsigned int tagType) -{ - if (msg) { - AQH_MSG_IPC_TAG16 *xmsg; - - xmsg=GWEN_INHERIT_GETDATA(GWEN_MSG, AQH_MSG_IPC_TAG16, msg); - if (xmsg && xmsg->tagList) - return GWEN_Tag16_List_FindFirstByTagType(xmsg->tagList, tagType); - } - return NULL; -} - - - -GWEN_TAG16_LIST *AQH_Tag16IpcMsg_ParseTags(const GWEN_MSG *msg, int doCopy) -{ - return _parseTags(msg, doCopy); -} - - - -GWEN_TAG16_LIST *_parseTags(const GWEN_MSG *msg, int doCopy) -{ - uint32_t msgSize; - - msgSize=GWEN_Msg_GetBytesInBuffer(msg); - if (msgSize>GWEN_MSGIPC_OFFS_PAYLOAD) { - const uint8_t *ptr; - uint32_t payloadSize; - - ptr=GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD; - payloadSize=msgSize-GWEN_MSGIPC_OFFS_PAYLOAD; - - if (payloadSize) { - GWEN_TAG16_LIST *tagList; - - tagList=GWEN_Tag16_List_fromBuffer(ptr, payloadSize, doCopy); - if (tagList==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "Error reading tags from message"); - return NULL; - } - return tagList; - } - } - - return NULL; -} - - - -void AQH_Tag16IpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=GWEN_MSGIPC_OFFS_PAYLOAD) { - GWEN_Buffer_AppendArgs(dbuf, - "Tag16 %s (code=%d, proto=%d, proto version=%d)\n", - sText?sText:"", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg)); - } -} - - - - - - - diff --git a/aqhome/ipc/msg_ipc_tag16.h b/aqhome/ipc/msg_ipc_tag16.h deleted file mode 100644 index 43c5b1b..0000000 --- a/aqhome/ipc/msg_ipc_tag16.h +++ /dev/null @@ -1,45 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_TAG16_H -#define AQH_MSG_IPC_TAG16_H - - -#include - -#include -#include -#include - - -AQHOME_API GWEN_MSG *AQH_Tag16IpcMsg_new(uint8_t protoId, uint8_t protoVer, uint16_t code, - uint32_t msgId, uint32_t refMsgId, - uint32_t payloadLen, const uint8_t *payload); -AQHOME_API void AQH_Tag16IpcMsg_ExtendAndParse(GWEN_MSG *msg, int doCopy); - -AQHOME_API void AQH_Tag16IpcMsg_Extend(GWEN_MSG *msg); -AQHOME_API void AQH_Tag16IpcMsg_ReadTags(GWEN_MSG *msg, int doCopy); - -AQHOME_API GWEN_TAG16_LIST *AQH_Tag16IpcMsg_GetTags(const GWEN_MSG *msg); - -AQHOME_API GWEN_DEPRECATED GWEN_TAG16_LIST *AQH_Tag16IpcMsg_ParseTags(const GWEN_MSG *msg, int doCopy); -AQHOME_API void AQH_Tag16IpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - -AQHOME_API const GWEN_TAG16 *AQH_Tag16IpcMsg_FindFirstTagByType(const GWEN_MSG *msg, unsigned int tagType); - -AQHOME_API char *AQH_Tag16IpcMsg_GetTagDataAsNewString(const GWEN_MSG *msg, unsigned int tagType, const char *defaultValue); -AQHOME_API uint32_t AQH_Tag16IpcMsg_GetTagDataAsUint32(const GWEN_MSG *msg, unsigned int tagType, uint32_t defaultValue); -AQHOME_API uint64_t AQH_Tag16IpcMsg_GetTagDataAsUint64(const GWEN_MSG *msg, unsigned int tagType, uint64_t defaultValue); - - - - -#endif - - - diff --git a/aqhome/ipc/msg_ipc_tag16_p.h b/aqhome/ipc/msg_ipc_tag16_p.h deleted file mode 100644 index 00da2be..0000000 --- a/aqhome/ipc/msg_ipc_tag16_p.h +++ /dev/null @@ -1,25 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_TAG16_P_H -#define AQH_MSG_IPC_TAG16_P_H - - -#include - - -typedef struct AQH_MSG_IPC_TAG16 AQH_MSG_IPC_TAG16; -struct AQH_MSG_IPC_TAG16 { - GWEN_TAG16_LIST *tagList; -}; - - -#endif - - - diff --git a/aqhome/ipc/nodes/0BUILD b/aqhome/ipc/nodes/0BUILD deleted file mode 100644 index 8d004bd..0000000 --- a/aqhome/ipc/nodes/0BUILD +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - $(gwenhywfar_cflags) - -I$(topsrcdir) - -I$(topbuilddir) - - - - --include=$(builddir) - --include=$(srcdir) - - - - - - $(visibility_cflags) - - - - --api=AQHOME_API - - - - - - - - - - - - - - - - - - $(local/built_headers_pub) - - - - - ipc_nodes.h - msg_ipc_forward.h - msg_ipc_getdevices_req.h - msg_ipc_getdevices_rsp.h - msg_ipc_ping.h - msg_ipc_setaccmsggrps.h - msg_ipc_value.h - - - - - - - - - $(local/typefiles) - - ipc_nodes.c - msg_ipc_forward.c - msg_ipc_getdevices_req.c - msg_ipc_getdevices_rsp.c - msg_ipc_ping.c - msg_ipc_setaccmsggrps.c - msg_ipc_value.c - - - - - - - - - - - - - - - - - - - diff --git a/aqhome/ipc/nodes/ipc_nodes.c b/aqhome/ipc/nodes/ipc_nodes.c deleted file mode 100644 index dffab65..0000000 --- a/aqhome/ipc/nodes/ipc_nodes.c +++ /dev/null @@ -1,16 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include - - diff --git a/aqhome/ipc/nodes/ipc_nodes.h b/aqhome/ipc/nodes/ipc_nodes.h deleted file mode 100644 index 88d60e9..0000000 --- a/aqhome/ipc/nodes/ipc_nodes.h +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_NODES_H -#define AQH_MSG_IPC_NODES_H - - -#include - -#include -#include - - -#define AQH_IPC_PROTOCOL_NODES_ID 1 -#define AQH_IPC_PROTOCOL_NODES_VERSION 1 - - -#define AQH_MSGTYPE_IPC_NODES_RESULT 0xf001 - -#define AQH_MSGTYPE_IPC_NODES_FORWARD 0xf100 -#define AQH_MSGTYPE_IPC_NODES_VALUE 0xf200 -#define AQH_MSGTYPE_IPC_NODES_PING 0xf300 -#define AQH_MSGTYPE_IPC_NODES_SETACCMSGGRPS 0xf400 -#define AQH_MSGTYPE_IPC_NODES_GETDEVICES_REQ 0xf500 -#define AQH_MSGTYPE_IPC_NODES_GETDEVICES_RSP 0xf600 - - - - -#endif - - - diff --git a/aqhome/ipc/nodes/msg_ipc_forward.c b/aqhome/ipc/nodes/msg_ipc_forward.c deleted file mode 100644 index 0cbfd54..0000000 --- a/aqhome/ipc/nodes/msg_ipc_forward.c +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - - - -#define AQH_MSG_OFFS_FORWARD_MSG (GWEN_MSGIPC_OFFS_PAYLOAD+0) - -#define AQH_MSG_FORWARD_MINSIZE (AQH_MSG_OFFS_FORWARD_MSG+AQH_MSG_OFFS_ALL_DATA_BEGIN) - - - -GWEN_MSG *AQH_ForwardIpcMsg_new(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - const uint8_t *ptr, uint32_t len) -{ - return GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, msgId, refMsgId, len, ptr); -} - - - -const uint8_t *AQH_ForwardIpcMsg_GetMsgPtr(const GWEN_MSG *msg) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FORWARD_MINSIZE) - return GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_FORWARD_MSG; - return NULL; -} - - - -uint32_t AQH_ForwardIpcMsg_GetMsgLen(const GWEN_MSG *msg) -{ - uint32_t len; - - len=GWEN_Msg_GetBytesInBuffer(msg); - if (len>AQH_MSG_FORWARD_MINSIZE) { - return len-AQH_MSG_OFFS_FORWARD_MSG; - } - return 0; -} - - -GWEN_MSG *AQH_ForwardIpcMsg_GetCopyOfNodeMsg(const GWEN_MSG *msg) -{ - return GWEN_Msg_fromBytes(AQH_ForwardIpcMsg_GetMsgPtr(msg), AQH_ForwardIpcMsg_GetMsgLen(msg)); -} - - - -void AQH_ForwardIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FORWARD_MINSIZE) { - const uint8_t *ptr; - uint32_t len; - - ptr=AQH_ForwardIpcMsg_GetMsgPtr(msg); - len=AQH_ForwardIpcMsg_GetMsgLen(msg); - - GWEN_Buffer_AppendArgs(dbuf, "FORWARD (code=%d, protocol=%d, protocol version=%d)\n", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg)); - if (ptr && len) { - GWEN_Text_DumpString2Buffer((const char*)ptr, len, dbuf, 2); - GWEN_Buffer_AppendByte(dbuf, '\n'); - } - } -} - - - - - - - diff --git a/aqhome/ipc/nodes/msg_ipc_forward.h b/aqhome/ipc/nodes/msg_ipc_forward.h deleted file mode 100644 index 608920f..0000000 --- a/aqhome/ipc/nodes/msg_ipc_forward.h +++ /dev/null @@ -1,32 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_FORWARD_H -#define AQH_MSG_IPC_FORWARD_H - - -#include -#include -#include - -#include -#include - - - -AQHOME_API GWEN_MSG *AQH_ForwardIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, const uint8_t *ptr, uint32_t len); -AQHOME_API const uint8_t *AQH_ForwardIpcMsg_GetMsgPtr(const GWEN_MSG *msg); -AQHOME_API uint32_t AQH_ForwardIpcMsg_GetMsgLen(const GWEN_MSG *msg); -AQHOME_API GWEN_MSG *AQH_ForwardIpcMsg_GetCopyOfNodeMsg(const GWEN_MSG *msg); -AQHOME_API void AQH_ForwardIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - -#endif - - - diff --git a/aqhome/ipc/nodes/msg_ipc_getdevices_req.c b/aqhome/ipc/nodes/msg_ipc_getdevices_req.c deleted file mode 100644 index c13e52e..0000000 --- a/aqhome/ipc/nodes/msg_ipc_getdevices_req.c +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - - -#define AQH_MSGIPC_GETDEVICES_REQ_PAYLOADSIZE 0 -#define AQH_MSGIPC_GETDEVICES_REQ_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_REQ_PAYLOADSIZE) - - - - -GWEN_MSG *AQH_GetDevicesRequestIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId) -{ - return GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, - msgId, refMsgId, AQH_MSGIPC_GETDEVICES_REQ_PAYLOADSIZE, NULL); -} - - - -void AQH_GetDevicesRequestIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_GETDEVICES_REQ_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, - "GET_DEVICES REQ %s (code=%d, proto=%d, proto version=%d, msgId=%d, refMsgId=%d)\n", - sText?sText:"", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg), - GWEN_IpcMsg_GetMsgId(msg), - GWEN_IpcMsg_GetRefMsgId(msg)); - } -} - - - - - diff --git a/aqhome/ipc/nodes/msg_ipc_getdevices_req.h b/aqhome/ipc/nodes/msg_ipc_getdevices_req.h deleted file mode 100644 index 01cf3ed..0000000 --- a/aqhome/ipc/nodes/msg_ipc_getdevices_req.h +++ /dev/null @@ -1,27 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSGIPC_GETDEVICES_REQ_H -#define AQH_MSGIPC_GETDEVICES_REQ_H - - -#include -#include - -#include -#include - - -AQHOME_API GWEN_MSG *AQH_GetDevicesRequestIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId); - -AQHOME_API void AQH_GetDevicesRequestIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - diff --git a/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.c b/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.c deleted file mode 100644 index c747cf7..0000000 --- a/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.c +++ /dev/null @@ -1,189 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - - -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_FLAGS 0 /* 1 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_BUSADDR 1 /* 1 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_UID 2 /* 4 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_MANUF 6 /* 4 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_DEVTYPE 10 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_DEVVER 12 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_FWVER 14 /* 4 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_LASTCHG 18 /* 8 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_PKGOUT 26 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_PKGIN 28 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_COLLISIONS 30 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_BUSY 32 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_CRC 34 /* 2 bytes */ -#define AQH_MSGIPC_GETDEVICES_RSP_OFFS_IO 36 /* 2 bytes */ - - -#define AQH_MSGIPC_GETDEVICES_RSP_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_IO+2) - - - -GWEN_MSG *AQH_GetDevicesResponseIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint8_t flags, const AQH_NODE_INFO *ni) -{ - GWEN_MSG *msg; - const GWEN_TIMESTAMP *t; - - msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, msgId, refMsgId, 0, NULL); - GWEN_Msg_AddUint8(msg, flags & 0xff); - GWEN_Msg_AddUint8(msg, AQH_NodeInfo_GetBusAddress(ni)); - GWEN_Msg_AddUint32(msg, AQH_NodeInfo_GetUid(ni)); - - GWEN_Msg_AddUint32(msg, AQH_NodeInfo_GetManufacturer(ni)); - GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetDeviceType(ni)); - GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetDeviceVersion(ni)); - GWEN_Msg_AddUint32(msg, AQH_NodeInfo_GetFirmwareVersion(ni)); - t=AQH_NodeInfo_GetTimestampLastChange(ni); - GWEN_Msg_AddUint64(msg, t?((uint64_t)GWEN_Timestamp_toInt64(t)):0L); - - GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetStatsPacketsOut(ni)); - GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetStatsPacketsIn(ni)); - GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetStatsCollisions(ni)); - GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetStatsBusy(ni)); - GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetStatsCrcErrors(ni)); - GWEN_Msg_AddUint16(msg, AQH_NodeInfo_GetStatsIoErrors(ni)); - GWEN_IpcMsg_AdjustMsgSize(msg); - - return msg; -} - - - -uint8_t AQH_GetDevicesResponseIpcMsg_GetFlags(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_FLAGS, 0); -} - - - -uint8_t AQH_GetDevicesResponseIpcMsg_GetBusAddress(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_BUSADDR, 0); -} - - - -uint32_t AQH_GetDevicesResponseIpcMsg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_UID, 0); -} - - - -uint32_t AQH_GetDevicesResponseIpcMsg_GetManufacturer(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_MANUF, 0); -} - - - -uint16_t AQH_GetDevicesResponseIpcMsg_GetDeviceType(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_DEVTYPE, 0); -} - - - -uint16_t AQH_GetDevicesResponseIpcMsg_GetDeviceVersion(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_DEVVER, 0); -} - - - -uint32_t AQH_GetDevicesResponseIpcMsg_GetFirmwareVersion(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_FWVER, 0); -} - - - -int64_t AQH_GetDevicesResponseIpcMsg_GetTimestamp(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint64At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_LASTCHG, 0); -} - - - -uint16_t AQH_GetDevicesResponseIpcMsg_GetPkgOut(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_PKGOUT, 0); -} - - - -uint16_t AQH_GetDevicesResponseIpcMsg_GetPkgIn(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_PKGIN, 0); -} - - - -uint16_t AQH_GetDevicesResponseIpcMsg_GetCollisions(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_COLLISIONS, 0); -} - - - -uint16_t AQH_GetDevicesResponseIpcMsg_GetBusy(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_BUSY, 0); -} - - - -uint16_t AQH_GetDevicesResponseIpcMsg_GetCrcErrors(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_CRC, 0); -} - - - -uint16_t AQH_GetDevicesResponseIpcMsg_GetIoErrors(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_GETDEVICES_RSP_OFFS_IO, 0); -} - - - -void AQH_GetDevicesResponseIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_GETDEVICES_RSP_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, - "GET_DEVICES_RSP %s (code=%d, proto=%d, proto version=%d, uid=0x%08x, bus addr=0x%02x, flags=0x%02x)\n", - sText, - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg), - (unsigned int) AQH_GetDevicesResponseIpcMsg_GetUid(msg), - AQH_GetDevicesResponseIpcMsg_GetBusAddress(msg), - AQH_GetDevicesResponseIpcMsg_GetFlags(msg)); - } -} - - diff --git a/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h b/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h deleted file mode 100644 index 0c639d4..0000000 --- a/aqhome/ipc/nodes/msg_ipc_getdevices_rsp.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSGIPC_GETDEVICES_RSP_H -#define AQH_MSGIPC_GETDEVICES_RSP_H - - -#include -#include -#include - -#include -#include - - -#define AQH_MSGIPC_GETDEVICES_RSP_FLAGS_LAST 0x01 - - -AQHOME_API GWEN_MSG *AQH_GetDevicesResponseIpcMsg_new(uint16_t code, - uint32_t msgId, uint32_t refMsgId, - uint8_t flags, const AQH_NODE_INFO *ni); - -AQHOME_API uint8_t AQH_GetDevicesResponseIpcMsg_GetFlags(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_GetDevicesResponseIpcMsg_GetBusAddress(const GWEN_MSG *msg); - -AQHOME_API uint32_t AQH_GetDevicesResponseIpcMsg_GetUid(const GWEN_MSG *msg); - -AQHOME_API uint32_t AQH_GetDevicesResponseIpcMsg_GetManufacturer(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetDeviceType(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetDeviceVersion(const GWEN_MSG *msg); -AQHOME_API uint32_t AQH_GetDevicesResponseIpcMsg_GetFirmwareVersion(const GWEN_MSG *msg); - -AQHOME_API int64_t AQH_GetDevicesResponseIpcMsg_GetTimestamp(const GWEN_MSG *msg); - -AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetPkgOut(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetPkgIn(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetCollisions(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetBusy(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetCrcErrors(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_GetDevicesResponseIpcMsg_GetIoErrors(const GWEN_MSG *msg); - - -AQHOME_API void AQH_GetDevicesResponseIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - diff --git a/aqhome/ipc/nodes/msg_ipc_ping.c b/aqhome/ipc/nodes/msg_ipc_ping.c deleted file mode 100644 index 837507c..0000000 --- a/aqhome/ipc/nodes/msg_ipc_ping.c +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - - -#define AQH_MSGIPC_PING_OFFS_DESTADDR 0 /* 1 bytes */ - -#define AQH_MSGIPC_PING_PAYLOADSIZE 1 -#define AQH_MSGIPC_PING_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_PING_PAYLOADSIZE) - - - - -GWEN_MSG *AQH_PingIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint8_t destAddr) -{ - GWEN_MSG *msg; - - msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, - msgId, refMsgId, - AQH_MSGIPC_PING_PAYLOADSIZE, NULL); - GWEN_Msg_AddUint8(msg, destAddr & 0xff); - - return msg; -} - - - -uint8_t AQH_PingIpcMsg_GetDestAddr(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_PING_OFFS_DESTADDR, 0); -} - - - -void AQH_PingIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_PING_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, - "PING %s (code=%d, proto=%d, proto version=%d, dest addr=%02x)\n", - sText?sText:"", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg), - AQH_PingIpcMsg_GetDestAddr(msg)); - } -} - - - - - diff --git a/aqhome/ipc/nodes/msg_ipc_ping.h b/aqhome/ipc/nodes/msg_ipc_ping.h deleted file mode 100644 index 4c348a2..0000000 --- a/aqhome/ipc/nodes/msg_ipc_ping.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_PING_H -#define AQH_MSG_IPC_PING_H - - -#include -#include - -#include -#include - - -AQHOME_API GWEN_MSG *AQH_PingIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint8_t destAddr); - -AQHOME_API uint8_t AQH_PingIpcMsg_GetDestAddr(const GWEN_MSG *msg); - -AQHOME_API void AQH_PingIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - diff --git a/aqhome/ipc/nodes/msg_ipc_setaccmsggrps.c b/aqhome/ipc/nodes/msg_ipc_setaccmsggrps.c deleted file mode 100644 index 35f5dec..0000000 --- a/aqhome/ipc/nodes/msg_ipc_setaccmsggrps.c +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - - -#define AQH_MSGIPC_SETACCEPTEDMSGGRPS_OFFS_GROUPS 0 /* 4 bytes */ - -#define AQH_MSGIPC_SETACCEPTEDMSGGRPS_PAYLOADSIZE (AQH_MSGIPC_SETACCEPTEDMSGGRPS_OFFS_GROUPS+4) -#define AQH_MSGIPC_SETACCEPTEDMSGGRPS_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_SETACCEPTEDMSGGRPS_PAYLOADSIZE) - - - - -GWEN_MSG *AQH_SetAcceptedMsgGroupsIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint32_t groups) -{ - GWEN_MSG *msg; - uint8_t *ptr; - - msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, - msgId, refMsgId, - AQH_MSGIPC_SETACCEPTEDMSGGRPS_PAYLOADSIZE, NULL); - GWEN_Msg_AddUint32(msg, groups); - return msg; -} - - - -uint32_t AQH_SetAcceptedMsgGroupsIpcMsg_GetMsgGroups(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_SETACCEPTEDMSGGRPS_OFFS_GROUPS, 0); -} - - - -void AQH_SetAcceptedMsgGroupsIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_SETACCEPTEDMSGGRPS_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, - "SET_ACCEPTED_MSG_GROUPS (code=%d, proto=%d, proto version=%d, groups=%08x)\n", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg), - AQH_SetAcceptedMsgGroupsIpcMsg_GetMsgGroups(msg)); - } -} - - - diff --git a/aqhome/ipc/nodes/msg_ipc_setaccmsggrps.h b/aqhome/ipc/nodes/msg_ipc_setaccmsggrps.h deleted file mode 100644 index 7c4b513..0000000 --- a/aqhome/ipc/nodes/msg_ipc_setaccmsggrps.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSGIPC_SETACCEPTEDMSGGRPS_H -#define AQH_MSGIPC_SETACCEPTEDMSGGRPS_H - - -#include -#include - -#include -#include - - -AQHOME_API GWEN_MSG *AQH_SetAcceptedMsgGroupsIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint32_t groups); - -AQHOME_API uint32_t AQH_SetAcceptedMsgGroupsIpcMsg_GetMsgGroups(const GWEN_MSG *msg); - -AQHOME_API void AQH_SetAcceptedMsgGroupsIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - diff --git a/aqhome/ipc/nodes/msg_ipc_value.c b/aqhome/ipc/nodes/msg_ipc_value.c deleted file mode 100644 index 365f744..0000000 --- a/aqhome/ipc/nodes/msg_ipc_value.c +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include - -#include -#include - -#include -#include -#include -#include -#include -#include - - -#define AQH_MSGIPC_VALUE_OFFS_UID 0 /* 4 bytes */ -#define AQH_MSGIPC_VALUE_OFFS_VALUEID 4 /* 1 byte */ -#define AQH_MSGIPC_VALUE_OFFS_VALUETYPE 5 /* 1 byte */ -#define AQH_MSGIPC_VALUE_OFFS_VALUE_NOM 6 /* 2 bytes */ -#define AQH_MSGIPC_VALUE_OFFS_VALUE_DENOM 8 /* 2 bytes */ - -#define AQH_MSGIPC_VALUE_PAYLOADIZE (AQH_MSGIPC_VALUE_OFFS_UID+10) -#define AQH_MSGIPC_VALUE_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_PAYLOADIZE) - - - - -GWEN_MSG *AQH_ValueIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, - uint32_t uid, - uint8_t valueId, - uint8_t valueType, - int16_t valueNom, - int16_t valueDenom) -{ - GWEN_MSG *msg; - uint8_t *ptr; - - msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_NODES_ID, AQH_IPC_PROTOCOL_NODES_VERSION, code, - msgId, refMsgId, AQH_MSGIPC_VALUE_PAYLOADIZE, NULL); - GWEN_Msg_AddUint32(msg, uid); - GWEN_Msg_AddUint8(msg, valueId); - GWEN_Msg_AddUint8(msg, valueType); - GWEN_Msg_AddUint16(msg, valueNom); - GWEN_Msg_AddUint16(msg, valueDenom); - - return msg; -} - - - -uint32_t AQH_ValueIpcMsg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_UID, 0); -} - - - -uint8_t AQH_ValueIpcMsg_GetValueId(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUEID, 0); -} - - - -uint8_t AQH_ValueIpcMsg_GetValueType(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUETYPE, 0); -} - - - -int16_t AQH_ValueIpcMsg_GetValueNom(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUE_NOM, 0); -} - - - -int16_t AQH_ValueIpcMsg_GetValueDenom(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_VALUE_OFFS_VALUE_DENOM, 1); -} - - - -double AQH_ValueIpcMsg_GetValueAsDouble(const GWEN_MSG *msg) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_VALUE_MINSIZE) { - double nom; - int16_t rawDenom; - double denom; - - nom=(double) AQH_ValueIpcMsg_GetValueNom(msg); - rawDenom=AQH_ValueIpcMsg_GetValueDenom(msg); - if (rawDenom==0) - denom=1.0; - else - denom=(double) rawDenom; - return (double)(nom/denom); - } - return 0.0; -} - - - -void AQH_ValueIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGIPC_VALUE_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, - "VALUE (code=%d, proto=%d, proto version=%d, uid=0x%08x, value_id=0x%02x, type=0x%02x, value=%f)\n", - GWEN_IpcMsg_GetCode(msg), - GWEN_IpcMsg_GetProtoId(msg), - GWEN_IpcMsg_GetProtoVersion(msg), - (unsigned int) AQH_ValueIpcMsg_GetUid(msg), - AQH_ValueIpcMsg_GetValueId(msg), - AQH_ValueIpcMsg_GetValueType(msg), - AQH_ValueIpcMsg_GetValueAsDouble(msg)); - } -} - - - - - - - diff --git a/aqhome/ipc/nodes/msg_ipc_value.h b/aqhome/ipc/nodes/msg_ipc_value.h deleted file mode 100644 index 0e5ceb9..0000000 --- a/aqhome/ipc/nodes/msg_ipc_value.h +++ /dev/null @@ -1,41 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_IPC_VALUE_H -#define AQH_MSG_IPC_VALUE_H - - -#include -#include -#include - -#include -#include - - - -AQHOME_API GWEN_MSG *AQH_ValueIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, - uint32_t uid, - uint8_t valueId, - uint8_t valueType, - int16_t valueNom, - int16_t valueDenom); -AQHOME_API uint32_t AQH_ValueIpcMsg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_ValueIpcMsg_GetValueId(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_ValueIpcMsg_GetValueType(const GWEN_MSG *msg); -AQHOME_API int16_t AQH_ValueIpcMsg_GetValueNom(const GWEN_MSG *msg); -AQHOME_API int16_t AQH_ValueIpcMsg_GetValueDenom(const GWEN_MSG *msg); -AQHOME_API double AQH_ValueIpcMsg_GetValueAsDouble(const GWEN_MSG *msg); - -AQHOME_API void AQH_ValueIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - -#endif - - - diff --git a/aqhome/ipc/requests.c b/aqhome/ipc/requests.c deleted file mode 100644 index 78630cd..0000000 --- a/aqhome/ipc/requests.c +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2024 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include "./requests.h" - -#include -#include - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static void _freeFinishedRequests(GWEN_MSG_REQUEST *rq); - - - - -void AQH_Requests_CheckTimeouts(GWEN_MSG_REQUEST *requestTreeRoot) -{ - if (requestTreeRoot) { - GWEN_MSG_REQUEST *rq; - GWEN_TIMESTAMP *now; - - now=GWEN_Timestamp_NowInLocalTime(); - rq=GWEN_MsgRequest_Tree2_GetFirstChild(requestTreeRoot); - while(rq) { - const GWEN_TIMESTAMP *ts; - - ts=GWEN_MsgRequest_GetExpiresAt(rq); - if (GWEN_Timestamp_Compare(now, ts)>=0) { - /* timeout */ - DBG_INFO(NULL, "Request timed out, aborting"); - GWEN_MsgRequest_Abort(rq, GWEN_MSG_REQUEST_REASON_TIMEOUT); - } - rq=GWEN_MsgRequest_Tree2_GetBelow(rq); - } - GWEN_Timestamp_free(now); - } -} - - - -void AQH_Requests_Cleanup(GWEN_MSG_REQUEST *requestTreeRoot) -{ - if (requestTreeRoot) { - GWEN_MSG_REQUEST *rq; - - rq=GWEN_MsgRequest_Tree2_GetFirstChild(requestTreeRoot); - while(rq) { - GWEN_MSG_REQUEST *nextSubRq; - - nextSubRq=GWEN_MsgRequest_Tree2_GetNext(rq); - _freeFinishedRequests(rq); - rq=nextSubRq; - } - } -} - - - -int AQH_Requests_HandleIpcMsg(GWEN_MSG_REQUEST *requestTreeRoot, GWEN_MSG_ENDPOINT *srcEp, GWEN_MSG *recvdMsg) -{ - if (requestTreeRoot) { - uint32_t refMsgId; - - refMsgId=GWEN_IpcMsg_GetRefMsgId(recvdMsg); - if (refMsgId) { - GWEN_MSG_REQUEST *rq; - - rq=GWEN_MsgRequest_Tree2_GetFirstChild(requestTreeRoot); - while(rq) { - if (srcEp==GWEN_MsgRequest_GetEndpoint(rq) && refMsgId==GWEN_MsgRequest_GetRequestMsgId(rq)) { - if (GWEN_MsgRequest_HandleResponse(rq, recvdMsg)==GWEN_MSG_REQUEST_RESULT_HANDLED) - return GWEN_MSG_REQUEST_RESULT_HANDLED; - } - - rq=GWEN_MsgRequest_Tree2_GetBelow(rq); - } - } - else { - DBG_INFO(NULL, "Message has no reference msg id, not a response"); - } - } - return GWEN_MSG_REQUEST_RESULT_NOT_HANDLED; -} - - - -int AQH_Requests_HandleTtyMsg(GWEN_MSG_REQUEST *requestTreeRoot, GWEN_MSG_ENDPOINT *srcEp, GWEN_MSG *recvdMsg) -{ - if (requestTreeRoot) { - GWEN_MSG_REQUEST *rq; - - rq=GWEN_MsgRequest_Tree2_GetFirstChild(requestTreeRoot); - while(rq) { - if (srcEp==GWEN_MsgRequest_GetEndpoint(rq)) { - if (GWEN_MsgRequest_HandleResponse(rq, recvdMsg)==GWEN_MSG_REQUEST_RESULT_HANDLED) - return GWEN_MSG_REQUEST_RESULT_HANDLED; - } - - rq=GWEN_MsgRequest_Tree2_GetBelow(rq); - } - } - return GWEN_MSG_REQUEST_RESULT_NOT_HANDLED; -} - - - -void _freeFinishedRequests(GWEN_MSG_REQUEST *rq) -{ - GWEN_MSG_REQUEST *subRq; - - subRq=GWEN_MsgRequest_Tree2_GetFirstChild(rq); - while(subRq) { - GWEN_MSG_REQUEST *nextSubRq; - - nextSubRq=GWEN_MsgRequest_Tree2_GetNext(subRq); - _freeFinishedRequests(subRq); - subRq=nextSubRq; - } - - if (GWEN_MsgRequest_GetState(rq)==GWEN_MSG_REQUEST_STATE_DONE) { - DBG_INFO(NULL, "Deleting request"); - GWEN_MsgRequest_free(rq); - } -} - - - diff --git a/aqhome/ipc/requests.h b/aqhome/ipc/requests.h deleted file mode 100644 index 44e36be..0000000 --- a/aqhome/ipc/requests.h +++ /dev/null @@ -1,30 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2024 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQHOME_REQUESTS_H -#define AQHOME_REQUESTS_H - - -#include - -#include - - - -AQHOME_API void AQH_Requests_CheckTimeouts(GWEN_MSG_REQUEST *requestTreeRoot); -AQHOME_API void AQH_Requests_Cleanup(GWEN_MSG_REQUEST *requestTreeRoot); - -AQHOME_API int AQH_Requests_HandleIpcMsg(GWEN_MSG_REQUEST *requestTreeRoot, GWEN_MSG_ENDPOINT *srcEp, GWEN_MSG *recvdMsg); -AQHOME_API int AQH_Requests_HandleTtyMsg(GWEN_MSG_REQUEST *requestTreeRoot, GWEN_MSG_ENDPOINT *srcEp, GWEN_MSG *recvdMsg); - - - - -#endif - - diff --git a/aqhome/ipc2/0BUILD b/aqhome/ipc2/0BUILD index 863cf1e..3e70e87 100644 --- a/aqhome/ipc2/0BUILD +++ b/aqhome/ipc2/0BUILD @@ -45,20 +45,20 @@ - msgreader.h - msgwriter.h - ipcmsgreader.h - nodemsgreader.h - mqttmsgreader.h - ttyobject.h - tcpd_object.h - tcp_object.h endpoint.h message.h msgrequest.h + msgreader.h + msgwriter.h + ipcm_sgreader.h + node_msgreader.h + tcpd_object.h + tcp_object.h ipc_server.h ipc_client.h + tty_object.h tty_endpoint.h + mqtt_msgreader.h mqtt_endpoint.h mqtt_client.h @@ -78,20 +78,20 @@ $(local/typefiles) - msgreader.c - msgwriter.c - ipcmsgreader.c - nodemsgreader.c - mqttmsgreader.c - ttyobject.c - tcpd_object.c - tcp_object.c endpoint.c message.c msgrequest.c + msgreader.c + msgwriter.c + node_msgreader.c + mqtt_msgreader.c + tcpd_object.c + tcp_object.c + ipc_msgreader.c ipc_server.c ipc_client.c ipc_endpoint.c + tty_object.c tty_endpoint.c mqtt_endpoint.c mqtt_client.c diff --git a/aqhome/ipc2/endpoint.c b/aqhome/ipc2/endpoint.c index 4e25306..d4c5100 100644 --- a/aqhome/ipc2/endpoint.c +++ b/aqhome/ipc2/endpoint.c @@ -561,7 +561,7 @@ int _handleClosed(AQH_OBJECT *o) { AQH_ENDPOINT *xo; - DBG_ERROR(AQH_LOGDOMAIN, "Connection closed."); + DBG_INFO(AQH_LOGDOMAIN, "Connection closed."); xo=GWEN_INHERIT_GETDATA(AQH_OBJECT, AQH_ENDPOINT, o); if (xo) { AQH_Object_Disable(xo->msgWriter); diff --git a/aqhome/ipc2/ipc_client.c b/aqhome/ipc2/ipc_client.c index 67878d5..587be46 100644 --- a/aqhome/ipc2/ipc_client.c +++ b/aqhome/ipc2/ipc_client.c @@ -12,7 +12,7 @@ #include "./ipc_client.h" -#include +#include #include #include diff --git a/aqhome/ipc2/ipcmsgreader.c b/aqhome/ipc2/ipc_msgreader.c similarity index 99% rename from aqhome/ipc2/ipcmsgreader.c rename to aqhome/ipc2/ipc_msgreader.c index 5bb9a8e..3c4b78c 100644 --- a/aqhome/ipc2/ipcmsgreader.c +++ b/aqhome/ipc2/ipc_msgreader.c @@ -10,7 +10,7 @@ # include #endif -#include "./ipcmsgreader.h" +#include "./ipc_msgreader.h" #include "./msgreader_p.h" #include diff --git a/aqhome/ipc2/ipcmsgreader.h b/aqhome/ipc2/ipc_msgreader.h similarity index 100% rename from aqhome/ipc2/ipcmsgreader.h rename to aqhome/ipc2/ipc_msgreader.h diff --git a/aqhome/ipc2/ipc_server.c b/aqhome/ipc2/ipc_server.c index 4270753..455d2b2 100644 --- a/aqhome/ipc2/ipc_server.c +++ b/aqhome/ipc2/ipc_server.c @@ -13,7 +13,7 @@ #include "./ipc_server_p.h" #include -#include +#include #include #include @@ -121,7 +121,7 @@ int _handleNewConn(AQH_OBJECT *o, int newFd) AQH_OBJECT *msgWriter; AQH_OBJECT *endpoint; - DBG_ERROR(AQH_LOGDOMAIN, "Incoming connection"); + DBG_INFO(AQH_LOGDOMAIN, "Incoming connection"); eventLoop=AQH_Object_GetEventLoop(o); fdCopy=dup(newFd); diff --git a/aqhome/ipc2/mqtt_client.c b/aqhome/ipc2/mqtt_client.c index f51cc31..a94f3b5 100644 --- a/aqhome/ipc2/mqtt_client.c +++ b/aqhome/ipc2/mqtt_client.c @@ -12,7 +12,7 @@ #include "./mqtt_client.h" -#include +#include #include #include diff --git a/aqhome/ipc2/mqttmsgreader.c b/aqhome/ipc2/mqtt_msgreader.c similarity index 99% rename from aqhome/ipc2/mqttmsgreader.c rename to aqhome/ipc2/mqtt_msgreader.c index 2c5a703..8ff3107 100644 --- a/aqhome/ipc2/mqttmsgreader.c +++ b/aqhome/ipc2/mqtt_msgreader.c @@ -10,7 +10,7 @@ # include #endif -#include "./mqttmsgreader.h" +#include "./mqtt_msgreader.h" #include "./msgreader_p.h" #include diff --git a/aqhome/ipc2/mqttmsgreader.h b/aqhome/ipc2/mqtt_msgreader.h similarity index 100% rename from aqhome/ipc2/mqttmsgreader.h rename to aqhome/ipc2/mqtt_msgreader.h diff --git a/aqhome/ipc2/nodemsgreader.c b/aqhome/ipc2/node_msgreader.c similarity index 99% rename from aqhome/ipc2/nodemsgreader.c rename to aqhome/ipc2/node_msgreader.c index f83957a..8a04290 100644 --- a/aqhome/ipc2/nodemsgreader.c +++ b/aqhome/ipc2/node_msgreader.c @@ -10,7 +10,7 @@ # include #endif -#include "./nodemsgreader.h" +#include "./node_msgreader.h" #include "./msgreader_p.h" #include diff --git a/aqhome/ipc2/nodemsgreader.h b/aqhome/ipc2/node_msgreader.h similarity index 100% rename from aqhome/ipc2/nodemsgreader.h rename to aqhome/ipc2/node_msgreader.h diff --git a/aqhome/ipc2/tcpd_object.c b/aqhome/ipc2/tcpd_object.c index 07bda63..6f651b6 100644 --- a/aqhome/ipc2/tcpd_object.c +++ b/aqhome/ipc2/tcpd_object.c @@ -186,7 +186,7 @@ int _handleSocketReady(AQH_OBJECT *o) DBG_ERROR(AQH_LOGDOMAIN, "here (%d)", clientSk); } else { - DBG_ERROR(AQH_LOGDOMAIN, "New connection"); + DBG_INFO(AQH_LOGDOMAIN, "New connection"); if (0==AQH_Object_EmitSignal(o, AQH_TCPD_OBJECT_SIGNAL_NEWCONN, clientSk, NULL)) { DBG_ERROR(AQH_LOGDOMAIN, "New connection not handled"); close(clientSk); diff --git a/aqhome/ipc2/tty_endpoint.c b/aqhome/ipc2/tty_endpoint.c index c66cbc3..e67ea29 100644 --- a/aqhome/ipc2/tty_endpoint.c +++ b/aqhome/ipc2/tty_endpoint.c @@ -12,9 +12,9 @@ #include "./tty_endpoint.h" -#include +#include #include -#include +#include #include #include diff --git a/aqhome/ipc2/ttyobject.c b/aqhome/ipc2/tty_object.c similarity index 99% rename from aqhome/ipc2/ttyobject.c rename to aqhome/ipc2/tty_object.c index 876ff56..364a900 100644 --- a/aqhome/ipc2/ttyobject.c +++ b/aqhome/ipc2/tty_object.c @@ -10,7 +10,7 @@ # include #endif -#include "./ttyobject.h" +#include "./tty_object.h" #include #include diff --git a/aqhome/ipc2/ttyobject.h b/aqhome/ipc2/tty_object.h similarity index 100% rename from aqhome/ipc2/ttyobject.h rename to aqhome/ipc2/tty_object.h diff --git a/aqhome/libtest.c b/aqhome/libtest.c index ba10c61..97eedaa 100644 --- a/aqhome/libtest.c +++ b/aqhome/libtest.c @@ -19,8 +19,8 @@ #include "aqhome/events2/eventloop.h" #include "aqhome/events2/fdobject.h" -#include "aqhome/ipc2/ttyobject.h" -#include "aqhome/ipc2/nodemsgreader.h" +#include "aqhome/ipc2/tty_object.h" +#include "aqhome/ipc2/node_msgreader.h" #include "aqhome/ipc2/msgreader.h" #include "aqhome/ipc2/msgwriter.h" #include "aqhome/ipc2/endpoint.h" @@ -40,269 +40,6 @@ #include -static int _mqttConnect2(GWEN_MSG_ENDPOINT *epClient); -static GWEN_MSG *_awaitPacket2(GWEN_MSG_ENDPOINT *epClient, uint8_t expectedPacketType); - - - -GWEN_MSG *createPingMsg(uint8_t destAddr, uint8_t srcAddr) -{ - GWEN_MSG *msg; - int rv; - - msg=GWEN_Msg_new(AQH_MAXMSGSIZE); - rv=GWEN_Msg_AddByte(msg, destAddr); - if (rv<0) { - fprintf(stderr, "ERROR1: %d\n", rv); - GWEN_Msg_free(msg); - return NULL; - } - rv=GWEN_Msg_AddByte(msg, 6); /* msglen */ - if (rv<0) { - fprintf(stderr, "ERROR2: %d\n", rv); - GWEN_Msg_free(msg); - return NULL; - } - rv=GWEN_Msg_AddByte(msg, AQH_MSG_TYPE_PING); /* ping */ - if (rv<0) { - fprintf(stderr, "ERROR3: %d\n", rv); - GWEN_Msg_free(msg); - return NULL; - } - rv=GWEN_Msg_AddByte(msg, srcAddr); /* src addr */ - if (rv<0) { - fprintf(stderr, "ERROR4: %d\n", rv); - GWEN_Msg_free(msg); - return NULL; - } - - rv=GWEN_Msg_AddByte(msg, 0); /* timestamp */ - if (rv<0) { - fprintf(stderr, "ERROR5: %d\n", rv); - GWEN_Msg_free(msg); - return NULL; - } - rv=GWEN_Msg_AddByte(msg, 0); /* timestamp */ - if (rv<0) { - fprintf(stderr, "ERROR6: %d\n", rv); - GWEN_Msg_free(msg); - return NULL; - } - rv=GWEN_Msg_AddByte(msg, 0); /* timestamp */ - if (rv<0) { - fprintf(stderr, "ERROR7: %d\n", rv); - GWEN_Msg_free(msg); - return NULL; - } - rv=GWEN_Msg_AddByte(msg, 0); /* timestamp */ - if (rv<0) { - fprintf(stderr, "ERROR8: %d\n", rv); - GWEN_Msg_free(msg); - return NULL; - } - - - rv=AQH_NodeMsg_AddChecksum(msg); - if (rv<0) { - fprintf(stderr, "ERROR9: %d\n", rv); - GWEN_Msg_free(msg); - return NULL; - } - - return msg; -} - - - -int testMqttConnection2() -{ - GWEN_MSG_ENDPOINT *epClient; - int loop; - - AQH_Init(); - - epClient=AQH_MqttClientEndpoint_new("TESTCLIENT1234", "127.0.0.1", 1883, NULL, 1); - for (loop=0;; loop++) { - DBG_INFO(GWEN_LOGDOMAIN, "Loop %d:", loop); - GWEN_MsgEndpoint_IoLoop(epClient, 2000); /* 2000 ms */ - - if (GWEN_MsgEndpoint_GetState(epClient)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) { - DBG_INFO(AQH_LOGDOMAIN, "Connected."); - break; - } - } - return 0; -} - - - -int testMqttSubscribe2(int argc, char **argv) -{ - GWEN_MSG_ENDPOINT *epClient; - int rv; - GWEN_MSG *msgOut; - GWEN_MSG *msgIn; - uint16_t pckId; - const char *host="127.0.0.1"; - - AQH_Init(); - - if (argc>1) - host=argv[1]; - - DBG_ERROR(AQH_LOGDOMAIN, "Connecting to %s (%s)", host, argv[1]); - epClient=AQH_MqttClientEndpoint_new("TESTCLIENT1234", host, 1883, NULL, 1); - rv=_mqttConnect2(epClient); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return 2; - } - - pckId=AQH_MqttClientEndpoint_GetNextPacketId(epClient); - //msgOut=AQH_PublishMqttMsg_new(AQH_MQTTMSG_FLAGS_QOS1, 1, "test/subject1", (const uint8_t*) "29.9", 4); - //msgOut=GWEN_SubscribeMqttMsg_new(AQH_MQTTMSG_MSGTYPE_SUBSCRIBE, pckId, "aqhome/#", 0); - msgOut=GWEN_SubscribeMqttMsg_new(AQH_MQTTMSG_MSGTYPE_SUBSCRIBE, pckId, "#", 0); - if (msgOut==NULL) { - DBG_ERROR(NULL, "Error creating message"); - return 2; - } - GWEN_MsgEndpoint_AddSendMessage(epClient, msgOut); - - msgIn=_awaitPacket2(epClient, AQH_MQTTMSG_MSGTYPE_SUBACK); - if (msgIn) { - GWEN_BUFFER *buf; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - AQH_SubAckMqttMsg_DumpToBuffer(msgIn, buf, "received"); - fprintf(stdout, "%s\n", GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - GWEN_Msg_free(msgIn); - } - - for (;;) { - GWEN_MSG *msg; - - GWEN_MsgEndpoint_IoLoop(epClient, 2000); /* 2000 ms */ - msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epClient); - if (msg) { - if ((AQH_MqttMsg_GetMsgTypeAndFlags(msg) & 0xf0)==(AQH_MQTTMSG_MSGTYPE_PUBLISH & 0xf0)) { - GWEN_BUFFER *buf; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - AQH_PublishMqttMsg_DumpToBuffer(msg, buf, "received"); - fprintf(stdout, "%s\n", GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - } - else { - DBG_ERROR(NULL, "Received this message:"); - GWEN_Text_DumpString((const char*) GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg), 2); - } - GWEN_Msg_free(msg); - } - } - - - return 0; -} - - - -int testMqttSubscribe3(int argc, char **argv) -{ - GWEN_MSG_ENDPOINT *epClient; - int rv; - //const char *host="127.0.0.1"; - const char *host="192.168.117.192"; - - AQH_Init(); - - if (argc>1) - host=argv[1]; - - DBG_ERROR(AQH_LOGDOMAIN, "Connecting to %s (%s)", host, argv[1]); - epClient=AQH_MqttClientEndpoint_new("TESTCLIENT1234", host, 1883, NULL, 1); - GWEN_MsgEndpoint_AddFlags(epClient, AQH_ENDPOINT2_MQTTCLIENT_FLAGS_SUBSCRIBEALL); - rv=GWEN_MultilayerEndpoint_StartConnect(epClient); - if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) { - DBG_ERROR(NULL, "Error on startConnect: %d", rv); - return 2; - } - - for (;;) { - GWEN_MSG *msg; - - GWEN_MsgEndpoint_IoLoop(epClient, 2000); /* 2000 ms */ - msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epClient); - if (msg) { - if ((AQH_MqttMsg_GetMsgTypeAndFlags(msg) & 0xf0)==(AQH_MQTTMSG_MSGTYPE_PUBLISH & 0xf0)) { - GWEN_BUFFER *buf; - - buf=GWEN_Buffer_new(0, 256, 0, 1); - AQH_PublishMqttMsg_DumpToBuffer(msg, buf, "received"); - fprintf(stdout, "%s\n", GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - } - else { - DBG_ERROR(NULL, "Received this message:"); - GWEN_Text_DumpString((const char*) GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg), 2); - } - GWEN_Msg_free(msg); - } - } - - - return 0; -} - - - -int _mqttConnect2(GWEN_MSG_ENDPOINT *epClient) -{ - int loop; - - for (loop=0;; loop++) { - DBG_INFO(GWEN_LOGDOMAIN, "Loop %d:", loop); - GWEN_MsgEndpoint_IoLoop(epClient, 2000); /* 2000 ms */ - - if (GWEN_MsgEndpoint_GetState(epClient)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) { - DBG_INFO(AQH_LOGDOMAIN, "Connected."); - break; - } - else if (GWEN_MsgEndpoint_GetState(epClient)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) { - DBG_INFO(AQH_LOGDOMAIN, "Disconnected."); - return GWEN_ERROR_IO; - } - } - - return 0; -} - - - -GWEN_MSG *_awaitPacket2(GWEN_MSG_ENDPOINT *epClient, uint8_t expectedPacketType) -{ - fprintf(stdout, "Waiting for response\n"); - for (;;) { - GWEN_MSG *msg; - - DBG_DEBUG(AQH_LOGDOMAIN, "Next loop"); - GWEN_MsgEndpoint_IoLoop(epClient, 2000); /* 2000 ms */ - msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epClient); - if (msg) { - if ((AQH_MqttMsg_GetMsgTypeAndFlags(msg) & 0xf0)==(expectedPacketType & 0xf0)) { - return msg; - } - else { - DBG_ERROR(NULL, "Received this message:"); - GWEN_Text_DumpString((const char*) GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg), 2); - } - } - } /* for */ - - return NULL; -} - - #if 0 GWEN_MSG_ENDPOINT *_acceptHttpConnection(GWEN_UNUSED GWEN_MSG_ENDPOINT *ep, diff --git a/aqhome/mqtt/0BUILD b/aqhome/mqtt/0BUILD deleted file mode 100644 index e1dee69..0000000 --- a/aqhome/mqtt/0BUILD +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - $(gwenhywfar_cflags) - -I$(topsrcdir) - -I$(topbuilddir) - - - - --include=$(builddir) - --include=$(srcdir) - - - - - - $(visibility_cflags) - - - - --api=AQHOME_API - - - - - - - - - - - - - - - - - - $(local/built_headers_pub) - - - - - endpoint_mqtt.h - endpoint_mqttc.h - msg_mqtt.h - msg_mqtt_connect.h - msg_mqtt_connack.h - msg_mqtt_publish.h - msg_mqtt_pubresponse.h - msg_mqtt_subscribe.h - msg_mqtt_suback.h - - - - - endpoint_mqtt_p.h - - - - - $(local/typefiles) - - endpoint_mqtt.c - endpoint_mqttc.c - msg_mqtt.c - msg_mqtt_connect.c - msg_mqtt_connack.c - msg_mqtt_publish.c - msg_mqtt_pubresponse.c - msg_mqtt_subscribe.c - msg_mqtt_suback.c - - - - - - - - - - - - - - - - - - - diff --git a/aqhome/mqtt/endpoint_mqtt.c b/aqhome/mqtt/endpoint_mqtt.c deleted file mode 100644 index d3a41e7..0000000 --- a/aqhome/mqtt/endpoint_mqtt.c +++ /dev/null @@ -1,226 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/mqtt/endpoint_mqtt_p.h" - -#include "aqhome/mqtt/msg_mqtt_connect.h" -#include "aqhome/mqtt/msg_mqtt_publish.h" - -#include -#include -#include - - -#define AQH_ENDPOINT_MQTT_DEFAULT_KEEPALIVE 600 - - - -GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT) - - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static void GWENHYWFAR_CB _freeData(void *bp, void *p); -static int _getBytesNeededForMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg); -static int _calcAndSetPayloadSizeAndOffset(GWEN_MSG *msg); - - - -/* ------------------------------------------------------------------------------------------------ - * implementations - * ------------------------------------------------------------------------------------------------ - */ - - -void AQH_MqttEndpoint_Extend(GWEN_MSG_ENDPOINT *ep) -{ - if (ep) { - AQH_ENDPOINT_MQTT *xep; - - GWEN_NEW_OBJECT(AQH_ENDPOINT_MQTT, xep); - GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep, xep, _freeData); - xep->keepAliveTime=AQH_ENDPOINT_MQTT_DEFAULT_KEEPALIVE; - - GWEN_MsgIoEndpoint_SetGetNeededBytesFn(ep, _getBytesNeededForMessage); - } -} - - - -void GWENHYWFAR_CB _freeData(GWEN_UNUSED void *bp, void *p) -{ - AQH_ENDPOINT_MQTT *xep; - - xep=(AQH_ENDPOINT_MQTT*) p; - free(xep->clientId); - GWEN_FREE_OBJECT(xep); -} - - - -const char *AQH_MqttEndpoint_GetClientId(const GWEN_MSG_ENDPOINT *ep) -{ - if (ep) { - AQH_ENDPOINT_MQTT *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep); - if (xep) { - return xep->clientId; - } - } - return NULL; -} - - - -void AQH_MqttEndpoint_SetClientId(GWEN_MSG_ENDPOINT *ep, const char *s) -{ - if (ep) { - AQH_ENDPOINT_MQTT *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep); - if (xep) { - free(xep->clientId); - xep->clientId=s?strdup(s):NULL; - } - } -} - - - -uint16_t AQH_MqttEndpoint_GetNextPacketId(const GWEN_MSG_ENDPOINT *ep) -{ - if (ep) { - AQH_ENDPOINT_MQTT *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep); - if (xep) { - return ++(xep->lastPacketId); - } - } - return 0; -} - - - -uint16_t AQH_MqttEndpoint_GetKeepAliveTime(const GWEN_MSG_ENDPOINT *ep) -{ - if (ep) { - AQH_ENDPOINT_MQTT *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep); - if (xep) { - return xep->keepAliveTime; - } - } - return 0; -} - - - -void AQH_MqttEndpoint_SetKeepAliveTime(GWEN_MSG_ENDPOINT *ep, uint16_t i) -{ - if (ep) { - AQH_ENDPOINT_MQTT *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_ENDPOINT_MQTT, ep); - if (xep) { - xep->keepAliveTime=i; - } - } -} - - - -int _getBytesNeededForMessage(GWEN_UNUSED GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg) -{ - uint32_t bytesInMsg; - - bytesInMsg=GWEN_Msg_GetBytesInBuffer(msg); - if (bytesInMsg<2) { - DBG_DEBUG(AQH_LOGDOMAIN, "Header not yet complete"); - return (int) (2-bytesInMsg); - } - if (!(GWEN_Msg_GetFlags(msg) & GWEN_MSG_FLAGS_PAYLOADINFO_SET)) - _calcAndSetPayloadSizeAndOffset(msg); - - if (GWEN_Msg_GetFlags(msg) & GWEN_MSG_FLAGS_PAYLOADINFO_SET) { - uint32_t msgLength; - - msgLength=GWEN_Msg_GetParsedPayloadOffset(msg)+GWEN_Msg_GetParsedPayloadSize(msg); - return (int)(msgLength-bytesInMsg); - } - else { - DBG_DEBUG(AQH_LOGDOMAIN, "Size field not complete, requesting another byte"); - return 1; - } -} - - - -int _calcAndSetPayloadSizeAndOffset(GWEN_MSG *msg) -{ - int remainingBytesInBuffer; - uint32_t mqttRemainingLength=0; - - remainingBytesInBuffer=GWEN_Msg_GetBytesInBuffer(msg); - if (remainingBytesInBuffer>1) { - const uint8_t *ptr; - int idx; - int shift=0; - - ptr=GWEN_Msg_GetConstBuffer(msg); - idx=1; - remainingBytesInBuffer--; - while(remainingBytesInBuffer) { - uint8_t len; - - len=ptr[idx]; - mqttRemainingLength+=(len & 0x7f)<keepAliveTime, xep->clientId, NULL, NULL); - } - } - return NULL; -} - - - diff --git a/aqhome/mqtt/endpoint_mqtt.h b/aqhome/mqtt/endpoint_mqtt.h deleted file mode 100644 index 546baf3..0000000 --- a/aqhome/mqtt/endpoint_mqtt.h +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** - * This file is part of the project Gwenhywfar. - * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_ENDPOINT_MQTT_H -#define AQH_ENDPOINT_MQTT_H - - -#include - -#include - - -#ifdef __cplusplus -extern "C" { -#endif - - -/** - * Extends the given endpoint to support MQTT messages. It expects the function GWEN_MsgIoEndpoint_Extend() to have been called - * beforehand. - */ -AQHOME_API void AQH_MqttEndpoint_Extend(GWEN_MSG_ENDPOINT *ep); - - -AQHOME_API const char *AQH_MqttEndpoint_GetClientId(const GWEN_MSG_ENDPOINT *ep); -AQHOME_API void AQH_MqttEndpoint_SetClientId(GWEN_MSG_ENDPOINT *ep, const char *s); - -AQHOME_API uint16_t AQH_MqttEndpoint_GetNextPacketId(const GWEN_MSG_ENDPOINT *ep); - -AQHOME_API uint16_t AQH_MqttEndpoint_GetKeepAliveTime(const GWEN_MSG_ENDPOINT *ep); -AQHOME_API void AQH_MqttEndpoint_SetKeepAliveTime(GWEN_MSG_ENDPOINT *ep, uint16_t i); - - - -AQHOME_API GWEN_MSG *AQH_MqttEndpoint_CreateMsgConnect(GWEN_MSG_ENDPOINT *ep); - - - -#ifdef __cplusplus -} -#endif - - -#endif - - diff --git a/aqhome/mqtt/endpoint_mqtt_p.h b/aqhome/mqtt/endpoint_mqtt_p.h deleted file mode 100644 index 4d9df9e..0000000 --- a/aqhome/mqtt/endpoint_mqtt_p.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_ENDPOINT_MQTT_P_H -#define AQH_ENDPOINT_MQTT_P_H - - -#include "aqhome/mqtt/endpoint_mqtt.h" - - - -typedef struct AQH_ENDPOINT_MQTT AQH_ENDPOINT_MQTT; -struct AQH_ENDPOINT_MQTT { - char *clientId; - uint16_t lastPacketId; - uint16_t keepAliveTime; -}; - - - - - -#endif - diff --git a/aqhome/mqtt/endpoint_mqttc.c b/aqhome/mqtt/endpoint_mqttc.c deleted file mode 100644 index 32f882d..0000000 --- a/aqhome/mqtt/endpoint_mqttc.c +++ /dev/null @@ -1,292 +0,0 @@ -/**************************************************************************** - * This file is part of the project Gwenhywfar. - * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/mqtt/endpoint_mqttc.h" - -#include "aqhome/mqtt/endpoint_mqtt.h" -#include "aqhome/mqtt/msg_mqtt_connect.h" -#include "aqhome/mqtt/msg_mqtt_connack.h" -#include "aqhome/mqtt/msg_mqtt_publish.h" -#include "aqhome/mqtt/msg_mqtt_subscribe.h" -#include "aqhome/mqtt/msg_mqtt_suback.h" - -#include -#include -#include -#include -#include - - -#define AQH_ENDPOINT2_MQTT_NAME "mqtt-client" -#define AQH_ENDPOINT2_MQTTC_RECONNECT_TIME 5 -#define AQH_ENDPOINT2_MQTTC_CONNECT_TIMEOUT 10 - -#define AQH_ENDPOINT2_MQTTC_STAGE_NONE 0 -#define AQH_ENDPOINT2_MQTTC_STAGE_CONNREQ 1 -#define AQH_ENDPOINT2_MQTTC_STAGE_SUBREQ 2 -#define AQH_ENDPOINT2_MQTTC_STAGE_UP 10 - - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static int _startConnect(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild); -static void _checkSockets(GWEN_MSG_ENDPOINT *ep, - GWEN_MSG_ENDPOINT *epChild, - GWEN_SOCKETSET *readSet, - GWEN_SOCKETSET *writeSet, - GWEN_SOCKETSET *xSet); -static void _lookForAndHandleConnAck(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild); -static void _lookForAndHandleSubAck(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild); -static int _sendSubscribeMsg(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild, const char *topicFilter); - - - -/* ------------------------------------------------------------------------------------------------ - * implementations - * ------------------------------------------------------------------------------------------------ - */ - - - -GWEN_MSG_ENDPOINT *AQH_MqttClientEndpoint_new(const char *clientId, - const char *host, int port, - const char *name, int groupId) -{ - GWEN_MSG_ENDPOINT *ep; - GWEN_MSG_ENDPOINT *epChild; - - ep=GWEN_MultilayerEndpoint_new(name?name:AQH_ENDPOINT2_MQTT_NAME, groupId); - GWEN_MultilayerEndpoint_SetConnectTimeoutInSeconds(ep, AQH_ENDPOINT2_MQTTC_CONNECT_TIMEOUT); - GWEN_MultilayerEndpoint_SetReconnectTimeInSeconds(ep, AQH_ENDPOINT2_MQTTC_RECONNECT_TIME); - GWEN_MultilayerEndpoint_SetStartConnectFn(ep, _startConnect); - GWEN_MultilayerEndpoint_SetCheckSocketsFn(ep, _checkSockets); - - epChild=GWEN_TcpcEndpoint_new(host, port, NULL, groupId); - GWEN_MsgIoEndpoint_Extend(epChild); - AQH_MqttEndpoint_Extend(epChild); - AQH_MqttEndpoint_SetClientId(epChild, clientId); - GWEN_MsgEndpoint_Tree2_AddChild(ep, epChild); - - return ep; -} - - - -uint16_t AQH_MqttClientEndpoint_GetKeepAliveTime(const GWEN_MSG_ENDPOINT *ep) -{ - if (ep) { - GWEN_MSG_ENDPOINT *epChild; - - epChild=GWEN_MsgEndpoint_Tree2_GetFirstChild(ep); - if (epChild) - return AQH_MqttEndpoint_GetKeepAliveTime(epChild); - } - return 0; -} - - - -void AQH_MqttClientEndpoint_SetKeepAliveTime(GWEN_MSG_ENDPOINT *ep, uint16_t i) -{ - if (ep) { - GWEN_MSG_ENDPOINT *epChild; - - epChild=GWEN_MsgEndpoint_Tree2_GetFirstChild(ep); - if (epChild) { - AQH_MqttEndpoint_SetKeepAliveTime(epChild, i); - } - } -} - - - -uint16_t AQH_MqttClientEndpoint_GetNextPacketId(const GWEN_MSG_ENDPOINT *ep) -{ - if (ep) { - GWEN_MSG_ENDPOINT *epChild; - - epChild=GWEN_MsgEndpoint_Tree2_GetFirstChild(ep); - if (epChild) { - return AQH_MqttEndpoint_GetNextPacketId(epChild); - } - } - return 0; -} - - - -void _checkSockets(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild, - GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet) -{ - int stage; - - GWEN_MsgEndpoint_CheckSockets(epChild, readSet, writeSet, xSet); /* let base layer work */ - - stage=GWEN_MultilayerEndpoint_GetStage(ep); - switch(stage) { - case AQH_ENDPOINT2_MQTTC_STAGE_CONNREQ: _lookForAndHandleConnAck(ep, epChild); break; - case AQH_ENDPOINT2_MQTTC_STAGE_SUBREQ: _lookForAndHandleSubAck(ep, epChild); break; - default: break; - } -} - - - -int _startConnect(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild) -{ - if (epChild) { - int rv; - GWEN_MSG *msg; - - rv=GWEN_TcpcEndpoint_StartConnect(epChild); - if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) { - DBG_INFO(AQH_LOGDOMAIN, "Error starting to connect child layer (%d)", rv); - return rv; - } - msg=AQH_MqttEndpoint_CreateMsgConnect(epChild); - if (msg) { - GWEN_MsgEndpoint_AddSendMessage(epChild, msg); - GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTING); - GWEN_MultilayerEndpoint_SetStage(ep, AQH_ENDPOINT2_MQTTC_STAGE_CONNREQ); - return rv; /* result from GWEN_TcpcEndpoint_StartConnect() above */ - } - } - return GWEN_ERROR_GENERIC; -} - - - - -void _lookForAndHandleConnAck(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild) -{ - GWEN_MSG *msg; - - msg=GWEN_MsgEndpoint_GetFirstReceivedMessage(epChild); - while(msg) { - GWEN_MSG *msgNext; - uint8_t msgType; - - msgNext=GWEN_Msg_List_Next(msg); - msgType=AQH_MqttMsg_GetMsgTypeAndFlags(msg) & 0xf0; - - if (msgType==AQH_MQTTMSG_MSGTYPE_CONNACK) { - int code; - - GWEN_Msg_List_Del(msg); /* remove from list */ - code=AQH_ConnAckMqttMsg_GetResultCode(msg); - if (code==AQH_MQTTMSG_CONNACK_RESULT_ACCEPTED) { - DBG_INFO(AQH_LOGDOMAIN, "Positive CONNACK response"); - if (GWEN_MsgEndpoint_GetFlags(ep) & AQH_ENDPOINT2_MQTTCLIENT_FLAGS_SUBSCRIBEALL) { - int rv; - - DBG_INFO(AQH_LOGDOMAIN, "Sending subscribe message"); - rv=_sendSubscribeMsg(ep, epChild, "#"); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error sending SUBSCRIBE request (%d)", rv); - GWEN_MultilayerEndpoint_SetStage(ep, AQH_ENDPOINT2_MQTTC_STAGE_NONE); - GWEN_MsgEndpoint_Disconnect(epChild); - GWEN_MsgEndpoint_Disconnect(ep); - } - else { - GWEN_MultilayerEndpoint_SetStage(ep, AQH_ENDPOINT2_MQTTC_STAGE_SUBREQ); - } - } - else { - DBG_INFO(AQH_LOGDOMAIN, "Connected (no auto-subscription requested)"); - GWEN_MultilayerEndpoint_SetStage(ep, AQH_ENDPOINT2_MQTTC_STAGE_UP); - GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTED); - } - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "Negative CONNACK response (%d)", code); - GWEN_MultilayerEndpoint_SetStage(ep, AQH_ENDPOINT2_MQTTC_STAGE_NONE); - GWEN_MsgEndpoint_Disconnect(epChild); - GWEN_MsgEndpoint_Disconnect(ep); - } - GWEN_Msg_free(msg); - break; - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "Ignoring response (%d)", msgType); - } - msg=msgNext; - } /* while */ -} - - - -void _lookForAndHandleSubAck(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild) -{ - GWEN_MSG *msg; - - msg=GWEN_MsgEndpoint_GetFirstReceivedMessage(epChild); - while(msg) { - GWEN_MSG *msgNext; - uint8_t msgType; - - msgNext=GWEN_Msg_List_Next(msg); - msgType=AQH_MqttMsg_GetMsgTypeAndFlags(msg) & 0xf0; - - if (msgType==AQH_MQTTMSG_MSGTYPE_SUBACK) { - int code; - - GWEN_Msg_List_Del(msg); /* remove from list */ - code=AQH_SubAckMqttMsg_GetResultCode(msg); - if (code!=128) { - DBG_INFO(AQH_LOGDOMAIN, "Positive SUBACK response, connected (%d, %02x)", code, code); - GWEN_MultilayerEndpoint_SetStage(ep, AQH_ENDPOINT2_MQTTC_STAGE_UP); - GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTED); - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "Negative SUBACK response (%d)", code); - GWEN_MultilayerEndpoint_SetStage(ep, AQH_ENDPOINT2_MQTTC_STAGE_NONE); - GWEN_MsgEndpoint_Disconnect(epChild); - GWEN_MsgEndpoint_Disconnect(ep); - } - GWEN_Msg_free(msg); - break; - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "Ignoring response (%d)", msgType); - } - msg=msgNext; - } /* while */ -} - - - -int _sendSubscribeMsg(GWEN_MSG_ENDPOINT *ep, GWEN_MSG_ENDPOINT *epChild, const char *topicFilter) -{ - uint16_t pckId; - GWEN_MSG *msgOut; - - DBG_INFO(AQH_LOGDOMAIN, "Sending SUBSCRIBE %s", topicFilter); - pckId=AQH_MqttClientEndpoint_GetNextPacketId(ep); - msgOut=GWEN_SubscribeMqttMsg_new(AQH_MQTTMSG_MSGTYPE_SUBSCRIBE, pckId, topicFilter, 0); - if (msgOut==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Error creating message"); - return GWEN_ERROR_INTERNAL; - } - GWEN_MsgEndpoint_AddSendMessage(epChild, msgOut); - - return 0; -} - - - - - diff --git a/aqhome/mqtt/endpoint_mqttc.h b/aqhome/mqtt/endpoint_mqttc.h deleted file mode 100644 index 7064178..0000000 --- a/aqhome/mqtt/endpoint_mqttc.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - * This file is part of the project Gwenhywfar. - * Gwenhywfar (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_ENDPOINT2_MQTTC_H -#define AQH_ENDPOINT2_MQTTC_H - - -#include - -#include - - -#ifdef __cplusplus -extern "C" { -#endif - -#define AQH_ENDPOINT2_MQTTCLIENT_FLAGS_SUBSCRIBEALL 0x0001 - - -/** - */ -AQHOME_API GWEN_MSG_ENDPOINT *AQH_MqttClientEndpoint_new(const char *clientId, - const char *host, int port, - const char *name, int groupId); - -AQHOME_API uint16_t AQH_MqttClientEndpoint_GetKeepAliveTime(const GWEN_MSG_ENDPOINT *ep); -AQHOME_API void AQH_MqttClientEndpoint_SetKeepAliveTime(GWEN_MSG_ENDPOINT *ep, uint16_t i); - -AQHOME_API uint16_t AQH_MqttClientEndpoint_GetNextPacketId(const GWEN_MSG_ENDPOINT *ep); - -AQHOME_API int AQH_MqttClientEndpoint_StartConnect(GWEN_MSG_ENDPOINT *ep); - - - -#ifdef __cplusplus -} -#endif - - -#endif - - diff --git a/aqhome/mqtt/msg_mqtt.c b/aqhome/mqtt/msg_mqtt.c deleted file mode 100644 index 7926f2b..0000000 --- a/aqhome/mqtt/msg_mqtt.c +++ /dev/null @@ -1,264 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include "aqhome/mqtt/msg_mqtt.h" - -#include -#include - -#include - -// maximum remaining length: fff ffff - - -static void _flagsToDb(uint8_t flags, GWEN_DB_NODE *dbDest, const char *varNameFlags, const char *varNameQos); - - - - -GWEN_MSG *GWEN_MqttMsg_new(uint8_t typeAndFlags, uint32_t payloadLen, const uint8_t *payload) -{ - if (payloadLen>0xfffffffu) { - DBG_ERROR(AQH_LOGDOMAIN, "Too many bytes in payload, can't encode into MQTT message"); - return NULL; - } - else { - GWEN_MSG *msg; - uint8_t *ptr; - uint32_t i; - uint32_t len; - - msg=GWEN_Msg_new(payloadLen+1+4); - ptr=GWEN_Msg_GetBuffer(msg); - *(ptr++)=typeAndFlags; - len=payloadLen; - i=0; - - do { - uint8_t b; - - b=len & 0x7f; - len>>=7; - if (len) - b|=0x80; - *(ptr++)=b; - } while(len && i<4); - - if (payloadLen) { - GWEN_Msg_SetParsedPayloadSize(msg, payloadLen); - GWEN_Msg_SetParsedPayloadOffset(msg, ptr-GWEN_Msg_GetBuffer(msg)); - memmove(ptr, payload, payloadLen); - ptr+=payloadLen; - } - i=ptr-GWEN_Msg_GetBuffer(msg); - GWEN_Msg_SetBytesInBuffer(msg, i); - - return msg; - } -} - - - -int AQH_MqttMsg_IsMsgComplete(const GWEN_MSG *msg) -{ - if (msg && (GWEN_Msg_GetFlags(msg) & GWEN_MSG_FLAGS_PAYLOADINFO_SET)) { - uint32_t msgLength; - - msgLength=GWEN_Msg_GetParsedPayloadOffset(msg)+GWEN_Msg_GetParsedPayloadSize(msg); - if (GWEN_Msg_GetBytesInBuffer(msg)>=msgLength) - return 1; - } - return 0; -} - - - -void AQH_MqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - GWEN_Text_DumpString2Buffer((const char*) GWEN_Msg_GetConstBuffer(msg), - GWEN_Msg_GetBytesInBuffer(msg), - dbuf, - 2); -} - - - -int AQH_MqttMsg_toDb(const GWEN_MSG *msg, GWEN_DB_NODE *dbDest) -{ - const uint8_t *msgPtr; - uint32_t msgLen; - uint8_t b; - const char *s; - - msgPtr=GWEN_Msg_GetConstBuffer(msg); - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - if (msgLen<2) { - DBG_ERROR(AQH_LOGDOMAIN, "Message too small (%d bytes)", msgLen); - return GWEN_ERROR_BAD_DATA; - } - b=msgPtr[0]; - s=AQH_MqttMsg_MsgTypeToString(b); - GWEN_DB_SetCharValue(dbDest, GWEN_DB_FLAGS_OVERWRITE_VARS, "cmdString", s); - GWEN_DB_SetIntValue(dbDest, GWEN_DB_FLAGS_OVERWRITE_VARS, "cmdAndFlags", b); - - _flagsToDb(b & 0x0f, dbDest, "flags", "qos"); - return 0; -} - - - -const char *AQH_MqttMsg_MsgTypeToString(uint8_t t) -{ - switch(t & 0xf0) { - case (AQH_MQTTMSG_MSGTYPE_CONNECT & 0xf0): return "CONNECT"; - case (AQH_MQTTMSG_MSGTYPE_CONNACK & 0xf0): return "CONACK"; - case (AQH_MQTTMSG_MSGTYPE_PUBLISH & 0xf0): return "PUBLISH"; - case (AQH_MQTTMSG_MSGTYPE_PUBACK & 0xf0): return "PUBACK"; - case (AQH_MQTTMSG_MSGTYPE_PUBREC & 0xf0): return "PUBREC"; - case (AQH_MQTTMSG_MSGTYPE_PUBREL & 0xf0): return "PUBREL"; - case (AQH_MQTTMSG_MSGTYPE_PUBCOMP & 0xf0): return "PUBCOMP"; - case (AQH_MQTTMSG_MSGTYPE_SUBSCRIBE & 0xf0): return "SUBSCRIBE"; - case (AQH_MQTTMSG_MSGTYPE_SUBACK & 0xf0): return "SUBACK"; - case (AQH_MQTTMSG_MSGTYPE_UNSUBSCRIBE & 0xf0): return "UNSUBSCRIBE"; - case (AQH_MQTTMSG_MSGTYPE_UNSUBACK & 0xf0): return "UNSUBACK"; - case (AQH_MQTTMSG_MSGTYPE_PINGREQ & 0xf0): return "PINGREQ"; - case (AQH_MQTTMSG_MSGTYPE_PINGRESP & 0xf0): return "PINGRESP"; - case (AQH_MQTTMSG_MSGTYPE_DISCONNECT & 0xf0): return "DISCONNECT"; - default: return "(unknown)"; - } -} - - - -uint8_t AQH_MqttMsg_GetMsgTypeAndFlags(const GWEN_MSG *msg) -{ - uint32_t msgLen; - - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - if (msgLen>0) { - const uint8_t *msgPtr; - - msgPtr=GWEN_Msg_GetConstBuffer(msg); - return msgPtr[0]; - } - - return 0; -} - - - - - - -void _flagsToDb(uint8_t flags, GWEN_DB_NODE *dbDest, const char *varNameFlags, const char *varNameQos) -{ - GWEN_DB_DeleteVar(dbDest, varNameFlags); - GWEN_DB_DeleteVar(dbDest, varNameQos); - if (flags & AQH_MQTTMSG_FLAGS_DUP) - GWEN_DB_SetCharValue(dbDest, GWEN_DB_FLAGS_DEFAULT, varNameFlags, "dup"); - if (flags & AQH_MQTTMSG_FLAGS_RETAIN) - GWEN_DB_SetCharValue(dbDest, GWEN_DB_FLAGS_DEFAULT, varNameFlags, "retain"); - - GWEN_DB_SetIntValue(dbDest, GWEN_DB_FLAGS_DEFAULT, varNameQos, (flags>>1) & 0x3); - -} - - - -/* helper functions */ - - -void AQH_MqttMsg_AppendStringWithLen(GWEN_BUFFER *buf, const char *s) -{ - unsigned int len; - - len=strlen(s); - GWEN_Buffer_AppendByte(buf, (len>>8) & 0xff); - GWEN_Buffer_AppendByte(buf, len & 0xff); - if (s && *s) - GWEN_Buffer_AppendString(buf, s); -} - - - -int AQH_MqttMsg_DumpString(const uint8_t *ptr, uint32_t len, GWEN_BUFFER *buf) -{ - if (len>1) { - int slen; - - slen=(ptr[0]<<8)+ptr[1]; - if (slen) { - if (slen>(len-2)) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid string length (%lu, remaining %lu)", - (unsigned long int) slen, (unsigned long int) len); - return GWEN_ERROR_BAD_DATA; - } - GWEN_Buffer_AppendBytes(buf, (const char*) ptr+2, slen); - } - return slen+2; - } - return GWEN_ERROR_BAD_DATA; -} - - - -char *AQH_MqttMsg_ExtractStringAt(const uint8_t *ptr, uint32_t len) -{ - if (len>1) { - int slen; - - slen=(ptr[0]<<8)+ptr[1]; - if (slen) { - char *result; - - if (slen>(len-2)) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid string length (%lu, remaining %lu)", - (unsigned long int) slen, (unsigned long int) len); - return NULL; - } - - result=(char*) malloc(slen+1); - if (result==NULL) { - DBG_ERROR(AQH_LOGDOMAIN, "Error on malloc"); - return NULL; - } - memmove(result, ptr+2, slen); - result[slen]=0; - return result; - } - } - return NULL; -} - - - -int AQH_MqttMsg_SkipStringAt(const uint8_t *ptr, uint32_t len) -{ - if (len>1) { - int slen; - - slen=(ptr[0]<<8)+ptr[1]; - if (slen) { - if (slen>(len-2)) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid string length (%lu, remaining %lu)", - (unsigned long int) slen, (unsigned long int) len); - return GWEN_ERROR_BAD_DATA; - } - } - return slen+2; - } - return GWEN_ERROR_BAD_DATA; -} - - - diff --git a/aqhome/mqtt/msg_mqtt.h b/aqhome/mqtt/msg_mqtt.h deleted file mode 100644 index 45ed922..0000000 --- a/aqhome/mqtt/msg_mqtt.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_MQTT_H -#define AQH_MSG_MQTT_H - - -#include - -#include -#include -#include - - - -#define AQH_MQTTMSG_OFFS_CONTROL 0 -#define AQH_MQTTMSG_OFFS_REMAINING_LENGTH 1 - - -/* from https://docs.solace.com/API/MQTT-311-Prtl-Conformance-Spec/MQTT%20Control%20Packet%20format.htm - */ -#define AQH_MQTTMSG_MSGTYPE_CONNECT 0x10u -#define AQH_MQTTMSG_MSGTYPE_CONNACK 0x20u -#define AQH_MQTTMSG_MSGTYPE_PUBLISH 0x30u -#define AQH_MQTTMSG_MSGTYPE_PUBACK 0x40u -#define AQH_MQTTMSG_MSGTYPE_PUBREC 0x50u /* assured delivery part 1 */ -#define AQH_MQTTMSG_MSGTYPE_PUBREL 0x62u /* assured delivery part 2 */ -#define AQH_MQTTMSG_MSGTYPE_PUBCOMP 0x70u /* assured delivery part 3 */ -#define AQH_MQTTMSG_MSGTYPE_SUBSCRIBE 0x82u -#define AQH_MQTTMSG_MSGTYPE_SUBACK 0x90u -#define AQH_MQTTMSG_MSGTYPE_UNSUBSCRIBE 0xa2u -#define AQH_MQTTMSG_MSGTYPE_UNSUBACK 0xb0u -#define AQH_MQTTMSG_MSGTYPE_PINGREQ 0xc0u -#define AQH_MQTTMSG_MSGTYPE_PINGRESP 0xd0u -#define AQH_MQTTMSG_MSGTYPE_DISCONNECT 0xe0u - - -#define AQH_MQTTMSG_FLAGS_DUP 0x08u -#define AQH_MQTTMSG_FLAGS_QOS2 0x04u -#define AQH_MQTTMSG_FLAGS_QOS1 0x02u -#define AQH_MQTTMSG_FLAGS_RETAIN 0x01u - - - -AQHOME_API GWEN_MSG *GWEN_MqttMsg_new(uint8_t typeAndFlags, uint32_t payloadLen, const uint8_t *payload); - -AQHOME_API int AQH_MqttMsg_IsMsgComplete(const GWEN_MSG *msg); -AQHOME_API void AQH_MqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - -AQHOME_API const char *AQH_MqttMsg_MsgTypeToString(uint8_t t); - -AQHOME_API uint8_t AQH_MqttMsg_GetMsgTypeAndFlags(const GWEN_MSG *msg); - - -/* helper functions */ -AQHOME_API void AQH_MqttMsg_AppendStringWithLen(GWEN_BUFFER *buf, const char *s); -AQHOME_API int AQH_MqttMsg_DumpString(const uint8_t *ptr, uint32_t len, GWEN_BUFFER *buf); - -AQHOME_API int AQH_MqttMsg_SkipStringAt(const uint8_t *ptr, uint32_t len); -AQHOME_API char *AQH_MqttMsg_ExtractStringAt(const uint8_t *ptr, uint32_t len); - - - -#endif diff --git a/aqhome/mqtt/msg_mqtt_connack.c b/aqhome/mqtt/msg_mqtt_connack.c deleted file mode 100644 index ea81bb4..0000000 --- a/aqhome/mqtt/msg_mqtt_connack.c +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include "aqhome/mqtt/msg_mqtt_connack.h" - -#include - - - -GWEN_MSG *GWEN_ConnAckMqttMsg_new(uint8_t flags, uint8_t result) -{ - uint8_t data[2]; - GWEN_MSG *msg; - - data[0]=flags; - data[1]=result; - - msg=GWEN_MqttMsg_new(AQH_MQTTMSG_MSGTYPE_CONNACK, 2, data); - if (msg==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "here"); - return NULL; - } - return msg; -} - - - -void AQH_ConnAckMqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - const uint8_t *msgPtr; - uint32_t msgLen; - - msgPtr=GWEN_Msg_GetConstBuffer(msg); - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - - if (msgLen>1) { - const uint8_t *payloadPtr; - uint32_t payloadLen; - - GWEN_Buffer_AppendArgs(dbuf, "%s %s", AQH_MqttMsg_MsgTypeToString(msgPtr[0] & 0xf0), sText); - payloadLen=GWEN_Msg_GetParsedPayloadSize(msg); - payloadPtr=msgPtr+GWEN_Msg_GetParsedPayloadOffset(msg); - if (payloadLen>=2) - GWEN_Buffer_AppendArgs(dbuf, "(flags=%02x, result=%d)", payloadPtr[0], payloadPtr[1]); - } -} - - - -int AQH_ConnAckMqttMsg_GetResultFlags(const GWEN_MSG *msg) -{ - const uint8_t *msgPtr; - uint32_t msgLen; - - msgPtr=GWEN_Msg_GetConstBuffer(msg); - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - - if (msgLen>1) { - uint32_t payloadLen; - const uint8_t *payloadPtr; - - payloadLen=GWEN_Msg_GetParsedPayloadSize(msg); - payloadPtr=msgPtr+GWEN_Msg_GetParsedPayloadOffset(msg); - - if (payloadLen) - return (int) (payloadPtr[0]); - } - - return GWEN_ERROR_GENERIC; -} - - - -int AQH_ConnAckMqttMsg_GetResultCode(const GWEN_MSG *msg) -{ - const uint8_t *msgPtr; - uint32_t msgLen; - - msgPtr=GWEN_Msg_GetConstBuffer(msg); - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - - if (msgLen>1) { - uint32_t payloadLen; - const uint8_t *payloadPtr; - - payloadLen=GWEN_Msg_GetParsedPayloadSize(msg); - payloadPtr=msgPtr+GWEN_Msg_GetParsedPayloadOffset(msg); - - if (payloadLen>1) - return (int) (payloadPtr[1]); - } - - return GWEN_ERROR_GENERIC; -} - - - - - - diff --git a/aqhome/mqtt/msg_mqtt_connack.h b/aqhome/mqtt/msg_mqtt_connack.h deleted file mode 100644 index 913a7da..0000000 --- a/aqhome/mqtt/msg_mqtt_connack.h +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_MQTT_CONNACK_H -#define AQH_MSG_MQTT_CONNACK_H - - -#include -#include - -#include -#include - - - -#define AQH_MQTTMSG_CONNACK_FLAGS_HAVE_SESSION 0x01u - -#define AQH_MQTTMSG_CONNACK_RESULT_ACCEPTED 0x00u -#define AQH_MQTTMSG_CONNACK_RESULT_BAD_PROTO 0x01u -#define AQH_MQTTMSG_CONNACK_RESULT_BAD_CLIENTID 0x02u -#define AQH_MQTTMSG_CONNACK_RESULT_UNAVAILABLE 0x03u -#define AQH_MQTTMSG_CONNACK_RESULT_BAD_CREDENTIALS 0x04u -#define AQH_MQTTMSG_CONNACK_RESULT_UNAUTHORIZED 0x05u - - - - - -AQHOME_API GWEN_MSG *GWEN_ConnAckMqttMsg_new(uint8_t flags, uint8_t result); - -AQHOME_API int AQH_ConnAckMqttMsg_GetResultFlags(const GWEN_MSG *msg); -AQHOME_API int AQH_ConnAckMqttMsg_GetResultCode(const GWEN_MSG *msg); - -AQHOME_API void AQH_ConnAckMqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - - -#endif diff --git a/aqhome/mqtt/msg_mqtt_connect.c b/aqhome/mqtt/msg_mqtt_connect.c deleted file mode 100644 index 09b3505..0000000 --- a/aqhome/mqtt/msg_mqtt_connect.c +++ /dev/null @@ -1,223 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include "aqhome/mqtt/msg_mqtt_connect.h" - -#include - - - -static int _dumpPayload(const uint8_t *payloadPtr, uint32_t payloadLen, GWEN_BUFFER *dbuf); -static void _appendStringWithLen(GWEN_BUFFER *buf, const char *s); -static int _dumpString(const uint8_t *ptr, uint32_t len, GWEN_BUFFER *buf); - - - - - -GWEN_MSG *GWEN_ConnectMqttMsg_new(const char *protoName, - uint8_t protoLevel, - uint8_t connectFlags, - uint16_t keepAliveTime, - const char *clientId, - const char *userName, - const char *password) -{ - GWEN_MSG *msg; - GWEN_BUFFER *buf; - - buf=GWEN_Buffer_new(0, 64, 0, 1); - _appendStringWithLen(buf, protoName?protoName:"MQTT"); - GWEN_Buffer_AppendByte(buf, protoLevel?protoLevel:4); - GWEN_Buffer_AppendByte(buf, connectFlags); - GWEN_Buffer_AppendByte(buf, (keepAliveTime>>8) & 0xff); - GWEN_Buffer_AppendByte(buf, keepAliveTime & 0xff); - - _appendStringWithLen(buf, clientId); - /* here could be inserted: will topic, will message */ - if (connectFlags & AQH_MQTTMSG_CONNECT_FLAGS_USERNAME) - _appendStringWithLen(buf, userName); - if (connectFlags & AQH_MQTTMSG_CONNECT_FLAGS_PASSWD) - _appendStringWithLen(buf, password); - - msg=GWEN_MqttMsg_new(AQH_MQTTMSG_MSGTYPE_CONNECT, GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - if (msg==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "here"); - return NULL; - } - - return msg; -} - - - -void AQH_ConnectMqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - const uint8_t *msgPtr; - uint32_t msgLen; - - msgPtr=GWEN_Msg_GetConstBuffer(msg); - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - - if (msgLen>1) { - uint32_t payloadLen; - const uint8_t *payloadPtr; - int rv; - - payloadLen=GWEN_Msg_GetParsedPayloadSize(msg); - payloadPtr=msgPtr+GWEN_Msg_GetParsedPayloadOffset(msg); - - GWEN_Buffer_AppendArgs(dbuf, "%s %s", AQH_MqttMsg_MsgTypeToString(msgPtr[0] & 0xf0), sText); - - GWEN_Buffer_AppendString(dbuf, "("); - rv=_dumpPayload(payloadPtr, payloadLen, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - } - else { - GWEN_Buffer_AppendString(dbuf, ")"); - } - } -} - - - -int _dumpPayload(const uint8_t *payloadPtr, uint32_t payloadLen, GWEN_BUFFER *dbuf) -{ - int rv; - uint8_t connectFlags; - uint16_t keepAliveTime; - - GWEN_Buffer_AppendString(dbuf, "proto: "); - rv=_dumpString(payloadPtr, payloadLen, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - payloadLen-=rv; - payloadPtr+=rv; - if (payloadLen<4) { /* expect at least proto ver(1), flags(1) and keepAlive(2) bytes */ - DBG_ERROR(AQH_LOGDOMAIN, "Msg too small"); - return GWEN_ERROR_BAD_DATA; - } - else { - GWEN_Buffer_AppendArgs(dbuf, " proto ver: %d", payloadPtr[0]); - payloadLen--; - payloadPtr++; - - connectFlags=payloadPtr[0]; - GWEN_Buffer_AppendArgs(dbuf, " flags: %02x", connectFlags); - payloadLen--; - payloadPtr++; - - keepAliveTime=(payloadPtr[0]<<8)+payloadPtr[1]; - GWEN_Buffer_AppendArgs(dbuf, " keep alive: %d", keepAliveTime); - payloadLen-=2; - payloadPtr+=2; - } - - GWEN_Buffer_AppendString(dbuf, " client id: "); - rv=_dumpString(payloadPtr, payloadLen, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - payloadLen-=rv; - payloadPtr+=rv; - - if (connectFlags & AQH_MQTTMSG_CONNECT_FLAGS_WILL_FLAG) { - GWEN_Buffer_AppendString(dbuf, " will topic: "); - rv=_dumpString(payloadPtr, payloadLen, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - payloadLen-=rv; - payloadPtr+=rv; - - GWEN_Buffer_AppendString(dbuf, " will msg: "); - rv=_dumpString(payloadPtr, payloadLen, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - payloadLen-=rv; - payloadPtr+=rv; - } - - if (connectFlags & AQH_MQTTMSG_CONNECT_FLAGS_USERNAME) { - GWEN_Buffer_AppendString(dbuf, " username: "); - rv=_dumpString(payloadPtr, payloadLen, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - payloadLen-=rv; - payloadPtr+=rv; - } - if (connectFlags & AQH_MQTTMSG_CONNECT_FLAGS_PASSWD) { - GWEN_Buffer_AppendString(dbuf, " password: "); - rv=_dumpString(payloadPtr, payloadLen, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - payloadLen-=rv; - payloadPtr+=rv; - } - - return 0; -} - - - -void _appendStringWithLen(GWEN_BUFFER *buf, const char *s) -{ - unsigned int len; - - len=strlen(s); - GWEN_Buffer_AppendByte(buf, (len>>8) & 0xff); - GWEN_Buffer_AppendByte(buf, len & 0xff); - if (s && *s) - GWEN_Buffer_AppendString(buf, s); -} - - - -int _dumpString(const uint8_t *ptr, uint32_t len, GWEN_BUFFER *buf) -{ - if (len>1) { - int slen; - - slen=(ptr[0]<<8)+ptr[1]; - if (slen) { - if (slen>(len-2)) { - DBG_ERROR(AQH_LOGDOMAIN, "Invalid string length (%lu, remaining %lu)", - (unsigned long int) slen, (unsigned long int) len); - return GWEN_ERROR_BAD_DATA; - } - GWEN_Buffer_AppendBytes(buf, (const char*) ptr+2, slen); - } - return slen+2; - } - return GWEN_ERROR_BAD_DATA; -} - - - - - - - - diff --git a/aqhome/mqtt/msg_mqtt_connect.h b/aqhome/mqtt/msg_mqtt_connect.h deleted file mode 100644 index dd56f7f..0000000 --- a/aqhome/mqtt/msg_mqtt_connect.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_MQTT_CONNECT_H -#define AQH_MSG_MQTT_CONNECT_H - - -#include -#include - -#include -#include - - - -#define AQH_MQTTMSG_CONNECT_FLAGS_USERNAME 0x80u -#define AQH_MQTTMSG_CONNECT_FLAGS_PASSWD 0x40u -#define AQH_MQTTMSG_CONNECT_FLAGS_WILL_RETAIN 0x20u -#define AQH_MQTTMSG_CONNECT_FLAGS_WILL_QOS2 0x10u -#define AQH_MQTTMSG_CONNECT_FLAGS_WILL_QOS1 0x08u -#define AQH_MQTTMSG_CONNECT_FLAGS_WILL_FLAG 0x04u -#define AQH_MQTTMSG_CONNECT_FLAGS_CLEAN_SESSION 0x01u - - - - -/** - * order in payload: - * - client id - * - will topic - * - will message - * - user name - * - password - */ -AQHOME_API GWEN_MSG *GWEN_ConnectMqttMsg_new(const char *protoName, /* "MQTT" */ - uint8_t protoLevel, /* 0x04 for MQTT 3.1.1 */ - uint8_t connectFlags, - uint16_t keepAliveTime, - const char *clientId, - const char *userName, - const char *password); - -AQHOME_API void AQH_ConnectMqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - - -#endif diff --git a/aqhome/mqtt/msg_mqtt_publish.c b/aqhome/mqtt/msg_mqtt_publish.c deleted file mode 100644 index 05804bd..0000000 --- a/aqhome/mqtt/msg_mqtt_publish.c +++ /dev/null @@ -1,213 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include "aqhome/mqtt/msg_mqtt_publish.h" - -#include - - - -static int _dumpPayload(uint8_t flags, const uint8_t *payloadPtr, uint32_t payloadLen, GWEN_BUFFER *dbuf); - - - - - -GWEN_MSG *AQH_PublishMqttMsg_new(uint8_t flags, uint16_t packetId, const char *sTopic, const uint8_t *messagePtr, uint32_t messageLen) -{ - if (sTopic && *sTopic) { - GWEN_MSG *msg; - GWEN_BUFFER *buf; - - buf=GWEN_Buffer_new(0, 64, 0, 1); - AQH_MqttMsg_AppendStringWithLen(buf, sTopic); - if (flags & (AQH_MQTTMSG_FLAGS_QOS2 | AQH_MQTTMSG_FLAGS_QOS1)) { - GWEN_Buffer_AppendByte(buf, (packetId>>8) & 0xff); - GWEN_Buffer_AppendByte(buf, packetId & 0xff); - } - if (messagePtr && messageLen) - GWEN_Buffer_AppendBytes(buf, (const char*) messagePtr, messageLen); - - msg=GWEN_MqttMsg_new(AQH_MQTTMSG_MSGTYPE_PUBLISH | flags, GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - if (msg==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "here"); - return NULL; - } - return msg; - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "Missing topic"); - return NULL; - } -} - - - -void AQH_PublishMqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - const uint8_t *msgPtr; - uint32_t msgLen; - - msgPtr=GWEN_Msg_GetConstBuffer(msg); - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - - if (msgLen>1) { - uint32_t payloadLen; - const uint8_t *payloadPtr; - int rv; - - payloadLen=GWEN_Msg_GetParsedPayloadSize(msg); - payloadPtr=msgPtr+GWEN_Msg_GetParsedPayloadOffset(msg); - - GWEN_Buffer_AppendArgs(dbuf, "%s %s", AQH_MqttMsg_MsgTypeToString(msgPtr[0] & 0xf0), sText); - - GWEN_Buffer_AppendString(dbuf, "("); - rv=_dumpPayload((msgPtr[0] & 0x0f), payloadPtr, payloadLen, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - } - else { - GWEN_Buffer_AppendString(dbuf, ")"); - } - } -} - - - -char *AQH_PublishMqttMsg_ExtractTopic(const GWEN_MSG *msg) -{ - const uint8_t *msgPtr; - uint32_t msgLen; - - msgPtr=GWEN_Msg_GetConstBuffer(msg); - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - - if (msgLen>1) { - uint32_t payloadLen; - const uint8_t *payloadPtr; - char *result; - - payloadLen=GWEN_Msg_GetParsedPayloadSize(msg); - payloadPtr=msgPtr+GWEN_Msg_GetParsedPayloadOffset(msg); - - result=AQH_MqttMsg_ExtractStringAt(payloadPtr, payloadLen); - if (result==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "here"); - return NULL; - } - return result; - } - - return NULL; -} - - - -char *AQH_PublishMqttMsg_ExtractValue(const GWEN_MSG *msg) -{ - const uint8_t *msgPtr; - uint32_t msgLen; - - msgPtr=GWEN_Msg_GetConstBuffer(msg); - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - - if (msgLen>1) { - uint8_t flags; - uint32_t payloadLen; - const uint8_t *payloadPtr; - int rv; - - flags=msgPtr[0] & 0x0f; - payloadLen=GWEN_Msg_GetParsedPayloadSize(msg); - payloadPtr=msgPtr+GWEN_Msg_GetParsedPayloadOffset(msg); - - rv=AQH_MqttMsg_SkipStringAt(payloadPtr, payloadLen); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return NULL; - } - payloadLen-=rv; - payloadPtr+=rv; - - if (flags & (AQH_MQTTMSG_FLAGS_QOS2 | AQH_MQTTMSG_FLAGS_QOS1)) { - if (payloadLen<2) { - DBG_ERROR(AQH_LOGDOMAIN, "Msg too small"); - return NULL; - } - else { - payloadLen-=2; - payloadPtr+=2; - } - } - - if (payloadLen) { - char *result; - - result=(char*) malloc(payloadLen+1); - memmove(result, payloadPtr, payloadLen); - result[payloadLen]=0; - return result; - } - else { - DBG_INFO(AQH_LOGDOMAIN, "No message"); - } - } - - return NULL; -} - - - -int _dumpPayload(uint8_t flags, const uint8_t *payloadPtr, uint32_t payloadLen, GWEN_BUFFER *dbuf) -{ - int rv; - - GWEN_Buffer_AppendString(dbuf, "flags:"); - if (flags & AQH_MQTTMSG_FLAGS_DUP) - GWEN_Buffer_AppendString(dbuf, " DUP"); - if (flags & AQH_MQTTMSG_FLAGS_RETAIN) - GWEN_Buffer_AppendString(dbuf, " RETAIN"); - GWEN_Buffer_AppendArgs(dbuf, " QOS%d", (flags>>1) & 0x03); - - GWEN_Buffer_AppendString(dbuf, " topic: "); - rv=AQH_MqttMsg_DumpString(payloadPtr, payloadLen, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - payloadLen-=rv; - payloadPtr+=rv; - - if (flags & (AQH_MQTTMSG_FLAGS_QOS2 | AQH_MQTTMSG_FLAGS_QOS1)) { - if (payloadLen<2) { - DBG_ERROR(AQH_LOGDOMAIN, "Msg too small"); - return GWEN_ERROR_BAD_DATA; - } - else { - GWEN_Buffer_AppendArgs(dbuf, " packet id: %d", (payloadPtr[0]<<8)+payloadPtr[1]); - payloadLen-=2; - payloadPtr+=2; - } - } - - if (payloadLen) { - GWEN_Buffer_AppendString(dbuf, " message: "); - GWEN_Buffer_AppendBytes(dbuf, (const char*) payloadPtr, payloadLen); - } - - return 0; -} - - - diff --git a/aqhome/mqtt/msg_mqtt_publish.h b/aqhome/mqtt/msg_mqtt_publish.h deleted file mode 100644 index fc84fdc..0000000 --- a/aqhome/mqtt/msg_mqtt_publish.h +++ /dev/null @@ -1,33 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_MQTT_PUBLISH_H -#define AQH_MSG_MQTT_PUBLISH_H - - -#include -#include - -#include -#include - - - -AQHOME_API GWEN_MSG *AQH_PublishMqttMsg_new(uint8_t flags, uint16_t packetId, - const char *sTopic, - const uint8_t *messagePtr, uint32_t messageLen); - -AQHOME_API void AQH_PublishMqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - -AQHOME_API char *AQH_PublishMqttMsg_ExtractTopic(const GWEN_MSG *msg); -AQHOME_API char *AQH_PublishMqttMsg_ExtractValue(const GWEN_MSG *msg); - - - - -#endif diff --git a/aqhome/mqtt/msg_mqtt_pubresponse.c b/aqhome/mqtt/msg_mqtt_pubresponse.c deleted file mode 100644 index 2967576..0000000 --- a/aqhome/mqtt/msg_mqtt_pubresponse.c +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include "aqhome/mqtt/msg_mqtt_pubresponse.h" - -#include - - - -GWEN_MSG *GWEN_PubResponseMqttMsg_new(uint8_t typeAndFlags, uint16_t pkgId) -{ - uint8_t data[2]; - GWEN_MSG *msg; - - data[0]=pkgId>>8 & 0xff; - data[1]=pkgId & 0xff; - - msg=GWEN_MqttMsg_new(AQH_MQTTMSG_MSGTYPE_CONNACK, 2, data); - if (msg==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "here"); - return NULL; - } - return msg; -} - - - -uint16_t AQH_PubResponseMqttMsg_GetPacketId(const GWEN_MSG *msg) -{ - const uint8_t *msgPtr; - uint32_t msgLen; - - msgPtr=GWEN_Msg_GetConstBuffer(msg); - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - - if (msgLen>1) { - const uint8_t *payloadPtr; - uint32_t payloadLen; - - payloadLen=GWEN_Msg_GetParsedPayloadSize(msg); - payloadPtr=msgPtr+GWEN_Msg_GetParsedPayloadOffset(msg); - if (payloadPtr && payloadLen>=2) - return (payloadPtr[0]<<8)+payloadPtr[1]; - } - return 0; -} - - - -void AQH_PubResponseMqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - uint8_t msgType; - uint16_t packetId; - - msgType=AQH_MqttMsg_GetMsgTypeAndFlags(msg); - packetId=AQH_PubResponseMqttMsg_GetPacketId(msg); - GWEN_Buffer_AppendArgs(dbuf, "%s %s (packet id: %04x)", AQH_MqttMsg_MsgTypeToString(msgType & 0xf0), sText, packetId); -} - - - - - - diff --git a/aqhome/mqtt/msg_mqtt_pubresponse.h b/aqhome/mqtt/msg_mqtt_pubresponse.h deleted file mode 100644 index 2b336d0..0000000 --- a/aqhome/mqtt/msg_mqtt_pubresponse.h +++ /dev/null @@ -1,31 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_MQTT_PUBRESPONSE_H -#define AQH_MSG_MQTT_PUBRESPONSE_H - - -#include -#include - -#include -#include - - - -/** - * Use for PUBACK, PUBREC, PUBREL and PUBCOMP. - */ -AQHOME_API GWEN_MSG *GWEN_PubResponseMqttMsg_new(uint8_t typeAndFlags, uint16_t pkgId); -AQHOME_API uint16_t AQH_PubResponseMqttMsg_GetPacketId(const GWEN_MSG *msg); -AQHOME_API void AQH_PubResponseMqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - - -#endif diff --git a/aqhome/mqtt/msg_mqtt_suback.c b/aqhome/mqtt/msg_mqtt_suback.c deleted file mode 100644 index a35de15..0000000 --- a/aqhome/mqtt/msg_mqtt_suback.c +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include "aqhome/mqtt/msg_mqtt_suback.h" - -#include - - - -GWEN_MSG *GWEN_SubAckMqttMsg_new(uint8_t flags, uint16_t packetId, uint8_t result) -{ - GWEN_MSG *msg; - GWEN_BUFFER *buf; - - buf=GWEN_Buffer_new(0, 64, 0, 1); - if (flags & (AQH_MQTTMSG_FLAGS_QOS2 | AQH_MQTTMSG_FLAGS_QOS1)) { - GWEN_Buffer_AppendByte(buf, (packetId>>8) & 0xff); - GWEN_Buffer_AppendByte(buf, packetId & 0xff); - } - /* payload */ - GWEN_Buffer_AppendByte(buf, result); - - msg=GWEN_MqttMsg_new(AQH_MQTTMSG_MSGTYPE_SUBACK | flags, GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - if (msg==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "here"); - return NULL; - } - return msg; -} - - - -int AQH_SubAckMqttMsg_GetResultCode(const GWEN_MSG *msg) -{ - const uint8_t *msgPtr; - uint32_t msgLen; - - msgPtr=GWEN_Msg_GetConstBuffer(msg); - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - - if (msgLen>1) { - uint32_t flags; - uint32_t payloadLen; - const uint8_t *payloadPtr; - - flags=AQH_MqttMsg_GetMsgTypeAndFlags(msg); - payloadLen=GWEN_Msg_GetParsedPayloadSize(msg); - payloadPtr=msgPtr+GWEN_Msg_GetParsedPayloadOffset(msg); - - if (payloadLen>0) { - if (flags & (AQH_MQTTMSG_FLAGS_QOS2 | AQH_MQTTMSG_FLAGS_QOS1)) { - payloadLen--; - payloadPtr++; - } - if (payloadLen>1) - return (int) (payloadPtr[0]); - } - } - - return GWEN_ERROR_GENERIC; -} - - - -void AQH_SubAckMqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - const uint8_t *msgPtr; - uint32_t msgLen; - - msgPtr=GWEN_Msg_GetConstBuffer(msg); - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - - if (msgLen>1) { - const uint8_t *payloadPtr; - uint32_t payloadLen; - - GWEN_Buffer_AppendArgs(dbuf, "%s %s", AQH_MqttMsg_MsgTypeToString(msgPtr[0] & 0xf0), sText); - payloadLen=GWEN_Msg_GetParsedPayloadSize(msg); - payloadPtr=msgPtr+GWEN_Msg_GetParsedPayloadOffset(msg); - if (payloadLen>=1) - GWEN_Buffer_AppendArgs(dbuf, "(result=%d)", payloadPtr[0]); - } -} - - - - - - diff --git a/aqhome/mqtt/msg_mqtt_suback.h b/aqhome/mqtt/msg_mqtt_suback.h deleted file mode 100644 index 901147a..0000000 --- a/aqhome/mqtt/msg_mqtt_suback.h +++ /dev/null @@ -1,28 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_MQTT_SUBACK_H -#define AQH_MSG_MQTT_SUBACK_H - - -#include -#include - -#include -#include - - - -AQHOME_API GWEN_MSG *GWEN_SubAckMqttMsg_new(uint8_t flags, uint16_t packetId, uint8_t result); -AQHOME_API void AQH_SubAckMqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - -AQHOME_API int AQH_SubAckMqttMsg_GetResultCode(const GWEN_MSG *msg); - - - -#endif diff --git a/aqhome/mqtt/msg_mqtt_subscribe.c b/aqhome/mqtt/msg_mqtt_subscribe.c deleted file mode 100644 index 78170f8..0000000 --- a/aqhome/mqtt/msg_mqtt_subscribe.c +++ /dev/null @@ -1,127 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include "aqhome/mqtt/msg_mqtt_subscribe.h" - -#include - - - -static int _dumpPayload(uint8_t flags, const uint8_t *payloadPtr, uint32_t payloadLen, GWEN_BUFFER *dbuf); - - - - - -GWEN_MSG *GWEN_SubscribeMqttMsg_new(uint8_t flags, uint16_t packetId, const char *sTopic, uint8_t requestedQos) -{ - if (sTopic && *sTopic) { - GWEN_MSG *msg; - GWEN_BUFFER *buf; - - buf=GWEN_Buffer_new(0, 64, 0, 1); - GWEN_Buffer_AppendByte(buf, (packetId>>8) & 0xff); - GWEN_Buffer_AppendByte(buf, packetId & 0xff); - - /* add topic filter / qos pair */ - AQH_MqttMsg_AppendStringWithLen(buf, sTopic); - GWEN_Buffer_AppendByte(buf, requestedQos); - - msg=GWEN_MqttMsg_new(AQH_MQTTMSG_MSGTYPE_SUBSCRIBE | flags, - GWEN_Buffer_GetUsedBytes(buf), - (const uint8_t*) GWEN_Buffer_GetStart(buf)); - GWEN_Buffer_free(buf); - if (msg==NULL) { - DBG_INFO(AQH_LOGDOMAIN, "here"); - return NULL; - } - return msg; - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "Missing topic or message"); - return NULL; - } -} - - - -void AQH_SubscribeMqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - const uint8_t *msgPtr; - uint32_t msgLen; - - msgPtr=GWEN_Msg_GetConstBuffer(msg); - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - - if (msgLen>1) { - uint32_t payloadLen; - const uint8_t *payloadPtr; - int rv; - - payloadLen=GWEN_Msg_GetParsedPayloadSize(msg); - payloadPtr=msgPtr+GWEN_Msg_GetParsedPayloadOffset(msg); - - GWEN_Buffer_AppendArgs(dbuf, "%s %s", AQH_MqttMsg_MsgTypeToString(msgPtr[0] & 0xf0), sText); - - GWEN_Buffer_AppendString(dbuf, "("); - rv=_dumpPayload((msgPtr[0] & 0x0f), payloadPtr, payloadLen, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - } - else { - GWEN_Buffer_AppendString(dbuf, ")"); - } - } -} - - - -int _dumpPayload(uint8_t flags, const uint8_t *payloadPtr, uint32_t payloadLen, GWEN_BUFFER *dbuf) -{ - int rv; - - GWEN_Buffer_AppendString(dbuf, "flags:"); - if (flags & AQH_MQTTMSG_FLAGS_DUP) - GWEN_Buffer_AppendString(dbuf, " DUP"); - if (flags & AQH_MQTTMSG_FLAGS_RETAIN) - GWEN_Buffer_AppendString(dbuf, " RETAIN"); - GWEN_Buffer_AppendArgs(dbuf, " QOS%d", (flags>>1) & 0x03); - - if (flags & (AQH_MQTTMSG_FLAGS_QOS2 | AQH_MQTTMSG_FLAGS_QOS1)) { - if (payloadLen<2) { - DBG_ERROR(AQH_LOGDOMAIN, "Msg too small"); - return GWEN_ERROR_BAD_DATA; - } - else { - GWEN_Buffer_AppendArgs(dbuf, " packet id: %d", (payloadPtr[0]<<8)+payloadPtr[1]); - payloadLen-=2; - payloadPtr+=2; - } - } - - while(payloadLen) { - GWEN_Buffer_AppendString(dbuf, " topic: "); - rv=AQH_MqttMsg_DumpString(payloadPtr, payloadLen, dbuf); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - payloadLen-=rv; - payloadPtr+=rv; - } - - return 0; -} - - - diff --git a/aqhome/mqtt/msg_mqtt_subscribe.h b/aqhome/mqtt/msg_mqtt_subscribe.h deleted file mode 100644 index 9ec42e0..0000000 --- a/aqhome/mqtt/msg_mqtt_subscribe.h +++ /dev/null @@ -1,27 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_MQTT_SUBSCRIBE_H -#define AQH_MSG_MQTT_SUBSCRIBE_H - - -#include -#include - -#include -#include - - - -AQHOME_API GWEN_MSG *GWEN_SubscribeMqttMsg_new(uint8_t flags, uint16_t packetId, const char *sTopic, uint8_t requestedQos); -AQHOME_API void AQH_SubscribeMqttMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - - -#endif diff --git a/aqhome/msg/0BUILD b/aqhome/msg/0BUILD index 2269d26..821a359 100644 --- a/aqhome/msg/0BUILD +++ b/aqhome/msg/0BUILD @@ -45,61 +45,17 @@ - endpoint_tty.h - msg_node.h - msg_ping.h - msg_pong.h - msg_claimaddr.h - msg_denyaddr.h - msg_haveaddr.h - msg_needaddr.h - msg_sendstats.h - msg_recvstats.h - msg_memstats.h - msg_sysstats.h - msg_value.h - msg_value2.h - msg_value3.h - msg_device.h - msg_flashready.h - msg_flashstart.h - msg_flashresponse.h - msg_flashend.h - msg_flashdata.h - msg_reboot.h - endpoint_tty_p.h $(local/typefiles) - endpoint_tty.c - msg_node.c - msg_ping.c - msg_pong.c - msg_claimaddr.c - msg_denyaddr.c - msg_haveaddr.c - msg_needaddr.c - msg_sendstats.c - msg_recvstats.c - msg_memstats.c - msg_sysstats.c - msg_value.c - msg_value2.c - msg_value3.c - msg_device.c - msg_flashready.c - msg_flashstart.c - msg_flashresponse.c - msg_flashend.c - msg_flashdata.c - msg_reboot.c + dummy.c diff --git a/aqhome/msg/dummy.c b/aqhome/msg/dummy.c new file mode 100644 index 0000000..e69de29 diff --git a/aqhome/msg/endpoint_tty.c b/aqhome/msg/endpoint_tty.c deleted file mode 100644 index d423882..0000000 --- a/aqhome/msg/endpoint_tty.c +++ /dev/null @@ -1,423 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include "aqhome/msg/endpoint_tty_p.h" - -#include "aqhome/msg/msg_node.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - - - -#define AQH_MSG_ENDPOINT_TTY_BAUDRATE B19200 -#define AQH_MSG_ENDPOINT_TTY_BYTE_MICROSECS 520 -#define GWEN_ENDPOINT_TTY_RECONNECT_TIME 10 - - - -GWEN_INHERIT(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY) - - - - -/* ------------------------------------------------------------------------------------------------ - * forward declarations - * ------------------------------------------------------------------------------------------------ - */ - -static void GWENHYWFAR_CB _freeData(void *bp, void *p); - -/* virtual fn for GWEN_MSG_ENDPOINT */ -static void _addSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_SOCKETSET *xSet); - -/* virtual fns for GWEN_MSG_ENDPOINT_MSGIO */ -static int _getBytesNeededForMessage(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg); -static int _startMsg(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg); -static void _endMsg(GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg); - -/* private fns */ -static int _getSocketFd(GWEN_MSG_ENDPOINT *ep); -static int _openDevice(GWEN_MSG_ENDPOINT *ep); -static int _attnLow(GWEN_MSG_ENDPOINT *ep); -static int _attnHigh(GWEN_MSG_ENDPOINT *ep); -static int _isAttnLow(GWEN_MSG_ENDPOINT *ep); - - - -/* ------------------------------------------------------------------------------------------------ - * implementations - * ------------------------------------------------------------------------------------------------ - */ - - -GWEN_MSG_ENDPOINT *AQH_TtyEndpoint_new(const char *devicePath, int groupId) -{ - GWEN_MSG_ENDPOINT *ep; - AQH_MSG_ENDPOINT_TTY *xep; - - ep=GWEN_MsgEndpoint_new(AQH_MSG_ENDPOINT_TTY_NAME, groupId); - GWEN_MsgEndpoint_SetDefaultMessageSize(ep, AQH_MAXMSGSIZE); - - GWEN_NEW_OBJECT(AQH_MSG_ENDPOINT_TTY, xep); - GWEN_INHERIT_SETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep, xep, _freeData); - - xep->deviceName=strdup(devicePath); - - GWEN_MsgEndpoint_SetAddSocketsFn(ep, _addSockets); - - /* extend with msg handling code */ - GWEN_MsgIoEndpoint_Extend(ep); - GWEN_MsgIoEndpoint_SetGetNeededBytesFn(ep, _getBytesNeededForMessage); - GWEN_MsgIoEndpoint_SetSendMsgStartFn(ep, _startMsg); - GWEN_MsgIoEndpoint_SetSendMsgFinishFn(ep, _endMsg); - - return ep; -} - - - -void _freeData(GWEN_UNUSED void *bp, void *p) -{ - AQH_MSG_ENDPOINT_TTY *xep; - - xep=(AQH_MSG_ENDPOINT_TTY*) p; - free(xep->deviceName); - GWEN_FREE_OBJECT(xep); -} - - - -void _addSockets(GWEN_MSG_ENDPOINT *ep, GWEN_SOCKETSET *readSet, GWEN_SOCKETSET *writeSet, GWEN_UNUSED GWEN_SOCKETSET *xSet) -{ - if (ep) { - if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) { - time_t now; - - now=time(NULL); - if ((now-GWEN_MsgEndpoint_GetTimeOfLastStateChange(ep))>=GWEN_ENDPOINT_TTY_RECONNECT_TIME) { - int rv; - - /* (re)connect, set state */ - DBG_INFO(AQH_LOGDOMAIN, "Starting to (re-)connect"); - rv=AQH_TtyEndpoint_Connect(ep); - if (rv<0) { - DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv); - } - } - } - - if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_CONNECTED) { - GWEN_SocketSet_AddSocket(readSet, GWEN_MsgEndpoint_GetSocket(ep)); - if (GWEN_MsgEndpoint_HaveMessageToSend(ep)) - GWEN_SocketSet_AddSocket(writeSet, GWEN_MsgEndpoint_GetSocket(ep)); - } - } /* if (ep) */ -} - - - -int AQH_TtyEndpoint_Connect(GWEN_MSG_ENDPOINT *ep) -{ - if (ep) { - if (GWEN_MsgEndpoint_GetState(ep)==GWEN_MSG_ENDPOINT_STATE_UNCONNECTED) { - int fd; - - DBG_INFO(AQH_LOGDOMAIN, "Connecting TTY device"); - fd=_openDevice(ep); - if (fd<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", fd); - return fd; - } - else { - GWEN_SOCKET *sk; - int rv; - - sk=GWEN_Socket_fromFile(fd); - rv=GWEN_Socket_SetBlocking(sk, 0); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "Error setting socket nonblocking: %d", rv); - GWEN_Socket_free(sk); - return GWEN_ERROR_IO; - } - GWEN_Socket_AddFlags(sk, GWEN_SOCKET_FLAGS_DUMP_READ); - - GWEN_MsgEndpoint_SetSocket(ep, sk); - GWEN_MsgEndpoint_SetState(ep, GWEN_MSG_ENDPOINT_STATE_CONNECTED); - GWEN_MsgEndpoint_DiscardInput(ep); - _attnHigh(ep); - return 0; - } - } - else { - DBG_ERROR(AQH_LOGDOMAIN, "Endpoint %s: Not unconnected", GWEN_MsgEndpoint_GetName(ep)); - return GWEN_ERROR_INVALID; - } - } - return GWEN_ERROR_GENERIC; -} - - - -int _getSocketFd(GWEN_MSG_ENDPOINT *ep) -{ - if (ep) { - GWEN_SOCKET *sk; - - sk=GWEN_MsgEndpoint_GetSocket(ep); - if (sk) { - return GWEN_Socket_GetSocketInt(sk); - } - } - return GWEN_ERROR_GENERIC; -} - - - -int _openDevice(GWEN_MSG_ENDPOINT *ep) -{ - AQH_MSG_ENDPOINT_TTY *xep; - int fd; - struct termios options; - int rv; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep); - assert(xep); - DBG_INFO(AQH_LOGDOMAIN, "Opening device %s", xep->deviceName); - fd=open(xep->deviceName, O_NOCTTY | O_NDELAY | O_RDWR); - if (fd<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error on open(%s): %s (%d)", xep->deviceName, strerror(errno), errno); - return GWEN_ERROR_IO; - } - DBG_INFO(AQH_LOGDOMAIN, "Device %s open (socket %d)", xep->deviceName, fd); - rv=tcgetattr(fd, &(xep->previousOptions)); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error on tcgetattr(%s): %s (%d)", xep->deviceName, strerror(errno), errno); - return GWEN_ERROR_IO; - } - options=xep->previousOptions; -// memset(&options, 0, sizeof(options)); /* preset */ - - options.c_cflag=CLOCAL | CREAD | CS8; - options.c_iflag=IGNPAR | IGNBRK; - options.c_oflag=0; - options.c_lflag&= ~(ICANON | ECHO | ECHOE | ISIG); - options.c_cc[VTIME]=0; /* read timeout in deciseconds */ - options.c_cc[VMIN]=0; /* no minimum number of receive bytes */ - cfmakeraw(&options); - - rv=cfsetispeed(&options, AQH_MSG_ENDPOINT_TTY_BAUDRATE); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error on cfsetispeed(%s): %s (%d)", xep->deviceName, strerror(errno), errno); - return GWEN_ERROR_IO; - } - rv=cfsetospeed(&options, AQH_MSG_ENDPOINT_TTY_BAUDRATE); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error on cfsetospeed(%s): %s (%d)", xep->deviceName, strerror(errno), errno); - return GWEN_ERROR_IO; - } - - rv=tcflush(fd, TCIOFLUSH); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error on tcflush(%s): %s (%d)", xep->deviceName, strerror(errno), errno); - return GWEN_ERROR_IO; - } - - rv=tcsetattr(fd, TCSANOW, &options); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error on tcsetattr(%s): %s (%d)", xep->deviceName, strerror(errno), errno); - return GWEN_ERROR_IO; - } - - return fd; -} - - - -int _startMsg(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG *msg) -{ - if (ep) { - AQH_MSG_ENDPOINT_TTY *xep; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep); - assert(xep); - if (xep->intendedAttnState==1) { - int rv; - - rv=_isAttnLow(ep); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - if (rv>0) { - DBG_INFO(AQH_LOGDOMAIN, "Line busy"); - usleep(AQH_MSG_ENDPOINT_TTY_BYTE_MICROSECS); - return GWEN_ERROR_TIMEOUT; - } - - rv=_attnLow(ep); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "here (%d)", rv); - return rv; - } - usleep(AQH_MSG_ENDPOINT_TTY_BYTE_MICROSECS/5); - } - } - return 0; -} - - - -void _endMsg(GWEN_MSG_ENDPOINT *ep, GWEN_UNUSED GWEN_MSG *msg) -{ - /* TODO: flush before releasing ATTN */ - _attnHigh(ep); -} - - - -int _getBytesNeededForMessage(GWEN_UNUSED GWEN_MSG_ENDPOINT *ep, GWEN_MSG *msg) -{ - uint32_t bytesInMsg; - - bytesInMsg=GWEN_Msg_GetBytesInBuffer(msg); - if (bytesInMsgGWEN_Msg_GetMaxSize(msg)) { - DBG_ERROR(AQH_LOGDOMAIN, "Message too long for msg (%d > %d)", msgSize, GWEN_Msg_GetMaxSize(msg)); - GWEN_MsgEndpoint_DiscardInput(ep); - return GWEN_ERROR_BAD_DATA; - } - - bytesNeeded=(int) (msgSize-bytesInMsg); - if (bytesNeeded<0 || (bytesNeeded==0 && bytesInMsg==0)) { - DBG_ERROR(AQH_LOGDOMAIN, "Bad number of bytes needed, bad message format (bytesNeeded=%d)", bytesNeeded); - GWEN_MsgEndpoint_DiscardInput(ep); - return GWEN_ERROR_BAD_DATA; - } - - return bytesNeeded; - } -} - - - -int _attnLow(GWEN_MSG_ENDPOINT *ep) -{ - AQH_MSG_ENDPOINT_TTY *xep; - int status; - int rv; - int fd; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep); - assert(xep); - fd=_getSocketFd(ep); - if (fd<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Not connected (%s)", xep->deviceName); - return GWEN_ERROR_IO; - } - rv=ioctl(fd, TIOCMGET, &status); /* GET the State of MODEM bits in Status */ - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno); - return GWEN_ERROR_IO; - } - status |= TIOCM_DTR | TIOCM_RTS; /* clear the DTR pin (cave: signals inverted!) */ - rv=ioctl(fd, TIOCMSET, &status); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno); - return GWEN_ERROR_IO; - } - xep->intendedAttnState=0; - return 0; -} - - - -int _attnHigh(GWEN_MSG_ENDPOINT *ep) -{ - AQH_MSG_ENDPOINT_TTY *xep; - int status; - int rv; - int fd; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep); - assert(xep); - fd=_getSocketFd(ep); - if (fd<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Not connected (%s)", xep->deviceName); - return GWEN_ERROR_IO; - } - rv=ioctl(fd, TIOCMGET, &status); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno); - return GWEN_ERROR_IO; - } - status |= TIOCM_DTR; /* Set the DTR pin */ - status &= ~ (TIOCM_DTR | TIOCM_RTS); /* clear the DTR pin (cave: signals inverted!) */ - rv=ioctl(fd, TIOCMSET, &status); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno); - return GWEN_ERROR_IO; - } - - xep->intendedAttnState=1; - return 0; -} - - - -int _isAttnLow(GWEN_MSG_ENDPOINT *ep) -{ - AQH_MSG_ENDPOINT_TTY *xep; - int status; - int rv; - int fd; - - xep=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT, AQH_MSG_ENDPOINT_TTY, ep); - assert(xep); - fd=_getSocketFd(ep); - if (fd<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Not connected (%s)", xep->deviceName); - return GWEN_ERROR_IO; - } - rv=ioctl(fd, TIOCMGET, &status); - if (rv<0) { - DBG_ERROR(AQH_LOGDOMAIN, "Error on ioctl(%s): %s (%d)", xep->deviceName, strerror(errno), errno); - return GWEN_ERROR_IO; - } - return (status & TIOCM_CTS)?1:0; -} - - - - - - - diff --git a/aqhome/msg/endpoint_tty.h b/aqhome/msg/endpoint_tty.h deleted file mode 100644 index 308d637..0000000 --- a/aqhome/msg/endpoint_tty.h +++ /dev/null @@ -1,26 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSGENDPOINT_TTY_H -#define AQH_MSGENDPOINT_TTY_H - - -#include - -#include - - -#define AQH_MSG_ENDPOINT_TTY_NAME "tty" - - -AQHOME_API GWEN_MSG_ENDPOINT *AQH_TtyEndpoint_new(const char *devicePath, int groupId); - -AQHOME_API int AQH_TtyEndpoint_Connect(GWEN_MSG_ENDPOINT *ep); - - -#endif diff --git a/aqhome/msg/endpoint_tty_p.h b/aqhome/msg/endpoint_tty_p.h deleted file mode 100644 index 1817860..0000000 --- a/aqhome/msg/endpoint_tty_p.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSGENDPOINT_TTY_P_H -#define AQH_MSGENDPOINT_TTY_P_H - - - -#include - -#include "aqhome/msg/endpoint_tty.h" - -#include - - - - -typedef struct AQH_MSG_ENDPOINT_TTY AQH_MSG_ENDPOINT_TTY; -struct AQH_MSG_ENDPOINT_TTY { - char *deviceName; - struct termios previousOptions; - int intendedAttnState; -}; - - - - - -#endif diff --git a/aqhome/msg/msg_claimaddr.c b/aqhome/msg/msg_claimaddr.c deleted file mode 100644 index 25085b7..0000000 --- a/aqhome/msg/msg_claimaddr.c +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_claimaddr.h" - -#include -#include -#include -#include - - -#define AQH_MSG_OFFS_CLAIMADDR_UID 0 -#define AQH_MSG_OFFS_CLAIMADDR_ADDR 4 - -#define AQH_MSG_CLAIMADDR_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_CLAIMADDR_ADDR+1) - - - -uint32_t AQH_ClaimAddrMsg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_CLAIMADDR_UID, 0); -} - - - -uint8_t AQH_ClaimAddrMsg_GetAddress(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_CLAIMADDR_ADDR, 0); -} - - - -void AQH_ClaimAddrMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_CLAIM_ADDRESS) && - (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_CLAIMADDR_MINSIZE)) { - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: CLAIM_ADDRESS %s (uid=0x%08x, address=0x%02x)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_ClaimAddrMsg_GetUid(msg), - AQH_ClaimAddrMsg_GetAddress(msg)); - } -} - - - - - - diff --git a/aqhome/msg/msg_claimaddr.h b/aqhome/msg/msg_claimaddr.h deleted file mode 100644 index 2092344..0000000 --- a/aqhome/msg/msg_claimaddr.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_CLAIMADDR_H -#define AQH_MSG_CLAIMADDR_H - - -#include -#include - -#include -#include - - - -AQHOME_API uint32_t AQH_ClaimAddrMsg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_ClaimAddrMsg_GetAddress(const GWEN_MSG *msg); -AQHOME_API void AQH_ClaimAddrMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - -#endif - - - diff --git a/aqhome/msg/msg_denyaddr.c b/aqhome/msg/msg_denyaddr.c deleted file mode 100644 index 8894a98..0000000 --- a/aqhome/msg/msg_denyaddr.c +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_denyaddr.h" - -#include -#include -#include -#include - - - -#define AQH_MSG_OFFS_DENYADDR_UID 0 -#define AQH_MSG_OFFS_DENYADDR_ADDR 4 - -#define AQH_MSG_DENYADDR_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DENYADDR_ADDR+1) - - - -uint32_t AQH_DenyAddrMsg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DENYADDR_UID, 0); -} - - - -uint8_t AQH_DenyAddrMsg_GetAddress(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DENYADDR_ADDR, 0); -} - - - -void AQH_DenyAddrMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_DENY_ADDRESS) && - (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DENYADDR_MINSIZE)) { - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: DENY_ADDRESS %s (uid=0x%08x, address=0x%02x)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_DenyAddrMsg_GetUid(msg), - AQH_DenyAddrMsg_GetAddress(msg)); - } -} - - - - - - diff --git a/aqhome/msg/msg_denyaddr.h b/aqhome/msg/msg_denyaddr.h deleted file mode 100644 index 4423d41..0000000 --- a/aqhome/msg/msg_denyaddr.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_DENYADDR_H -#define AQH_MSG_DENYADDR_H - - -#include -#include - -#include -#include - - - -AQHOME_API uint32_t AQH_DenyAddrMsg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_DenyAddrMsg_GetAddress(const GWEN_MSG *msg); -AQHOME_API void AQH_DenyAddrMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - -#endif - - - diff --git a/aqhome/msg/msg_device.c b/aqhome/msg/msg_device.c deleted file mode 100644 index d23efdc..0000000 --- a/aqhome/msg/msg_device.c +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_device.h" - -#include -#include -#include -#include - - -#define AQH_MSG_OFFS_DEVICE_UID 0 /* 4 bytes */ -#define AQH_MSG_OFFS_DEVICE_MANUF 4 /* 4 bytes */ -#define AQH_MSG_OFFS_DEVICE_DEVTYPE 8 /* 2 bytes */ -#define AQH_MSG_OFFS_DEVICE_DEVVERSION 10 /* 1 byte */ -#define AQH_MSG_OFFS_DEVICE_DEVREVISION 11 /* 1 byte */ -#define AQH_MSG_OFFS_DEVICE_FWVARIANT 12 /* 1 byte */ -#define AQH_MSG_OFFS_DEVICE_FWVMAJOR 13 /* 1 byte */ -#define AQH_MSG_OFFS_DEVICE_FWVMINOR 14 /* 1 byte */ -#define AQH_MSG_OFFS_DEVICE_FWVPATCH 15 /* 1 byte */ - - -#define AQH_MSG_DEVICE_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVPATCH+1) - - - -uint32_t AQH_DeviceMsg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_UID, 0); -} - - - -uint32_t AQH_DeviceMsg_GetManufacturer(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_MANUF, 0); -} - - - -uint16_t AQH_DeviceMsg_GetDeviceType(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVTYPE, 0); -} - - - -uint8_t AQH_DeviceMsg_GetDeviceVersion(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVVERSION, 0); -} - - - -uint8_t AQH_DeviceMsg_GetDeviceRevision(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVREVISION, 0); -} - - - -uint8_t AQH_DeviceMsg_GetFirmwareVariant(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVARIANT, 0); -} - - -uint8_t AQH_DeviceMsg_GetFirmwareVersionMajor(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVMAJOR, 0); -} - - - -uint8_t AQH_DeviceMsg_GetFirmwareVersionMinor(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVMINOR, 0); -} - - - -uint8_t AQH_DeviceMsg_GetFirmwareVersionPatchlevel(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVPATCH, 0); -} - - - -void AQH_DeviceMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: DEVICE %s (uid=0x%08x, dev=%08x:%04x v%d.%d, fw=%d.%d.%d (%d))\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_DeviceMsg_GetUid(msg), - AQH_DeviceMsg_GetManufacturer(msg), - AQH_DeviceMsg_GetDeviceType(msg), - AQH_DeviceMsg_GetDeviceVersion(msg), - AQH_DeviceMsg_GetDeviceRevision(msg), - AQH_DeviceMsg_GetFirmwareVersionMajor(msg), - AQH_DeviceMsg_GetFirmwareVersionMinor(msg), - AQH_DeviceMsg_GetFirmwareVersionPatchlevel(msg), - AQH_DeviceMsg_GetFirmwareVariant(msg)); - } -} - - - - - diff --git a/aqhome/msg/msg_device.h b/aqhome/msg/msg_device.h deleted file mode 100644 index 47fb421..0000000 --- a/aqhome/msg/msg_device.h +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_DEVICE_H -#define AQH_MSG_DEVICE_H - - -#include -#include - -#include -#include - - - -AQHOME_API uint32_t AQH_DeviceMsg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint32_t AQH_DeviceMsg_GetManufacturer(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_DeviceMsg_GetDeviceType(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_DeviceMsg_GetDeviceVersion(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_DeviceMsg_GetDeviceRevision(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_DeviceMsg_GetFirmwareVariant(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_DeviceMsg_GetFirmwareVersionMajor(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_DeviceMsg_GetFirmwareVersionMinor(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_DeviceMsg_GetFirmwareVersionPatchlevel(const GWEN_MSG *msg); - -AQHOME_API void AQH_DeviceMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_flashdata.c b/aqhome/msg/msg_flashdata.c deleted file mode 100644 index b899ded..0000000 --- a/aqhome/msg/msg_flashdata.c +++ /dev/null @@ -1,110 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_flashdata.h" - -#include -#include -#include -#include -#include - - -#define AQH_MSG_OFFS_FLASHDATA_ADDRESS 0 /* 4 bytes */ -#define AQH_MSG_OFFS_FLASHDATA_DATA 4 /* x bytes */ - - -#define AQH_MSG_FLASHDATA_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_DATA) - - - -GWEN_MSG *AQH_FlashDataMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t addr, - const uint8_t *dataPtr, uint32_t dataLen) -{ - GWEN_MSG *msg; - uint8_t *ptr; - int rv; - uint32_t i; - - msg=AQH_NodeMsg_new(destAddr, srcAddr, code, dataLen+4, NULL); - ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_ADDRESS; - - *(ptr++)=addr & 0xff; - *(ptr++)=(addr>>8) & 0xff; - *(ptr++)=(addr>>16) & 0xff; - *(ptr++)=(addr>>24) & 0xff; - - for (i=0; iAQH_MSG_FLASHDATA_MINSIZE) - return msgDataLen-6; /* cmd (1), src(1), addr(4) */ - return 0; -} - - - -const uint8_t *AQH_FlashDataMsg_GetDataPtr(const GWEN_MSG *msg) -{ - const uint8_t *ptr; - - ptr=GWEN_Msg_GetConstBuffer(msg); - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHDATA_MINSIZE) - return ptr+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_DATA; - return NULL; -} - - - -void AQH_FlashDataMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHDATA_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHDATA %s (data address=0x%04x, data length=%d)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - AQH_FlashDataMsg_GetAddress(msg), - AQH_FlashDataMsg_GetDataLen(msg)); - } -} - - - - - - - diff --git a/aqhome/msg/msg_flashdata.h b/aqhome/msg/msg_flashdata.h deleted file mode 100644 index f91d23e..0000000 --- a/aqhome/msg/msg_flashdata.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_FLASHDATA_H -#define AQH_MSG_FLASHDATA_H - - -#include -#include - -#include -#include - - -AQHOME_API GWEN_MSG *AQH_FlashDataMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t addr, - const uint8_t *dataPtr, uint32_t dataLen); - -AQHOME_API uint32_t AQH_FlashDataMsg_GetAddress(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_FlashDataMsg_GetDataLen(const GWEN_MSG *msg); -AQHOME_API const uint8_t *AQH_FlashDataMsg_GetDataPtr(const GWEN_MSG *msg); -AQHOME_API void AQH_FlashDataMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - - -#endif - - - diff --git a/aqhome/msg/msg_flashend.c b/aqhome/msg/msg_flashend.c deleted file mode 100644 index b2e228e..0000000 --- a/aqhome/msg/msg_flashend.c +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_flashend.h" - -#include -#include -#include -#include - - -#define AQH_MSG_OFFS_FLASHEND_REASON 0 /* 1 byte */ - -#define AQH_MSG_FLASHEND_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHEND_REASON+1) - - - -GWEN_MSG *AQH_FlashEndMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint8_t reason) -{ - GWEN_MSG *msg; - uint8_t *ptr; - int rv; - - msg=AQH_NodeMsg_new(destAddr, srcAddr, code, 5, NULL); - ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHEND_REASON; - - *(ptr++)=reason & 0xff; /* reason */ - GWEN_Msg_IncCurrentPos(msg, 5); - - rv=AQH_NodeMsg_AddChecksum(msg); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Msg_free(msg); - return NULL; - } - - return msg; - -} - - - -uint8_t AQH_FlashEndMsg_GetReason(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHEND_REASON, 0); -} - - - -void AQH_FlashEndMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHEND_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHEND %s (reason=%d)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - AQH_FlashEndMsg_GetReason(msg)); - } -} - - - - - - - diff --git a/aqhome/msg/msg_flashend.h b/aqhome/msg/msg_flashend.h deleted file mode 100644 index c48901f..0000000 --- a/aqhome/msg/msg_flashend.h +++ /dev/null @@ -1,31 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_FLASHEND_H -#define AQH_MSG_FLASHEND_H - - -#include -#include - -#include -#include - - -AQHOME_API GWEN_MSG *AQH_FlashEndMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint8_t reason); - -AQHOME_API uint8_t AQH_FlashEndMsg_GetReason(const GWEN_MSG *msg); - -AQHOME_API void AQH_FlashEndMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_flashready.c b/aqhome/msg/msg_flashready.c deleted file mode 100644 index 51015cc..0000000 --- a/aqhome/msg/msg_flashready.c +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_flashready.h" - -#include -#include -#include -#include - - -#define AQH_MSG_OFFS_FLASHREADY_UID 0 /* 4 bytes */ -#define AQH_MSG_OFFS_FLASHREADY_MANUF 4 /* 4 bytes */ -#define AQH_MSG_OFFS_FLASHREADY_DEVTYPE 8 /* 2 bytes */ -#define AQH_MSG_OFFS_FLASHREADY_DEVVERSION 10 /* 1 byte */ -#define AQH_MSG_OFFS_FLASHREADY_DEVREVISION 11 /* 1 byte */ -#define AQH_MSG_OFFS_FLASHREADY_FWVARIANT 12 /* 1 byte */ -#define AQH_MSG_OFFS_FLASHREADY_FWVMAJOR 13 /* 1 byte */ -#define AQH_MSG_OFFS_FLASHREADY_FWVMINOR 14 /* 1 byte */ -#define AQH_MSG_OFFS_FLASHREADY_FWVPATCH 15 /* 1 byte */ -#define AQH_MSG_OFFS_FLASHREADY_PAGESIZE 16 /* 2 bytes */ - -#define AQH_MSG_FLASHREADY_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_PAGESIZE+2) - - - -uint32_t AQH_FlashReadyMsg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_UID, 0); -} - - - -uint32_t AQH_FlashReadyMsg_GetManufacturer(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_MANUF, 0); -} - - - -uint16_t AQH_FlashReadyMsg_GetDeviceType(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_DEVTYPE, 0); -} - - - -uint8_t AQH_FlashReadyMsg_GetDeviceVersion(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_DEVVERSION, 0); -} - - - -uint8_t AQH_FlashReadyMsg_GetDeviceRevision(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_DEVREVISION, 0); -} - - - -uint8_t AQH_FlashReadyMsg_GetFirmwareVariant(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVARIANT, 0); -} - - -uint8_t AQH_FlashReadyMsg_GetFirmwareVersionMajor(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVMAJOR, 0); -} - - - -uint8_t AQH_FlashReadyMsg_GetFirmwareVersionMinor(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVMINOR, 0); -} - - - -uint8_t AQH_FlashReadyMsg_GetFirmwareVersionPatchlevel(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVPATCH, 0); -} - - - -uint16_t AQH_FlashReadyMsg_GetPagesize(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_PAGESIZE, 0); -} - - - - - - -void AQH_FlashReadyMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_FLASH_READY) && - (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHREADY_MINSIZE)) { - - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: FLASHREADY %s (uid=0x%08x, dev=%08x:%04x v%d.%d, fw=%d.%d.%d (%d) pagesize=%d)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_FlashReadyMsg_GetUid(msg), - AQH_FlashReadyMsg_GetManufacturer(msg), - AQH_FlashReadyMsg_GetDeviceType(msg), - AQH_FlashReadyMsg_GetDeviceVersion(msg), - AQH_FlashReadyMsg_GetDeviceRevision(msg), - AQH_FlashReadyMsg_GetFirmwareVersionMajor(msg), - AQH_FlashReadyMsg_GetFirmwareVersionMinor(msg), - AQH_FlashReadyMsg_GetFirmwareVersionPatchlevel(msg), - AQH_FlashReadyMsg_GetFirmwareVariant(msg), - AQH_FlashReadyMsg_GetPagesize(msg)); - } -} - - - - - - - diff --git a/aqhome/msg/msg_flashready.h b/aqhome/msg/msg_flashready.h deleted file mode 100644 index 170297b..0000000 --- a/aqhome/msg/msg_flashready.h +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_FLASHREADY_H -#define AQH_MSG_FLASHREADY_H - - -#include -#include - -#include -#include - - -AQHOME_API uint32_t AQH_FlashReadyMsg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint32_t AQH_FlashReadyMsg_GetManufacturer(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_FlashReadyMsg_GetDeviceType(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_FlashReadyMsg_GetDeviceVersion(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_FlashReadyMsg_GetDeviceRevision(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_FlashReadyMsg_GetFirmwareVariant(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_FlashReadyMsg_GetFirmwareVersionMajor(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_FlashReadyMsg_GetFirmwareVersionMinor(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_FlashReadyMsg_GetFirmwareVersionPatchlevel(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_FlashReadyMsg_GetPagesize(const GWEN_MSG *msg); - -AQHOME_API void AQH_FlashReadyMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_flashresponse.c b/aqhome/msg/msg_flashresponse.c deleted file mode 100644 index 6d23a10..0000000 --- a/aqhome/msg/msg_flashresponse.c +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_flashresponse.h" - -#include -#include -#include -#include - - -#define AQH_MSG_OFFS_FLASHRESPONSE_CODE 0 /* 1 byte */ - -#define AQH_MSG_FLASHRESPONSE_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHRESPONSE_CODE+1) - - - -uint8_t AQH_FlashResponseMsg_GetCode(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHRESPONSE_CODE, 0); -} - - - -void AQH_FlashResponseMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHRESPONSE_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHRESPONSE %s (code=%d)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - AQH_FlashResponseMsg_GetCode(msg)); - } -} - - - - - - - diff --git a/aqhome/msg/msg_flashresponse.h b/aqhome/msg/msg_flashresponse.h deleted file mode 100644 index bd9b023..0000000 --- a/aqhome/msg/msg_flashresponse.h +++ /dev/null @@ -1,28 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_FLASHRESPONSE_H -#define AQH_MSG_FLASHRESPONSE_H - - -#include -#include - -#include -#include - - -AQHOME_API uint8_t AQH_FlashResponseMsg_GetCode(const GWEN_MSG *msg); -AQHOME_API void AQH_FlashResponseMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_flashstart.c b/aqhome/msg/msg_flashstart.c deleted file mode 100644 index 87f023b..0000000 --- a/aqhome/msg/msg_flashstart.c +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_flashstart.h" - -#include -#include -#include -#include - - -#define AQH_MSG_OFFS_FLASHSTART_UID 0 /* 4 bytes */ - -#define AQH_MSG_FLASHSTART_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_UID+4) - - - -GWEN_MSG *AQH_FlashStartMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid) -{ - GWEN_MSG *msg; - uint8_t *ptr; - int rv; - - msg=AQH_NodeMsg_new(destAddr, srcAddr, code, 8, NULL); - ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_UID; - - *(ptr++)=uid & 0xff; /* uid */ - *(ptr++)=(uid>>8) & 0xff; - *(ptr++)=(uid>>16) & 0xff; - *(ptr++)=(uid>>24) & 0xff; - - rv=AQH_NodeMsg_AddChecksum(msg); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Msg_free(msg); - return NULL; - } - - return msg; - -} - - - -uint32_t AQH_FlashStartMsg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_UID, 0); -} - - - -void AQH_FlashStartMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_FLASHSTART_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHSTART %s (uid=0x%08x)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_FlashStartMsg_GetUid(msg)); - } -} - - - - - - - diff --git a/aqhome/msg/msg_flashstart.h b/aqhome/msg/msg_flashstart.h deleted file mode 100644 index e34575c..0000000 --- a/aqhome/msg/msg_flashstart.h +++ /dev/null @@ -1,30 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_FLASHSTART_H -#define AQH_MSG_FLASHSTART_H - - -#include -#include - -#include -#include - -AQHOME_API GWEN_MSG *AQH_FlashStartMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid); - -AQHOME_API uint32_t AQH_FlashStartMsg_GetUid(const GWEN_MSG *msg); - -AQHOME_API void AQH_FlashStartMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_haveaddr.c b/aqhome/msg/msg_haveaddr.c deleted file mode 100644 index 1ae44b5..0000000 --- a/aqhome/msg/msg_haveaddr.c +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_haveaddr.h" - -#include -#include -#include -#include - - -#define AQH_MSG_OFFS_HAVEADDR_UID 0 -#define AQH_MSG_OFFS_HAVEADDR_ADDR 4 - -#define AQH_MSG_HAVEADDR_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_HAVEADDR_ADDR+1) - - - -uint32_t AQH_HaveAddrMsg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_HAVEADDR_UID, 0); -} - - - -uint8_t AQH_HaveAddrMsg_GetAddress(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_HAVEADDR_ADDR, 0); -} - - - -void AQH_HaveAddrMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_HAVE_ADDRESS) && - (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_HAVEADDR_MINSIZE)) { - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: HAVE_ADDRESS %s (uid=0x%08x, address=0x%02x)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_HaveAddrMsg_GetUid(msg), - AQH_HaveAddrMsg_GetAddress(msg)); - } -} - - - - - - diff --git a/aqhome/msg/msg_haveaddr.h b/aqhome/msg/msg_haveaddr.h deleted file mode 100644 index 059165f..0000000 --- a/aqhome/msg/msg_haveaddr.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_HAVEADDR_H -#define AQH_MSG_HAVEADDR_H - - -#include -#include - -#include -#include - - - -AQHOME_API uint32_t AQH_HaveAddrMsg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_HaveAddrMsg_GetAddress(const GWEN_MSG *msg); -AQHOME_API void AQH_HaveAddrMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - -#endif - - - diff --git a/aqhome/msg/msg_memstats.c b/aqhome/msg/msg_memstats.c deleted file mode 100644 index 3a761be..0000000 --- a/aqhome/msg/msg_memstats.c +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_memstats.h" - -#include -#include -#include -#include - - - -#define AQH_MSG_OFFS_MEMSTATS_SECONDS 0 /* 4 bytes */ -#define AQH_MSG_OFFS_MEMSTATS_UID 4 /* 4 bytes */ -#define AQH_MSG_OFFS_MEMSTATS_STACKUSAGE 8 /* 2 bytes */ -#define AQH_MSG_OFFS_MEMSTATS_BUFFERSUSED 10 /* 1 byte */ -#define AQH_MSG_OFFS_MEMSTATS_MAXBUFFERSUSED 11 /* 1 byte */ -#define AQH_MSG_OFFS_MEMSTATS_RECVNOBUFFER 12 /* 2 bytes */ - -#define AQH_MSG_MEMSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_RECVNOBUFFER+2) - - - -uint32_t AQH_MemStatsMsg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_UID, 0); -} - - - -uint32_t AQH_MemStatsMsg_GetSeconds(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_SECONDS, 0); -} - - -uint16_t AQH_MemStatsMsg_GetStackUsage(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_STACKUSAGE, 0); -} - - - -uint8_t AQH_MemStatsMsg_GetBuffersUsed(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_BUFFERSUSED, 0); -} - - - -uint8_t AQH_MemStatsMsg_GetMaxBuffersUsed(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_MAXBUFFERSUSED, 0); -} - - - -uint16_t AQH_MemStatsMsg_GetRecvNoBufferErrors(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_RECVNOBUFFER, 0); -} - - - -void AQH_MemStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: MEMSTATS %s (uid=0x%08x, uptime=%d, stack used=%d, buffers used=%d(max=%d), no recvbuf=%d)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_MemStatsMsg_GetUid(msg), - AQH_MemStatsMsg_GetSeconds(msg), - AQH_MemStatsMsg_GetStackUsage(msg), - AQH_MemStatsMsg_GetBuffersUsed(msg), - AQH_MemStatsMsg_GetMaxBuffersUsed(msg), - AQH_MemStatsMsg_GetRecvNoBufferErrors(msg)); -} - - - - - - - diff --git a/aqhome/msg/msg_memstats.h b/aqhome/msg/msg_memstats.h deleted file mode 100644 index c995244..0000000 --- a/aqhome/msg/msg_memstats.h +++ /dev/null @@ -1,38 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_MEMSTATS_H -#define AQH_MSG_MEMSTATS_H - - -#include -#include - -#include -#include - - - -AQHOME_API uint32_t AQH_MemStatsMsg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint32_t AQH_MemStatsMsg_GetSeconds(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_MemStatsMsg_GetStackUsage(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_MemStatsMsg_GetBuffersUsed(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_MemStatsMsg_GetMaxBuffersUsed(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_MemStatsMsg_GetSendNoBufferErrors(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_MemStatsMsg_GetRecvNoBufferErrors(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_MemStatsMsg_GetIdlePercentage(const GWEN_MSG *msg); - - -AQHOME_API void AQH_MemStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_needaddr.c b/aqhome/msg/msg_needaddr.c deleted file mode 100644 index 7bf1e99..0000000 --- a/aqhome/msg/msg_needaddr.c +++ /dev/null @@ -1,52 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_needaddr.h" - -#include -#include -#include -#include - - - -#define AQH_MSG_OFFS_NEEDADDR_UID 0 - -#define AQH_MSG_NEEDADDR_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_NEEDADDR_UID+4) - - - -uint32_t AQH_NeedAddrMsg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_NEEDADDR_UID, 0); -} - - - -void AQH_NeedAddrMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_NEED_ADDRESS) && - (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_NEEDADDR_MINSIZE)) { - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: NEED_ADDRESS %s (uid=0x%08x)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_NeedAddrMsg_GetUid(msg)); - } -} - - - - - - diff --git a/aqhome/msg/msg_needaddr.h b/aqhome/msg/msg_needaddr.h deleted file mode 100644 index eb1cf21..0000000 --- a/aqhome/msg/msg_needaddr.h +++ /dev/null @@ -1,28 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_NEEDADDR_H -#define AQH_MSG_NEEDADDR_H - - -#include -#include - -#include -#include - - - -AQHOME_API uint32_t AQH_NeedAddrMsg_GetUid(const GWEN_MSG *msg); -AQHOME_API void AQH_NeedAddrMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - -#endif - - - diff --git a/aqhome/msg/msg_node.c b/aqhome/msg/msg_node.c deleted file mode 100644 index 6bc4d2f..0000000 --- a/aqhome/msg/msg_node.c +++ /dev/null @@ -1,308 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - - -#include "aqhome/msg/msg_node.h" - -#include -#include - - -#define COM_USE_CRC8 1 - - - -#ifdef COM_USE_CRC8 -static uint8_t _calcCrc8Checksum(const uint8_t *ptr, uint8_t len); -#else -static uint8_t _calcXorChecksum(const uint8_t *ptr, uint8_t len); -#endif - - - -GWEN_MSG *AQH_NodeMsg_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint8_t payloadLen, const uint8_t *payload) -{ - GWEN_MSG *msg; - uint32_t len; - uint8_t *ptr; - - len=AQH_MSG_OFFS_ALL_DATA_BEGIN+payloadLen+1; /* dest, len, code, src, payload, crc8 */ - msg=GWEN_Msg_new(len); - if (msg==NULL) - return NULL; - ptr=GWEN_Msg_GetBuffer(msg); - - ptr[AQH_MSG_OFFS_ALL_DEST_ADDRESS]=destAddr & 0xff; - ptr[AQH_MSG_OFFS_ALL_PAYLOAD_LEN]=payloadLen+2; - ptr[AQH_MSG_OFFS_ALL_MSG_TYPE]=code; - ptr[AQH_MSG_OFFS_ALL_SRC_ADDRESS]=srcAddr; - - if (payloadLen && payload) - memmove(ptr+AQH_MSG_OFFS_ALL_DATA_BEGIN, payload, payloadLen); - GWEN_Msg_SetBytesInBuffer(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+payloadLen); - GWEN_Msg_IncCurrentPos(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+payloadLen); - return msg; -} - - - -uint8_t AQH_NodeMsg_GetDestAddress(const GWEN_MSG *msg) -{ - if (msg && GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_OFFS_ALL_DATA_BEGIN) { - const uint8_t *ptr; - - ptr=GWEN_Msg_GetConstBuffer(msg); - return ptr[AQH_MSG_OFFS_ALL_DEST_ADDRESS]; - } - - return 0; -} - - - -uint8_t AQH_NodeMsg_GetMsgType(const GWEN_MSG *msg) -{ - if (msg && GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_OFFS_ALL_DATA_BEGIN) { - const uint8_t *ptr; - - ptr=GWEN_Msg_GetConstBuffer(msg); - return ptr[AQH_MSG_OFFS_ALL_MSG_TYPE]; - } - - return 0; -} - - - -uint8_t AQH_NodeMsg_GetSourceAddress(const GWEN_MSG *msg) -{ - if (msg && GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_OFFS_ALL_DATA_BEGIN) { - const uint8_t *ptr; - - ptr=GWEN_Msg_GetConstBuffer(msg); - return ptr[AQH_MSG_OFFS_ALL_SRC_ADDRESS]; - } - - return 0; -} - - - -uint8_t AQH_NodeMsg_GetMsgPayloadLen(const GWEN_MSG *msg) -{ - if (msg && GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_OFFS_ALL_DATA_BEGIN) { - const uint8_t *ptr; - - ptr=GWEN_Msg_GetConstBuffer(msg); - return ptr[AQH_MSG_OFFS_ALL_PAYLOAD_LEN]; - } - - return 0; -} - - - -int AQH_NodeMsg_IsMsgComplete(const GWEN_MSG *msg) -{ - if (msg) { - uint8_t msgLen; - - msgLen=GWEN_Msg_GetBytesInBuffer(msg); - if (msgLen>=AQH_MSG_OFFS_ALL_DATA_BEGIN) { - const uint8_t *ptr; - uint8_t len; - - ptr=GWEN_Msg_GetConstBuffer(msg); - len=ptr[AQH_MSG_OFFS_ALL_PAYLOAD_LEN]+AQH_MSG_OFFS_ALL_PAYLOAD_BEGIN+1; - if (len>AQH_MAXMSGSIZE) { - DBG_ERROR(AQH_LOGDOMAIN, "Total length > max length (%d > %d)", len, AQH_MAXMSGSIZE); - return -1; - } - else if (msgLen>=len) - return 1; - } - } - - return 0; -} - - - -int AQH_NodeMsg_IsChecksumValid(const GWEN_MSG *msg) -{ - if (msg && AQH_NodeMsg_IsMsgComplete(msg)) { -#ifdef COM_USE_CRC8 - return (_calcCrc8Checksum(GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg))==0)?1:0; -#else - return (_calcXorChecksum(GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg))==0)?1:0; -#endif - } - return 0; -} - - - -int AQH_NodeMsg_AddChecksum(GWEN_MSG *msg) -{ - if (msg) { - int rv; - -#ifdef COM_USE_CRC8 - rv=GWEN_Msg_AddByte(msg, _calcCrc8Checksum(GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg))); -#else - rv=GWEN_Msg_AddByte(msg, _calcXorChecksum(GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg))); -#endif - if (rv<0) { - DBG_INFO(NULL, "here (%d)", rv); - return rv; - } - return 0; - } - return GWEN_ERROR_GENERIC; -} - - - -void AQH_NodeMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: %d %s\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - AQH_NodeMsg_GetMsgType(msg), - sText); - GWEN_Text_DumpString2Buffer((const char*)GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg), dbuf, 34); -} - - - - -uint32_t AQH_NodeMsg_GetMsgGroup(uint8_t msgType) -{ - switch(msgType) { - case AQH_MSG_TYPE_PING: - case AQH_MSG_TYPE_PONG: - case AQH_MSG_TYPE_COMSENDSTATS: - case AQH_MSG_TYPE_COMRECVSTATS: - case AQH_MSG_TYPE_TWIBUSMEMBER: - case AQH_MSG_TYPE_DEBUG: - case AQH_MSG_TYPE_DEVICE: - case AQH_MSG_TYPE_MEMSTATS: - case AQH_MSG_TYPE_SYSSTATS: - return AQH_MSG_TYPEGROUP_INFO; - - case AQH_MSG_TYPE_VALUE: - case AQH_MSG_TYPE_VALUE2: - case AQH_MSG_TYPE_VALUE_REPORT: - case AQH_MSG_TYPE_VALUE_SET: - case AQH_MSG_TYPE_VALUE_SET_ACK: - case AQH_MSG_TYPE_VALUE_SET_NACK: - return AQH_MSG_TYPEGROUP_VALUES; - - case AQH_MSG_TYPE_NEED_ADDRESS: - case AQH_MSG_TYPE_HAVE_ADDRESS: - case AQH_MSG_TYPE_CLAIM_ADDRESS: - case AQH_MSG_TYPE_DENY_ADDRESS: - case AQH_MSG_TYPE_ADDRESS_RANGE: - return AQH_MSG_TYPEGROUP_ADDRESS; - - case AQH_MSG_TYPE_NET_SET_ACCEPTED_MSGGROUPS: - return AQH_MSG_TYPEGROUP_ADMIN; - - case AQH_MSG_TYPE_FLASH_START: - case AQH_MSG_TYPE_FLASH_END: - case AQH_MSG_TYPE_FLASH_READY: - case AQH_MSG_TYPE_FLASH_DATA: - case AQH_MSG_TYPE_FLASH_RSP: - case AQH_MSG_TYPE_REBOOT_REQ: - case AQH_MSG_TYPE_REBOOT_RSP: - return AQH_MSG_TYPEGROUP_FLASH; - - default: - return 0; - } -} - - - - -#ifdef COM_USE_CRC8 -uint8_t _calcCrc8Checksum(const uint8_t *ptr, uint8_t len) -{ - int i; - uint8_t x=0xff; - - for (i=0; i - -#include -#include - - -#define AQH_MAXMSGSIZE 128 - - -#define AQH_MSG_OFFS_ALL_DEST_ADDRESS 0 -#define AQH_MSG_OFFS_ALL_PAYLOAD_LEN 1 -#define AQH_MSG_OFFS_ALL_PAYLOAD_BEGIN 2 -#define AQH_MSG_OFFS_ALL_MSG_TYPE 2 -#define AQH_MSG_OFFS_ALL_SRC_ADDRESS 3 -#define AQH_MSG_OFFS_ALL_DATA_BEGIN 4 - - -#define AQH_MSG_TYPE_PING 10 -#define AQH_MSG_TYPE_PONG 11 -#define AQH_MSG_TYPE_COMSENDSTATS 20 -#define AQH_MSG_TYPE_COMRECVSTATS 21 -#define AQH_MSG_TYPE_TWIBUSMEMBER 30 -#define AQH_MSG_TYPE_DEBUG 40 -#define AQH_MSG_TYPE_VALUE 50 /* deprecated */ -#define AQH_MSG_TYPE_VALUE2 51 /* deprecated */ -#define AQH_MSG_TYPE_NEED_ADDRESS 60 -#define AQH_MSG_TYPE_HAVE_ADDRESS 61 -#define AQH_MSG_TYPE_CLAIM_ADDRESS 62 -#define AQH_MSG_TYPE_DENY_ADDRESS 63 -#define AQH_MSG_TYPE_ADDRESS_RANGE 64 - -#define AQH_MSG_TYPE_FLASH_START 70 -#define AQH_MSG_TYPE_FLASH_END 71 -#define AQH_MSG_TYPE_FLASH_READY 72 -#define AQH_MSG_TYPE_FLASH_DATA 73 -#define AQH_MSG_TYPE_FLASH_RSP 74 - -#define AQH_MSG_TYPE_DEVICE 80 -#define AQH_MSG_TYPE_MEMSTATS 81 -#define AQH_MSG_TYPE_SYSSTATS 82 - -#define AQH_MSG_TYPE_REBOOT_REQ 90 -#define AQH_MSG_TYPE_REBOOT_RSP 91 - -#define AQH_MSG_TYPE_VALUE_REPORT 100 -#define AQH_MSG_TYPE_VALUE_SET 101 -#define AQH_MSG_TYPE_VALUE_SET_ACK 102 -#define AQH_MSG_TYPE_VALUE_SET_NACK 103 - - -/* internal msg types via NET interface */ -#define AQH_MSG_TYPE_NET_SET_ACCEPTED_MSGGROUPS 200 - - -#define AQH_MSG_TYPEGROUP_INFO 0x00000001 -#define AQH_MSG_TYPEGROUP_VALUES 0x00000002 -#define AQH_MSG_TYPEGROUP_ADDRESS 0x00000004 -#define AQH_MSG_TYPEGROUP_FLASH 0x00000008 -#define AQH_MSG_TYPEGROUP_ADMIN 0x00000010 -#define AQH_MSG_TYPEGROUP_ALL 0xffffffff - - -#define AQH_MSG_MODULES_MASK_TIMER 0x02 -#define AQH_MSG_MODULES_MASK_COM 0x04 -#define AQH_MSG_MODULES_MASK_LED 0x08 -#define AQH_MSG_MODULES_MASK_TWIMASTER 0x10 -#define AQH_MSG_MODULES_MASK_LCD 0x20 -#define AQH_MSG_MODULES_MASK_SI7021 0x40 -#define AQH_MSG_MODULES_MASK_STATS 0x80 - - - -AQHOME_API GWEN_MSG *AQH_NodeMsg_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint8_t payloadLen, const uint8_t *payload); - - -AQHOME_API uint8_t AQH_NodeMsg_GetDestAddress(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_NodeMsg_GetMsgType(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_NodeMsg_GetSourceAddress(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_NodeMsg_GetMsgPayloadLen(const GWEN_MSG *msg); - - - -AQHOME_API int AQH_NodeMsg_IsMsgComplete(const GWEN_MSG *msg); -AQHOME_API int AQH_NodeMsg_IsChecksumValid(const GWEN_MSG *msg); -AQHOME_API int AQH_NodeMsg_AddChecksum(GWEN_MSG *msg); - -AQHOME_API void AQH_NodeMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - -AQHOME_API uint32_t AQH_NodeMsg_GetMsgGroup(uint8_t msgType); - -AQHOME_API const char *AQH_NodeMsg_MsgTypeToChar(uint8_t i); - - -#endif diff --git a/aqhome/msg/msg_ping.c b/aqhome/msg/msg_ping.c deleted file mode 100644 index 4621e45..0000000 --- a/aqhome/msg/msg_ping.c +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_ping.h" -#include "aqhome/msg/msg_node.h" - -#include -#include -#include -#include - -#include - - -#define AQH_MSG_OFFS_PING_TIMESTAMP 0 - -#define AQH_MSG_PING_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_PING_TIMESTAMP+4+1) - - - - -GWEN_MSG *AQH_PingMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code) -{ - GWEN_MSG *msg; - uint8_t *ptr; - int rv; - - msg=AQH_NodeMsg_new(destAddr, srcAddr, code, 4, NULL); - ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_PING_TIMESTAMP; - *(ptr++)=0; /* timestamp */ - *(ptr++)=0; - *(ptr++)=0; - *ptr=0; - - rv=AQH_NodeMsg_AddChecksum(msg); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Msg_free(msg); - return NULL; - } - - return msg; -} - - - -uint32_t AQH_PingMsg_GetTimestamp(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_PING_TIMESTAMP, 0); -} - - - -void AQH_PingMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_PING) && - (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_PING_MINSIZE)) { - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: PING %s (timestamp=0x%08x)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_PingMsg_GetTimestamp(msg)); - } -} - - - - - - diff --git a/aqhome/msg/msg_ping.h b/aqhome/msg/msg_ping.h deleted file mode 100644 index 218ca59..0000000 --- a/aqhome/msg/msg_ping.h +++ /dev/null @@ -1,30 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_NODE_PING_H -#define AQH_MSG_NODE_PING_H - - -#include -#include - -#include -#include - - -AQHOME_API GWEN_MSG *AQH_PingMsg_new(uint8_t code, uint8_t srcAddr, uint8_t destAddr); - -AQHOME_API uint32_t AQH_PingMsg_GetTimestamp(const GWEN_MSG *msg); -AQHOME_API void AQH_PingMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_pong.c b/aqhome/msg/msg_pong.c deleted file mode 100644 index a8e898b..0000000 --- a/aqhome/msg/msg_pong.c +++ /dev/null @@ -1,51 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_pong.h" - -#include -#include -#include -#include - - -#define AQH_MSG_OFFS_PONG_TIMESTAMP 0 - -#define AQH_MSG_PONG_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_PONG_TIMESTAMP+4) - - - -uint32_t AQH_PongMsg_GetTimestamp(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_PONG_TIMESTAMP, 0); -} - - - -void AQH_PongMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_PONG) && - (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_PONG_MINSIZE)) { - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: PONG %s (timestamp=0x%08x)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_PongMsg_GetTimestamp(msg)); - } -} - - - - - - diff --git a/aqhome/msg/msg_pong.h b/aqhome/msg/msg_pong.h deleted file mode 100644 index 0cb77bb..0000000 --- a/aqhome/msg/msg_pong.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_NODE_PONG_H -#define AQH_MSG_NODE_PONG_H - - -#include -#include - -#include -#include - - - -AQHOME_API uint32_t AQH_PongMsg_GetTimestamp(const GWEN_MSG *msg); -AQHOME_API void AQH_PongMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_reboot.c b/aqhome/msg/msg_reboot.c deleted file mode 100644 index 97e4bb9..0000000 --- a/aqhome/msg/msg_reboot.c +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_reboot.h" -#include "aqhome/msg/msg_node.h" - -#include -#include -#include -#include - -#include - - -#define AQH_MSG_OFFS_REBOOT_UID 0 /* 4 bytes */ - -#define AQH_MSG_REBOOT_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_REBOOT_UID+4) - - - -static GWEN_MSG *_rebootMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid); -static uint32_t _getUid(const GWEN_MSG *msg); -static void _rebootMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText, const char *cmd); - - - - - -GWEN_MSG *AQH_RebootRequestMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid) -{ - return _rebootMsg_new(srcAddr, destAddr, code, uid); -} - - - -uint32_t AQH_RebootRequestMsg_GetUid(const GWEN_MSG *msg) -{ - return _getUid(msg); -} - - - -void AQH_RebootRequestMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - _rebootMsg_DumpToBuffer(msg, dbuf, sText, "REBOOT_REQUEST"); -} - - - - - -GWEN_MSG *AQH_RebootResponseMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid) -{ - return _rebootMsg_new(srcAddr, destAddr, code, uid); -} - - - -uint32_t AQH_RebootResponseMsg_GetUid(const GWEN_MSG *msg) -{ - return _getUid(msg); -} - - - -void AQH_RebootResponseMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - _rebootMsg_DumpToBuffer(msg, dbuf, sText, "REBOOT_RESPONSE"); -} - - - - - -GWEN_MSG *_rebootMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid) -{ - GWEN_MSG *msg; - uint8_t *ptr; - int rv; - - msg=AQH_NodeMsg_new(destAddr, srcAddr, code, 4, NULL); - ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_REBOOT_UID; - - *(ptr++)=uid & 0xff; /* uid */ - *(ptr++)=(uid>>8) & 0xff; - *(ptr++)=(uid>>16) & 0xff; - *(ptr++)=(uid>>24) & 0xff; - - - rv=AQH_NodeMsg_AddChecksum(msg); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Msg_free(msg); - return NULL; - } - - return msg; -} - - - -uint32_t _getUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_REBOOT_UID, 0); -} - - - -void _rebootMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText, const char *cmd) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_REBOOT_MINSIZE) { - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: %s %s (uid=0x%08x)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - cmd, - sText, - _getUid(msg)); - } -} - - - - - - diff --git a/aqhome/msg/msg_reboot.h b/aqhome/msg/msg_reboot.h deleted file mode 100644 index ca93b0d..0000000 --- a/aqhome/msg/msg_reboot.h +++ /dev/null @@ -1,39 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_NODE_REBOOT_H -#define AQH_MSG_NODE_REBOOT_H - - -#include -#include - -#include -#include - - -AQHOME_API GWEN_MSG *AQH_RebootRequestMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid); - -AQHOME_API uint32_t AQH_RebootRequestMsg_GetUid(const GWEN_MSG *msg); - -AQHOME_API void AQH_RebootRequestMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -AQHOME_API GWEN_MSG *AQH_RebootResponseMsg_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t uid); - -AQHOME_API uint32_t AQH_RebootResponseMsg_GetUid(const GWEN_MSG *msg); - -AQHOME_API void AQH_RebootResponseMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_recvstats.c b/aqhome/msg/msg_recvstats.c deleted file mode 100644 index 3395a18..0000000 --- a/aqhome/msg/msg_recvstats.c +++ /dev/null @@ -1,107 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_recvstats.h" - -#include -#include -#include -#include - - - -#define AQH_MSG_OFFS_RECVSTATS_UID 0 /* 4 bytes */ -#define AQH_MSG_OFFS_RECVSTATS_PACKETSIN 4 /* 2 bytes */ -#define AQH_MSG_OFFS_RECVSTATS_CRCERRORS 6 /* 2 bytes */ -#define AQH_MSG_OFFS_RECVSTATS_IOERRORS 8 /* 2 bytes */ -#define AQH_MSG_OFFS_RECVSTATS_NOBUFFER 10 /* 2 bytes */ -#define AQH_MSG_OFFS_RECVSTATS_HANDLED 12 /* 2 bytes */ -#define AQH_MSG_OFFS_RECVSTATS_MISSED 14 /* 2 bytes */ - -#define AQH_MSG_RECVSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_IOERRORS+2) - - - -uint32_t AQH_RecvStatsMsg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_UID, 0); -} - - - -uint16_t AQH_RecvStatsMsg_GetPacketsIn(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_PACKETSIN, 0); -} - - - -uint16_t AQH_RecvStatsMsg_GetCrcErrors(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_CRCERRORS, 0); -} - - - -uint16_t AQH_RecvStatsMsg_GetIoErrors(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_IOERRORS, 0); -} - - - -uint16_t AQH_RecvStatsMsg_GetNoBufferErrors(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_NOBUFFER, 0); -} - - - -uint16_t AQH_RecvStatsMsg_GetHandled(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_HANDLED, 0); -} - - - -uint16_t AQH_RecvStatsMsg_GetMissed(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_MISSED, 0); -} - - - -void AQH_RecvStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_COMRECVSTATS) && - (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_RECVSTATS_MINSIZE)) { - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: RECVSTATS %s (uid=0x%08x, in=%d, crc errs=%d, io errs=%d, nobuf errs=%d, handled=%d, missed=%d)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_RecvStatsMsg_GetUid(msg), - AQH_RecvStatsMsg_GetPacketsIn(msg), - AQH_RecvStatsMsg_GetCrcErrors(msg), - AQH_RecvStatsMsg_GetIoErrors(msg), - AQH_RecvStatsMsg_GetNoBufferErrors(msg), - AQH_RecvStatsMsg_GetHandled(msg), - AQH_RecvStatsMsg_GetMissed(msg)); - } -} - - - - - - - diff --git a/aqhome/msg/msg_recvstats.h b/aqhome/msg/msg_recvstats.h deleted file mode 100644 index 503797f..0000000 --- a/aqhome/msg/msg_recvstats.h +++ /dev/null @@ -1,37 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_RECVSTATS_H -#define AQH_MSG_RECVSTATS_H - - -#include -#include - -#include -#include - - - -AQHOME_API uint32_t AQH_RecvStatsMsg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_RecvStatsMsg_GetPacketsIn(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_RecvStatsMsg_GetCrcErrors(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_RecvStatsMsg_GetIoErrors(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_RecvStatsMsg_GetNoBufferErrors(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_RecvStatsMsg_GetHandled(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_RecvStatsMsg_GetMissed(const GWEN_MSG *msg); - - -AQHOME_API void AQH_RecvStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_sendstats.c b/aqhome/msg/msg_sendstats.c deleted file mode 100644 index 33c9765..0000000 --- a/aqhome/msg/msg_sendstats.c +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_sendstats.h" - -#include -#include -#include -#include - - -#define AQH_MSG_OFFS_SENDSTATS_UID 0 /* 4 bytes */ -#define AQH_MSG_OFFS_SENDSTATS_PACKETSOUT 4 /* 2 bytes */ -#define AQH_MSG_OFFS_SENDSTATS_COLLISIONS 6 /* 2 bytes */ -#define AQH_MSG_OFFS_SENDSTATS_BUSY 8 /* 2 bytes */ - -#define AQH_MSG_SENDSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_BUSY+2) - - - -uint32_t AQH_SendStatsMsg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_UID, 0); -} - - - -uint16_t AQH_SendStatsMsg_GetPacketsOut(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_PACKETSOUT, 0); -} - - - -uint16_t AQH_SendStatsMsg_GetCollisions(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_COLLISIONS, 0); -} - - - -uint16_t AQH_SendStatsMsg_GetBusyErrors(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_BUSY, 0); -} - - - -void AQH_SendStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) && - (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) { - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: SENDSTATS %s (uid=0x%08x, out=%d, collisions=%d, busy line=%d)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_SendStatsMsg_GetUid(msg), - AQH_SendStatsMsg_GetPacketsOut(msg), - AQH_SendStatsMsg_GetCollisions(msg), - AQH_SendStatsMsg_GetBusyErrors(msg)); - } -} - - - - - - - diff --git a/aqhome/msg/msg_sendstats.h b/aqhome/msg/msg_sendstats.h deleted file mode 100644 index 96de04a..0000000 --- a/aqhome/msg/msg_sendstats.h +++ /dev/null @@ -1,34 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_SENDSTATS_H -#define AQH_MSG_SENDSTATS_H - - -#include -#include - -#include -#include - - - -AQHOME_API uint32_t AQH_SendStatsMsg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_SendStatsMsg_GetPacketsOut(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_SendStatsMsg_GetCollisions(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_SendStatsMsg_GetBusyErrors(const GWEN_MSG *msg); - - -AQHOME_API void AQH_SendStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_sysstats.c b/aqhome/msg/msg_sysstats.c deleted file mode 100644 index b5e15fc..0000000 --- a/aqhome/msg/msg_sysstats.c +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_sysstats.h" - -#include -#include -#include -#include - - - -#define AQH_MSG_OFFS_SYSSTATS_SECONDS 0 /* 4 bytes */ -#define AQH_MSG_OFFS_SYSSTATS_UID 4 /* 4 bytes */ -#define AQH_MSG_OFFS_SYSSTATS_COMIRQS 8 /* 2 bytes */ -#define AQH_MSG_OFFS_SYSSTATS_TIMERIRQS 10 /* 2 bytes */ - -#define AQH_MSG_MEMSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_TIMERIRQS+2) - - - -uint32_t AQH_SysStatsMsg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_UID, 0); -} - - - -uint32_t AQH_SysStatsMsg_GetSeconds(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_SECONDS, 0); -} - - -uint16_t AQH_SysStatsMsg_GetComInterrupts(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_COMIRQS, 0); -} - - - -uint16_t AQH_SysStatsMsg_GetTimerInterrupts(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_TIMERIRQS, 0); -} - - - -void AQH_SysStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: SYSSTATS %s (uid=0x%08x, uptime=%d, com irqs=%d, timer irqs=%d)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_SysStatsMsg_GetUid(msg), - AQH_SysStatsMsg_GetSeconds(msg), - AQH_SysStatsMsg_GetComInterrupts(msg), - AQH_SysStatsMsg_GetTimerInterrupts(msg)); -} - - - - - - - diff --git a/aqhome/msg/msg_sysstats.h b/aqhome/msg/msg_sysstats.h deleted file mode 100644 index aa2f3a3..0000000 --- a/aqhome/msg/msg_sysstats.h +++ /dev/null @@ -1,35 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_SYS_MEMSTATS_H -#define AQH_SYS_MEMSTATS_H - - -#include -#include - -#include -#include - - - -AQHOME_API uint32_t AQH_SysStatsMsg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint32_t AQH_SysStatsMsg_GetSeconds(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_SysStatsMsg_GetComInterrupts(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_SysStatsMsg_GetTimerInterrupts(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_SysStatsMsg_GetIdlePercentage(const GWEN_MSG *msg); - - -AQHOME_API void AQH_SysStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_value.c b/aqhome/msg/msg_value.c deleted file mode 100644 index 12306cc..0000000 --- a/aqhome/msg/msg_value.c +++ /dev/null @@ -1,100 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_value.h" - -#include -#include -#include -#include - - - - -uint32_t AQH_ValueMsg_GetTimestamp(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE_TIMESTAMP, 0); -} - - - -uint8_t AQH_ValueMsg_GetValueId(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE_VALUEID, 0); -} - - - -uint8_t AQH_ValueMsg_GetValueType(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE_VALUETYPE, 0); -} - - - -const char *AQH_ValueMsg_GetValueTypeName(const GWEN_MSG *msg) -{ - uint8_t t; - - t=AQH_ValueMsg_GetValueType(msg); - switch(t) { - case AQH_MSG_VALUE_TYPE_TEMP: return "temperature"; - case AQH_MSG_VALUE_TYPE_HUMIDITY: return "humidity"; - default: break; - } - return "unknown"; -} - - - -double AQH_ValueMsg_GetValue(const GWEN_MSG *msg) -{ - if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_VALUE) && - (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE_MINSIZE)) { - const uint8_t *ptr; - double value; - double denom; - uint16_t intDenom; - - ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN; - value=(double)((ptr[AQH_MSG_OFFS_VALUE_VALUE])+(ptr[AQH_MSG_OFFS_VALUE_VALUE+1]<<8)); - intDenom=(ptr[AQH_MSG_OFFS_VALUE_DENOM])+(ptr[AQH_MSG_OFFS_VALUE_DENOM+1]<<8); - denom=(double)(intDenom); - if (intDenom==0) - denom=1.0; - return (double)(value/denom); - - } - return 0.0; -} - - - -void AQH_ValueMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_VALUE) && - (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE_MINSIZE)) { - GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: VALUE %s (timestamp=0x%08x, value_id=0x%02x type=%s value=%f)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_ValueMsg_GetTimestamp(msg), - AQH_ValueMsg_GetValueId(msg), - AQH_ValueMsg_GetValueTypeName(msg), - AQH_ValueMsg_GetValue(msg)); - } -} - - - - - diff --git a/aqhome/msg/msg_value.h b/aqhome/msg/msg_value.h deleted file mode 100644 index f8799e0..0000000 --- a/aqhome/msg/msg_value.h +++ /dev/null @@ -1,47 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_VALUE_H -#define AQH_MSG_VALUE_H - - -#include -#include - -#include -#include - - - -#define AQH_MSG_OFFS_VALUE_TIMESTAMP 0 -#define AQH_MSG_OFFS_VALUE_VALUEID 4 -#define AQH_MSG_OFFS_VALUE_VALUETYPE 5 -#define AQH_MSG_OFFS_VALUE_VALUE 6 -#define AQH_MSG_OFFS_VALUE_DENOM 8 - -#define AQH_MSG_VALUE_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE_DENOM+2) - -#define AQH_MSG_VALUE_TYPE_TEMP 1 -#define AQH_MSG_VALUE_TYPE_HUMIDITY 2 - - - -AQHOME_API uint32_t AQH_ValueMsg_GetTimestamp(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_ValueMsg_GetValueId(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_ValueMsg_GetValueType(const GWEN_MSG *msg); -AQHOME_API double AQH_ValueMsg_GetValue(const GWEN_MSG *msg); - - -AQHOME_API void AQH_ValueMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_value2.c b/aqhome/msg/msg_value2.c deleted file mode 100644 index 7d33415..0000000 --- a/aqhome/msg/msg_value2.c +++ /dev/null @@ -1,163 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_value2.h" - -#include -#include -#include -#include - - - -#define AQH_MSG_OFFS_VALUE2_UID 0 -#define AQH_MSG_OFFS_VALUE2_VALUEID 4 -#define AQH_MSG_OFFS_VALUE2_VALUETYPE 5 -#define AQH_MSG_OFFS_VALUE2_VALUE 6 -#define AQH_MSG_OFFS_VALUE2_DENOM 8 - -#define AQH_MSG_VALUE2_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE2_DENOM+2) - - - - -uint32_t AQH_Value2Msg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE2_UID, 0); -} - - - -uint8_t AQH_Value2Msg_GetValueId(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE2_VALUEID, 0); -} - - - -uint8_t AQH_Value2Msg_GetValueType(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE2_VALUETYPE, 0); -} - - - -int16_t AQH_Value2Msg_GetValueNom(const GWEN_MSG *msg) -{ - return (int16_t) GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE2_VALUE, 0); -} - - - -int16_t AQH_Value2Msg_GetValueDenom(const GWEN_MSG *msg) -{ - return (int16_t) GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE2_DENOM, 0); -} - - - -const char *AQH_Value2Msg_GetValueTypeName(const GWEN_MSG *msg) -{ - uint8_t t; - - t=AQH_Value2Msg_GetValueType(msg); - switch(t) { - case AQH_MSG_VALUE2_TYPE_TEMP: return "temperature"; - case AQH_MSG_VALUE2_TYPE_HUMIDITY: return "humidity"; - case AQH_MSG_VALUE2_TYPE_DOOR: return "door_window"; - default: break; - } - return "unknown"; -} - - - -const char *AQH_Value2Msg_GetValueAsWindowStateString(const GWEN_MSG *msg) -{ - switch(AQH_Value2Msg_GetValueNom(msg)) { - case 0: return "closed"; - case 128: return "tilted"; - case 255: return "open"; - default: break; - } - return "unknown"; -} - - - -const char *AQH_Value2Msg_GetValueTypeUnits(const GWEN_MSG *msg) -{ - uint8_t t; - - t=AQH_Value2Msg_GetValueType(msg); - switch(t) { - case AQH_MSG_VALUE2_TYPE_TEMP: return "Celsius"; - case AQH_MSG_VALUE2_TYPE_HUMIDITY: return "%"; - case AQH_MSG_VALUE2_TYPE_DOOR: return NULL; - default: break; - } - return NULL; -} - - - -double AQH_Value2Msg_GetValue(const GWEN_MSG *msg) -{ - if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_VALUE2) && - (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE2_MINSIZE)) { - const uint8_t *ptr; - double value; - double denom; - uint16_t intDenom; - - ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN; - value=(double)((ptr[AQH_MSG_OFFS_VALUE2_VALUE])+(ptr[AQH_MSG_OFFS_VALUE2_VALUE+1]<<8)); - intDenom=(ptr[AQH_MSG_OFFS_VALUE2_DENOM])+(ptr[AQH_MSG_OFFS_VALUE2_DENOM+1]<<8); - denom=(double)(intDenom); - if (intDenom==0) - denom=1.0; - return (double)(value/denom); - - } - return 0.0; -} - - - -void AQH_Value2Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_VALUE2) && - (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE2_MINSIZE)) { - if (AQH_Value2Msg_GetValueType(msg)==AQH_MSG_VALUE2_TYPE_DOOR) - GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: VALUE2 %s (uid=0x%08x, value_id=0x%02x type=%s value=%s)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_Value2Msg_GetUid(msg), - AQH_Value2Msg_GetValueId(msg), - AQH_Value2Msg_GetValueTypeName(msg), - AQH_Value2Msg_GetValueAsWindowStateString(msg)); - else - GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: VALUE2 %s (uid=0x%08x, value_id=0x%02x type=%s value=%f)\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sText, - (unsigned int) AQH_Value2Msg_GetUid(msg), - AQH_Value2Msg_GetValueId(msg), - AQH_Value2Msg_GetValueTypeName(msg), - AQH_Value2Msg_GetValue(msg)); - } -} - - - - diff --git a/aqhome/msg/msg_value2.h b/aqhome/msg/msg_value2.h deleted file mode 100644 index 1077f48..0000000 --- a/aqhome/msg/msg_value2.h +++ /dev/null @@ -1,46 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_VALUE2_H -#define AQH_MSG_VALUE2_H - - -#include -#include - -#include -#include - - - -#define AQH_MSG_VALUE2_TYPE_TEMP 1 -#define AQH_MSG_VALUE2_TYPE_HUMIDITY 2 -#define AQH_MSG_VALUE2_TYPE_DOOR 3 - - - -AQHOME_API uint32_t AQH_Value2Msg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_Value2Msg_GetValueId(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_Value2Msg_GetValueType(const GWEN_MSG *msg); -AQHOME_API int16_t AQH_Value2Msg_GetValueNom(const GWEN_MSG *msg); -AQHOME_API int16_t AQH_Value2Msg_GetValueDenom(const GWEN_MSG *msg); - -AQHOME_API double AQH_Value2Msg_GetValue(const GWEN_MSG *msg); - -AQHOME_API const char *AQH_Value2Msg_GetValueAsWindowStateString(const GWEN_MSG *msg); -AQHOME_API const char *AQH_Value2Msg_GetValueTypeName(const GWEN_MSG *msg); -AQHOME_API const char *AQH_Value2Msg_GetValueTypeUnits(const GWEN_MSG *msg); - -AQHOME_API void AQH_Value2Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/msg/msg_value3.c b/aqhome/msg/msg_value3.c deleted file mode 100644 index 46909a8..0000000 --- a/aqhome/msg/msg_value3.c +++ /dev/null @@ -1,234 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include "aqhome/msg/msg_value3.h" - -#include -#include -#include -#include - - - -#define AQH_MSG_OFFS_VALUE3_UID 0 /* 4 bytes */ -#define AQH_MSG_OFFS_VALUE3_MSGID 4 /* 2 bytes */ -#define AQH_MSG_OFFS_VALUE3_VALUEID 6 /* 1 byte */ -#define AQH_MSG_OFFS_VALUE3_VALUETYPE 7 /* 1 byte */ -#define AQH_MSG_OFFS_VALUE3_VALUE 8 /* 2 bytes */ -#define AQH_MSG_OFFS_VALUE3_DENOM 10 /* 2 bytes */ - -#define AQH_MSG_VALUE3_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_DENOM+2) - - - -GWEN_MSG *AQH_Value3Msg_new(uint8_t srcAddr, uint8_t destAddr, - uint8_t code, uint16_t msgId, - uint8_t valueId, - uint16_t value, uint16_t denom) -{ - GWEN_MSG *msg; - uint8_t *ptr; - int rv; - - msg=AQH_NodeMsg_new(destAddr, srcAddr, code, AQH_MSG_VALUE3_MINSIZE, NULL); - ptr=GWEN_Msg_GetBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN; - - *(ptr++)=0; /* uid (empty) */ - *(ptr++)=0; - *(ptr++)=0; - *(ptr++)=0; - - *(ptr++)=msgId & 0xff; /* msgid */ - *(ptr++)=(msgId>>8) & 0xff; - - *(ptr++)=valueId; /* valueid */ - *(ptr++)=0; /* valuetype (empty) */ - - *(ptr++)=value & 0xff; /* value */ - *(ptr++)=(value>>8) & 0xff; - - *(ptr++)=denom & 0xff; /* denom */ - *(ptr++)=(denom>>8) & 0xff; - - rv=AQH_NodeMsg_AddChecksum(msg); - if (rv<0) { - DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv); - GWEN_Msg_free(msg); - return NULL; - } - - return msg; -} - - - -uint32_t AQH_Value3Msg_GetUid(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_UID, 0); -} - - - -uint16_t AQH_Value3Msg_GetMsgId(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_MSGID, 0); -} - - - -uint8_t AQH_Value3Msg_GetValueId(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_VALUEID, 0); -} - - - -uint8_t AQH_Value3Msg_GetValueType(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_VALUETYPE, 0); -} - - - -uint16_t AQH_Value3Msg_GetValueNom(const GWEN_MSG *msg) -{ - return GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_VALUE, 0); -} - - - -uint16_t AQH_Value3Msg_GetValueDenom(const GWEN_MSG *msg) -{ - return (uint16_t) GWEN_Msg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE3_DENOM, 0); -} - - - -const char *AQH_Value3Msg_GetValueTypeName(const GWEN_MSG *msg) -{ - uint8_t t; - - t=AQH_Value3Msg_GetValueType(msg); - switch(t) { - case AQH_MSG_VALUE3_TYPE_TEMP: return "temperature"; - case AQH_MSG_VALUE3_TYPE_HUMIDITY: return "humidity"; - case AQH_MSG_VALUE3_TYPE_DOOR: return "door_window"; - case AQH_MSG_VALUE3_TYPE_MOTION: return "motion"; - case AQH_MSG_VALUE3_TYPE_CO2: return "CO2"; - case AQH_MSG_VALUE3_TYPE_TVOC: return "TVOC"; - default: break; - } - return "unknown"; -} - - - -const char *AQH_Value3Msg_GetValueAsWindowStateString(const GWEN_MSG *msg) -{ - switch(AQH_Value3Msg_GetValueNom(msg)) { - case 0: return "closed"; - case 128: return "tilted"; - case 255: return "open"; - default: break; - } - return "unknown"; -} - - - -const char *AQH_Value3Msg_GetValueTypeUnits(const GWEN_MSG *msg) -{ - uint8_t t; - - t=AQH_Value3Msg_GetValueType(msg); - switch(t) { - case AQH_MSG_VALUE3_TYPE_TEMP: return "Celsius"; - case AQH_MSG_VALUE3_TYPE_HUMIDITY: return "%"; - case AQH_MSG_VALUE3_TYPE_DOOR: return NULL; - case AQH_MSG_VALUE3_TYPE_CO2: return "ppm"; - case AQH_MSG_VALUE3_TYPE_TVOC: return "ppb"; - default: break; - } - return NULL; -} - - - -double AQH_Value3Msg_GetValue(const GWEN_MSG *msg) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE3_MINSIZE) { - const uint8_t *ptr; - double value; - double denom; - uint16_t intDenom; - - ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN; - value=(double)((ptr[AQH_MSG_OFFS_VALUE3_VALUE])+(ptr[AQH_MSG_OFFS_VALUE3_VALUE+1]<<8)); - intDenom=(ptr[AQH_MSG_OFFS_VALUE3_DENOM])+(ptr[AQH_MSG_OFFS_VALUE3_DENOM+1]<<8); - denom=(double)(intDenom); - if (intDenom==0) - denom=1.0; - return (double)(value/denom); - - } - return 0.0; -} - - - -void AQH_Value3Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText) -{ - if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_VALUE3_MINSIZE) { - const char *sCmd; - - switch(AQH_NodeMsg_GetMsgType(msg)) { - case AQH_MSG_TYPE_VALUE_REPORT: sCmd="report"; break; - case AQH_MSG_TYPE_VALUE_SET: sCmd="set"; break; - case AQH_MSG_TYPE_VALUE_SET_ACK: sCmd="ack"; break; - case AQH_MSG_TYPE_VALUE_SET_NACK: sCmd="nack"; break; - default: sCmd="unknown"; break; - } - - if (AQH_Value3Msg_GetValueType(msg)==AQH_MSG_VALUE3_TYPE_DOOR) - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: VALUE3(%s) %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%s [%04x/%04x])\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sCmd, - sText, - (unsigned int) AQH_Value3Msg_GetUid(msg), - (unsigned int)AQH_Value3Msg_GetMsgId(msg), - AQH_Value3Msg_GetValueId(msg), - AQH_Value3Msg_GetValueTypeName(msg), - AQH_Value3Msg_GetValueAsWindowStateString(msg), - AQH_Value3Msg_GetValueNom(msg), - AQH_Value3Msg_GetValueDenom(msg)); - else - GWEN_Buffer_AppendArgs(dbuf, - "0x%02x->0x%02x: VALUE3(%s) %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%f [%04x/%04x])\n", - AQH_NodeMsg_GetSourceAddress(msg), - AQH_NodeMsg_GetDestAddress(msg), - sCmd, - sText, - (unsigned int) AQH_Value3Msg_GetUid(msg), - (unsigned int)AQH_Value3Msg_GetMsgId(msg), - AQH_Value3Msg_GetValueId(msg), - AQH_Value3Msg_GetValueTypeName(msg), - AQH_Value3Msg_GetValue(msg), - AQH_Value3Msg_GetValueNom(msg), - AQH_Value3Msg_GetValueDenom(msg)); - } -} - - - - diff --git a/aqhome/msg/msg_value3.h b/aqhome/msg/msg_value3.h deleted file mode 100644 index f3b4dea..0000000 --- a/aqhome/msg/msg_value3.h +++ /dev/null @@ -1,54 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2024 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQH_MSG_VALUE3_H -#define AQH_MSG_VALUE3_H - - -#include -#include - -#include -#include - - - -#define AQH_MSG_VALUE3_TYPE_TEMP 1 -#define AQH_MSG_VALUE3_TYPE_HUMIDITY 2 -#define AQH_MSG_VALUE3_TYPE_DOOR 3 -#define AQH_MSG_VALUE3_TYPE_MOTION 6 -#define AQH_MSG_VALUE3_TYPE_CO2 7 -#define AQH_MSG_VALUE3_TYPE_TVOC 8 - - -AQHOME_API GWEN_MSG *AQH_Value3Msg_new(uint8_t srcAddr, uint8_t destAddr, - uint8_t code, uint16_t msgId, - uint8_t valueId, - uint16_t value, uint16_t denom); - -AQHOME_API uint32_t AQH_Value3Msg_GetUid(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_Value3Msg_GetMsgId(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_Value3Msg_GetValueId(const GWEN_MSG *msg); -AQHOME_API uint8_t AQH_Value3Msg_GetValueType(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_Value3Msg_GetValueNom(const GWEN_MSG *msg); -AQHOME_API uint16_t AQH_Value3Msg_GetValueDenom(const GWEN_MSG *msg); - -AQHOME_API double AQH_Value3Msg_GetValue(const GWEN_MSG *msg); - -AQHOME_API const char *AQH_Value3Msg_GetValueAsWindowStateString(const GWEN_MSG *msg); -AQHOME_API const char *AQH_Value3Msg_GetValueTypeName(const GWEN_MSG *msg); -AQHOME_API const char *AQH_Value3Msg_GetValueTypeUnits(const GWEN_MSG *msg); - -AQHOME_API void AQH_Value3Msg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText); - - - -#endif - - - diff --git a/aqhome/service/0BUILD b/aqhome/service/0BUILD deleted file mode 100644 index 20ac23e..0000000 --- a/aqhome/service/0BUILD +++ /dev/null @@ -1,82 +0,0 @@ - - - - - - - - $(gwenhywfar_cflags) - -I$(topsrcdir) - -I$(topbuilddir) - - - - --include=$(builddir) - --include=$(srcdir) - - - - - - $(visibility_cflags) - - - - --api=AQHOME_API - - - - module.t2d - moduleperms.t2d - role.t2d - user.t2d - session.t2d - permdef.t2d - - - - - - - - - - - - - - - $(local/built_headers_pub) - - - - - service.h - - - - - service_p.h - - - - - $(local/typefiles) - - service.c - - - - - - - - - - - - - - - - diff --git a/aqhome/service/module.t2d b/aqhome/service/module.t2d deleted file mode 100644 index 790af45..0000000 --- a/aqhome/service/module.t2d +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - AQH_MODULE - AQH_Module - module - - - with_inherit - with_xml - with_db - with_list1 - with_list2 - nodup - nocopy - - - -
aqhome/api.h
-
gwenhywfar/error.h
-
aqhome/service/role.h
-
aqhome/service/permdef.h
-
- - - - -
- - - - - - 0 - 0 - public - with_getbymember - - - - 0 - 0 - public - own with_getbymember - - - - 0 - 0 - public - own - - - - 0 - 0 - public - - - - - NULL - NULL - public - own - none - none - - - - NULL - NULL - public - own - none - none - - - - -
- -
- diff --git a/aqhome/service/moduleperms.t2d b/aqhome/service/moduleperms.t2d deleted file mode 100644 index ed8d35b..0000000 --- a/aqhome/service/moduleperms.t2d +++ /dev/null @@ -1,75 +0,0 @@ - - - - - - - - AQH_MODULE_PERMS - AQH_ModulePerms - moduleperms - - - with_inherit - with_xml - with_db - with_list1 - with_list2 - - - -
aqhome/api.h
-
gwenhywfar/error.h
-
aqhome/service/role.h
-
- - - - -
- - - - - - 0 - 0 - public - with_getbymember - - - - 0 - 0 - public - - - - - 0 - 0 - public - - - - - 0 - 0 - public - - - - - - 0 - 0 - public - volatile - - - - -
- -
- diff --git a/aqhome/service/permdef.t2d b/aqhome/service/permdef.t2d deleted file mode 100644 index 63df78b..0000000 --- a/aqhome/service/permdef.t2d +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - AQH_PERMDEF - AQH_PermDef - permdef - - - with_xml - with_db - with_list1 - nodup - nocopy - - - -
aqhome/api.h
-
- - - - -
- - - - - - NULL - NULL - public - own with_getbymember - - - - NULL - NULL - public - own with_getbymember - - - - 0 - 0 - public - own with_getbymember - - - - NULL - NULL - public - own - - - - -
- -
- diff --git a/aqhome/service/role.t2d b/aqhome/service/role.t2d deleted file mode 100644 index da88084..0000000 --- a/aqhome/service/role.t2d +++ /dev/null @@ -1,72 +0,0 @@ - - - - - - - - AQH_ROLE - AQH_Role - role - - - with_xml - with_db - with_list1 - with_list2 - - - -
aqhome/api.h
-
gwenhywfar/error.h
-
- - - - -
- - - - - - 0 - 0 - public - with_getbymember - - - - 0 - 0 - public - own - - - - 0 - 0 - public - - - - - 0 - 0 - public - - - - - 0 - 0 - public - - - - - -
- -
- diff --git a/aqhome/service/service.c b/aqhome/service/service.c deleted file mode 100644 index 5a04bac..0000000 --- a/aqhome/service/service.c +++ /dev/null @@ -1,190 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifdef HAVE_CONFIG_H -# include -#endif - -//#define DISABLE_DEBUGLOG - - -#include "aqhome/service/service_p.h" - -#include - - - -GWEN_INHERIT_FUNCTIONS(AQH_SERVICE); -GWEN_LIST_FUNCTIONS(AQH_SERVICE, AQH_Service); - - - - -AQH_SERVICE *AQH_Service_new(void) -{ - AQH_SERVICE *sv; - - GWEN_NEW_OBJECT(AQH_SERVICE, sv); - GWEN_INHERIT_INIT(AQH_SERVICE, sv); - GWEN_LIST_INIT(AQH_SERVICE, sv); - - sv->userList=AQH_User_List_new(); - sv->moduleList=AQH_Module_List_new(); - sv->sessionList=AQH_Session_List_new(); - - return sv; -} - - - -void AQH_Service_free(AQH_SERVICE *sv) -{ - if (sv) { - GWEN_LIST_FINI(AQH_SERVICE, sv); - GWEN_INHERIT_FINI(AQH_SERVICE, sv); - - AQH_User_List_free(sv->userList); - AQH_Module_List_free(sv->moduleList); - AQH_Session_List_free(sv->sessionList); - - GWEN_FREE_OBJECT(sv); - } -} - - - -AQH_USER_LIST *AQH_Service_GetUserList(const AQH_SERVICE *sv) -{ - return sv?sv->userList:NULL; -} - - - -AQH_USER *AQH_Service_GetUserById(const AQH_SERVICE *sv, uint32_t id) -{ - return sv?AQH_User_List_GetById(sv->userList, id):NULL; -} - - - -AQH_USER *AQH_Service_GetUserByAlias(const AQH_SERVICE *sv, const char *s) -{ - return sv?AQH_User_List_GetByAlias(sv->userList, s):NULL; -} - - - -void AQH_Service_AddUser(AQH_SERVICE *sv, AQH_USER *u) -{ - if (sv && u) - AQH_User_List_Add(u, sv->userList); -} - - - -void AQH_Service_DelUser(AQH_SERVICE *sv, uint32_t userId) -{ - if (sv && userId) { - AQH_USER *u; - - u=AQH_User_List_GetById(sv->userList, userId); - if (u) { - AQH_User_List_Del(u); - AQH_User_free(u); - } - } -} - - - -AQH_MODULE_LIST *AQH_Service_GetModuleList(const AQH_SERVICE *sv) -{ - return sv?sv->moduleList:NULL; -} - - - -AQH_MODULE *AQH_Service_GetModuleById(const AQH_SERVICE *sv, uint32_t id) -{ - return sv?AQH_Module_List_GetById(sv->moduleList, id):NULL; -} - - - -AQH_MODULE *AQH_Service_GetModuleByName(const AQH_SERVICE *sv, const char *s) -{ - return sv?AQH_Module_List_GetByName(sv->moduleList, s):NULL; -} - - - -void AQH_Service_AddModule(AQH_SERVICE *sv, AQH_MODULE *m) -{ - if (sv && m) - AQH_Module_List_Add(m, sv->moduleList); -} - - - -void AQH_Service_DelModule(AQH_SERVICE *sv, uint32_t moduleId) -{ - if (sv && moduleId) { - AQH_MODULE *m; - - m=AQH_Module_List_GetById(sv->moduleList, moduleId); - if (m) { - AQH_Module_List_Del(m); - AQH_Module_free(m); - } - } -} - - - -AQH_SESSION_LIST *AQH_Service_GetSessionList(const AQH_SERVICE *sv) -{ - return sv?sv->sessionList:NULL; -} - - - -AQH_SESSION *AQH_Service_GetSessionByUid(const AQH_SERVICE *sv, const char *sessionUid) -{ - return sv?AQH_Session_List_GetByUid(sv->sessionList, sessionUid):NULL; -} - - - -void AQH_Service_AddSession(AQH_SERVICE *sv, AQH_SESSION *session) -{ - if (sv && session) - AQH_Session_List_Add(session, sv->sessionList); -} - - - -void AQH_Service_DelSession(AQH_SERVICE *sv, const char *sid) -{ - if (sv && sid && *sid) { - AQH_SESSION *session; - - session=AQH_Session_List_GetByUid(sv->sessionList, sid); - if (session) { - AQH_Session_List_Del(session); - AQH_Session_free(session); - } - } -} - - - - - - - - diff --git a/aqhome/service/service.h b/aqhome/service/service.h deleted file mode 100644 index e5363b8..0000000 --- a/aqhome/service/service.h +++ /dev/null @@ -1,53 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQHOME_SERVICE_H -#define AQHOME_SERVICE_H - - -#include - -#include -#include - - -typedef struct AQH_SERVICE AQH_SERVICE; -GWEN_INHERIT_FUNCTION_LIB_DEFS(AQH_SERVICE, AQHOME_API); -GWEN_LIST_FUNCTION_LIB_DEFS(AQH_SERVICE, AQH_Service, AQHOME_API); - - -#include "aqhome/service/user.h" -#include "aqhome/service/module.h" -#include "aqhome/service/session.h" - - - -AQHOME_API AQH_SERVICE *AQH_Service_new(void); -AQHOME_API void AQH_Service_free(AQH_SERVICE *sv); - -AQHOME_API AQH_USER_LIST *AQH_Service_GetUserList(const AQH_SERVICE *sv); -AQHOME_API AQH_USER *AQH_Service_GetUserById(const AQH_SERVICE *sv, uint32_t id); -AQHOME_API AQH_USER *AQH_Service_GetUserByAlias(const AQH_SERVICE *sv, const char *s); -AQHOME_API void AQH_Service_AddUser(AQH_SERVICE *sv, AQH_USER *u); -AQHOME_API void AQH_Service_DelUser(AQH_SERVICE *sv, uint32_t userId); - - -AQHOME_API AQH_MODULE_LIST *AQH_Service_GetModuleList(const AQH_SERVICE *sv); -AQHOME_API AQH_MODULE *AQH_Service_GetModuleById(const AQH_SERVICE *sv, uint32_t id); -AQHOME_API AQH_MODULE *AQH_Service_GetModuleByName(const AQH_SERVICE *sv, const char *s); -AQHOME_API void AQH_Service_AddModule(AQH_SERVICE *sv, AQH_MODULE *m); -AQHOME_API void AQH_Service_DelModule(AQH_SERVICE *sv, uint32_t moduleId); - -AQHOME_API AQH_SESSION_LIST *AQH_Service_GetSessionList(const AQH_SERVICE *sv); -AQHOME_API AQH_SESSION *AQH_Service_GetSessionByUid(const AQH_SERVICE *sv, const char *sessionUid); -AQHOME_API void AQH_Service_AddSession(AQH_SERVICE *sv, AQH_SESSION *session); -AQHOME_API void AQH_Service_DelSession(AQH_SERVICE *sv, const char *sid); - - - -#endif diff --git a/aqhome/service/service_p.h b/aqhome/service/service_p.h deleted file mode 100644 index 1e9a1ab..0000000 --- a/aqhome/service/service_p.h +++ /dev/null @@ -1,29 +0,0 @@ -/**************************************************************************** - * This file is part of the project AqHome. - * AqHome (c) by 2023 Martin Preuss, all rights reserved. - * - * The license for this file can be found in the file COPYING which you - * should have received along with this file. - ****************************************************************************/ - -#ifndef AQHOME_SERVICE_P_H -#define AQHOME_SERVICE_P_H - - -#include "aqhome/service/service.h" - - -struct AQH_SERVICE { - GWEN_INHERIT_ELEMENT(AQH_SERVICE); - GWEN_LIST_ELEMENT(AQH_SERVICE); - - AQH_USER_LIST *userList; - AQH_MODULE_LIST *moduleList; - AQH_SESSION_LIST *sessionList; - -}; - - - - -#endif diff --git a/aqhome/service/session.t2d b/aqhome/service/session.t2d deleted file mode 100644 index 1b14585..0000000 --- a/aqhome/service/session.t2d +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - AQH_SESSION - AQH_Session - session - - - with_xml - with_db - with_list1 - with_list2 - nodup - nocopy - - - -
aqhome/api.h
-
gwenhywfar/error.h
-
gwenhywfar/timestamp.h
-
aqhome/service/user.h
-
- - - - -
- - - - - - - - - - - - - - 0 - 0 - public - own with_getbymember - - - - 0 - 0 - public - with_flags - - - - NULL - NULL - public - own - - - - 0 - 0 - public - - - - - 0 - 0 - public - own - - - - NULL - NULL - public - own - - - - NULL - NULL - public - own - - - - - NULL - NULL - public - assign - none - volatile nodup nocopy - - - - - - 0 - 0 - public - with_flags volatile - - - - -
- -
- diff --git a/aqhome/service/user.t2d b/aqhome/service/user.t2d deleted file mode 100644 index 1c46e13..0000000 --- a/aqhome/service/user.t2d +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - - AQH_USER - AQH_User - user - - - with_xml - with_db - with_list1 - with_list2 - with_refcount - nodup - nocopy - - - -
aqhome/api.h
-
gwenhywfar/error.h
-
gwenhywfar/timestamp.h
-
aqhome/service/moduleperms.h
-
- - - - -
- - - - - - - - - - - - - - User suspended - - - - Waiting for email confirmation - - - - Waiting for approval by admin - - - - - - - - - - - 0 - 0 - public - with_getbymember - - - - 0 - 0 - public - with_flags - - - - 0 - 0 - public - - - - - 0 - 0 - public - own - - - - 0 - 0 - public - own with_getbymember - - - - 0 - 0 - public - own - - - - 0 - 0 - public - own - - - - 0 - 0 - public - own - - - - NULL - NULL - public - own - - - - NULL - NULL - public - own - - - - NULL - NULL - public - none - none - own - - - - - 0 - 0 - public - volatile with_flags - - - - -
- -
-