1 /** @file
2 
3   A brief file description
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 /*****************************************************************************
25  * Filename: NetworkUtilsRemote.h
26  * Purpose: This file contains functions used by remote api client to
27  *          marshal requests to TM and unmarshal replies from TM.
28  *          Also contains functions used to store information specific
29  *          to a remote client connection.
30  * Created: 8/9/00
31  * Created by: lant
32  *
33  ***************************************************************************/
34 
35 #pragma once
36 
37 #include "mgmtapi.h"
38 #include "ts/apidefs.h"
39 #include "NetworkMessage.h"
40 #include "EventCallback.h"
41 
42 extern int main_socket_fd;
43 extern int event_socket_fd;
44 extern CallbackTable *remote_event_callbacks;
45 
46 // From CoreAPIRemote.cc
47 extern ink_thread ts_event_thread;
48 extern TSInitOptionT ts_init_options;
49 
50 /**********************************************************************
51  * Socket Helper Functions
52  **********************************************************************/
53 void set_socket_paths(const char *path);
54 
55 /* The following functions are specific for a client connection; uses
56  * the client connection information stored in the variables in
57  * NetworkUtilsRemote.cc
58  */
59 TSMgmtError
60 ts_connect(); /* TODO: update documentation, Renamed due to conflict with connect() in <sys/socket.h> on some platforms*/
61 TSMgmtError disconnect();
62 TSMgmtError reconnect();
63 TSMgmtError reconnect_loop(int num_attempts);
64 
65 void *socket_test_thread(void *arg);
66 void *event_poll_thread_main(void *arg);
67 
68 struct mgmtapi_sender : public mgmt_message_sender {
mgmtapi_sendermgmtapi_sender69   explicit mgmtapi_sender(int _fd) : fd(_fd) {}
70   TSMgmtError send(void *msg, size_t msglen) const override;
71   bool
is_connectedmgmtapi_sender72   is_connected() const override
73   {
74     return fd != ts::NO_FD;
75   }
76 
77   int fd;
78 };
79 
80 #define MGMTAPI_SEND_MESSAGE(fd, optype, ...) send_mgmt_request(mgmtapi_sender(fd), (optype), __VA_ARGS__)
81 
82 #define MGMTAPI_MGMT_SOCKET_NAME "mgmtapi.sock"
83 #define MGMTAPI_EVENT_SOCKET_NAME "eventapi.sock"
84 
85 /*****************************************************************************
86  * Marshalling (create requests)
87  *****************************************************************************/
88 
89 TSMgmtError send_register_all_callbacks(int fd, CallbackTable *cb_table);
90 TSMgmtError send_unregister_all_callbacks(int fd, CallbackTable *cb_table);
91 
92 /*****************************************************************************
93  * Un-marshalling (parse responses)
94  *****************************************************************************/
95 TSMgmtError parse_generic_response(OpType optype, int fd);
96