spc-proto.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*
  24. * File: spc-proto.h $XConsortium: spc-proto.h /main/3 1995/10/26 15:43:39 rswiston $
  25. * Language: C
  26. *
  27. * (c) Copyright 1988, Hewlett-Packard Company, all rights reserved.
  28. *
  29. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  30. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  31. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  32. * (c) Copyright 1993, 1994 Novell, Inc. *
  33. */
  34. #ifndef _spc_proto_h
  35. #define _spc_proto_h
  36. /*
  37. * Commands which are known to spcd and clients
  38. */
  39. /* The internet service */
  40. #define SPC_SERVICE (XeString)"dtspc" /* The name of the registered service */
  41. #define SPC_PROTOCOL (XeString)"tcp" /* The name of the registered protocol */
  42. /* MUST be a DECIMAL number as "%d" */
  43. #define SPC_PROTOCOL_VERSION_CDE_BASE 1000
  44. #define SPC_PROTOCOL_VERSION SPC_PROTOCOL_VERSION_CDE_BASE
  45. /* is used to read the string version */
  46. #define SPC_PROTOCOL_VERSION_CDE_BASE_STR "1000"
  47. #define SPC_PROTOCOL_VERSION_STR SPC_PROTOCOL_VERSION_CDE_BASE_STR
  48. /* We could make this user config for old domain systems? */
  49. #define SPC_UNKNOWN_HOSTINFO_STR "HP-UX:7.0:*"
  50. /*
  51. **
  52. ** Pseudo-filenames used for validating user
  53. **
  54. */
  55. #define PASSED_FILE_NAME (XeString)"<!passed>!"
  56. #define FAILED_FILE_NAME (XeString)"<!failed>!"
  57. /*
  58. *** Protocol command numbers. These MUST remain in the same order
  59. *** to work with previous version of the spcd
  60. */
  61. /* Connections to the server */
  62. #define APPLICATION_DATA 0 /* send data to subprocess */
  63. #define APPLICATION_STDOUT 1 /* data from subprocess */
  64. #define APPLICATION_STDERR 2 /* error messages from subprocess */
  65. #define ABORT 3 /* Client aborted */
  66. #define REGISTER 4 /* Register client */
  67. #define UNREGISTER 5 /* Unregister client */
  68. /* Channel requests */
  69. #define CHANNEL_OPEN 6 /* enable this channel for read/write */
  70. #define CHANNEL_CLOSE 7 /* no more i/o to this channel (send EOF) */
  71. #define CHANNEL_RESET 8 /* reset this channel */
  72. #define CHANNEL_ATTACH 9 /* attach PTY device to this channel */
  73. /* Application messages, client -> server */
  74. #define APPLICATION_SPAWN 10 /* start up subprocess */
  75. #define APPLICATION_SIGNAL 11 /* send signal to subprocess */
  76. /* application messages, server -> client */
  77. #define APPLICATION_DIED 12 /* sent when subprocess dies */
  78. #define SERVER_ERROR 13 /* server has detected an error */
  79. #define REPLY 14
  80. #define SERVER_DEBUG 15
  81. #define ENVIRON_RESET 16
  82. /* Query / reply protocols, client -> server -> client */
  83. #define QUERY_DEVICES 17
  84. #define DEVICE_REPLY 18
  85. #define QUERY_LOGFILE 19
  86. #define LOGFILE_REPLY 20
  87. /* Application messages, client -> server */
  88. #define DELETE_LOGFILE 21
  89. #define RESET_TERMIOS 23
  90. /* New B.00 protocol requests */
  91. #define CHANNEL_SEND_EOF 24 /* Send EOF to standard input of sub process */
  92. #define CHANNEL_TERMIOS 25 /* Send termios info for a particular pty */
  93. #define APP_B00_SPAWN 26 /* Enhanced spawn */
  94. #define NREQS 27 /* total number of requests. If
  95. any are added, this should constant
  96. should reflect the new total */
  97. #define PROT_TO_CONNECTOR(a) a
  98. #define CONNECTOR_TO_PROT(a) a
  99. #define PDRP(_pdata) _pdata->data+REQUEST_HEADER_LENGTH
  100. #define WRITE_INT(pdata, val)\
  101. sprintf_len(PDRP(pdata), (XeString)"%x", val)
  102. #define READ_INT(pdata, val) sscanf(PDRP(pdata), (XeString)"%x", &val)
  103. #define WRITE_STRING(pdata, name)\
  104. sprintf_len(PDRP(pdata), (XeString)"%s", name)
  105. #define READ_STRING(pdata, name) sscanf(PDRP(pdata), (XeString)"%s", name)
  106. #define READ_STRING_NO_COPY(pdata, name) (name = PDRP(pdata))
  107. #define WRITE_ABORT WRITE_INT
  108. #define READ_ABORT READ_INT
  109. #define WRITE_OPEN WRITE_INT
  110. #define READ_OPEN READ_INT
  111. #define WRITE_ATTACH WRITE_INT
  112. #define READ_ATTACH READ_INT
  113. #define WRITE_APPLICATION_DIED WRITE_INT
  114. #define READ_APPLICATION_DIED READ_INT
  115. #define WRITE_DEBUG WRITE_STRING
  116. #define READ_DEBUG READ_STRING
  117. #define WRITE_ERROR WRITE_INT
  118. #define READ_ERROR READ_INT
  119. #define WRITE_REGISTER(pdata, name, passwd, proto_ver, hostinfo)\
  120. sprint_register_data(PDRP(pdata), name, passwd, proto_ver, hostinfo)
  121. #define READ_REGISTER(pdata, name, passwd, proto_rev, hostinfo)\
  122. sscan_register_data(PDRP(pdata), &name, &passwd, &proto_rev, &hostinfo)
  123. #define WRITE_REPLY(pdata, val, err)\
  124. sprintf_len(PDRP(pdata), (XeString)"%x %x", val, err)
  125. #define READ_REPLY(pdata, val, err)\
  126. sscanf(PDRP(pdata), (XeString)"%x %x", &val, &err)
  127. #define WRITE_DEVICE_REPLY(pdata, m0, s0, m1, s1, m2, s2) \
  128. sprint_device_data(PDRP(pdata), m0, s0, m1, s1, m2, s2)
  129. #define READ_DEVICE_REPLY(pdata, m0, s0, m1, s1, m2, s2) \
  130. sscan_device_data(PDRP(pdata), m0, s0, m1, s1, m2, s2)
  131. #define WRITE_LOGFILE_REPLY(pdata, logfile, proto_ver, hostinfo) \
  132. sprint_logfile_data(PDRP(pdata), logfile, proto_ver, hostinfo)
  133. #define READ_LOGFILE_REPLY(pdata, logfile, proto_ver, hostinfo) \
  134. sscan_logfile_data(PDRP(pdata), logfile, proto_ver, hostinfo)
  135. #define WRITE_APPLICATION_SPAWN(pdata, path, dir, argv, envp) \
  136. sprint_application_data(PDRP(pdata), (XeString)"%s %d %d ", \
  137. path, dir, argv, envp, REQUEST_HEADER_LENGTH)
  138. #define READ_APPLICATION_SPAWN(pdata, path, dir, argv, envp) \
  139. sscan_application_data(PDRP(pdata), (XeString)"%s %d %d ", \
  140. &path, &dir, &argv, &envp, REQUEST_HEADER_LENGTH)
  141. #define WRITE_ENVIRON_RESET(pdata, numenv) \
  142. sprintf_len(PDRP(pdata), (XeString)"%d ", numenv)
  143. #define READ_ENVIRON_RESET(pdata, numenv) \
  144. sscanf(PDRP(pdata), (XeString)"%d ", &numenv)
  145. #define WRITE_APP_DATA(pdata, buffer, len) \
  146. (memcpy(PDRP(pdata), buffer, len), len)
  147. /* New B.00 protocol requests */
  148. #define WRITE_TERMIOS(pdata, connector, side, buffer) \
  149. sprintf_len(PDRP(pdata), (XeString)"%d %d %s", connector, side, buffer)
  150. #define READ_TERMIOS(pdata, connector, side, buffer) \
  151. sscanf(PDRP(pdata), (XeString)"%d %d %s", &connector, &side, buffer)
  152. /* Writing a header is special, as we don't want to be offset by
  153. REQUEST_HEADER_LENGTH */
  154. #define WRITE_HEADER(pdata, cid, type, len, seq) \
  155. sprintf_len(pdata->data, (XeString)"%08x%02x%04x%04x", cid, type, len, seq)
  156. #define READ_HEADER(pdata, cid, type, len, seq) \
  157. sscanf(pdata->data, (XeString)"%8x%2x%4x%4x", cid, type, len, seq)
  158. #define min(a, b) (((a) < (b)) ? (a) : (b))
  159. /*
  160. **
  161. ** The test here is reversed, that is, we check only for those
  162. ** requests where there is no reply expected, and assume the other
  163. ** ones do expect replies.
  164. **
  165. */
  166. #define NO_REPLY_VAL (-1)
  167. #define REPLY_EXPECTED(a, retval) \
  168. (((a==REPLY) || \
  169. (a==APPLICATION_DATA) || \
  170. (a==APPLICATION_STDOUT) || \
  171. (a==APPLICATION_STDERR) || \
  172. (a==REGISTER) || \
  173. (a==QUERY_LOGFILE) || \
  174. (a==QUERY_DEVICES) || \
  175. (a==ABORT) || \
  176. (a==SERVER_ERROR) \
  177. ) ? NO_REPLY_VAL : retval)
  178. typedef struct _prot_request {
  179. buffered_data_ptr dataptr;
  180. int seqno;
  181. int request_type;
  182. SPC_Channel_Ptr channel;
  183. struct _prot_request *next;
  184. } protocol_request, *protocol_request_ptr;
  185. typedef int (*protocol_request_handler)(protocol_request_ptr);
  186. /* spc-proto.c */
  187. buffered_data_ptr SPC_New_Buffered_Data_Ptr (void);
  188. void SPC_Reset_Protocol_Ptr (protocol_request_ptr prot, SPC_Channel_Ptr channel, XeChar req, int len);
  189. protocol_request_ptr SPC_New_Protocol_Ptr (SPC_Channel_Ptr channel, XeChar req, int len);
  190. void SPC_Free_Protocol_Ptr (protocol_request_ptr prot);
  191. SPC_Channel_Ptr SPC_Lookup_Channel (int cid, SPC_Connection_Ptr connection);
  192. SPC_Connection_Ptr SPC_Alloc_Connection (void);
  193. SPC_Connection_Ptr SPC_Lookup_Connection (XeString hostname);
  194. SPC_Connection_Ptr SPC_Lookup_Connection_Fd (int fd);
  195. SPC_Connection_Ptr SPC_Make_Connection (XeString hostname);
  196. void SPC_Add_Connection (SPC_Connection_Ptr connection);
  197. void SPC_Close_Connection (SPC_Connection_Ptr connection);
  198. int SPC_Read_Chars (SPC_Connection_Ptr connection, int request_len, XeString charptr);
  199. int SPC_Write_Chars (int fd, XeString charptr, int request_len);
  200. protocol_request_ptr SPC_Read_Protocol (SPC_Connection_Ptr connection);
  201. protocol_request_ptr SPC_Filter_Connection (SPC_Connection_Ptr connection, SPC_Channel_Ptr channel, int reqtype, int deletep);
  202. void SPC_Flush_Queued_Data (SPC_Channel_Ptr channel);
  203. int SPC_Read_Remote_Data (SPC_Channel_Ptr channel, int connector, XeString client_buffer, int nbytes);
  204. int print_protocol_request (XeString name, protocol_request_ptr proto);
  205. int SPC_Write_Protocol_Request (SPC_Connection_Ptr connection, SPC_Channel_Ptr channel, int request, ...);
  206. int SPC_Write_Single_Prot_Request (SPC_Connection_Ptr connection, XeString name, protocol_request_ptr prot);
  207. int SPC_Waitfor_Reply (SPC_Connection_Ptr connection, SPC_Channel_Ptr channel, int seqno);
  208. int SPC_Dispatch_Protocol (protocol_request_ptr proto, protocol_request_handler *);
  209. int SPC_Write_Reply (SPC_Connection_Ptr conn, protocol_request_ptr proto, int retval, int errval);
  210. int SPC_Send_Environ (SPC_Connection_Ptr connection, protocol_request_ptr prot);
  211. int sprint_counted_string (XeString buf, int count, XeString *vect, int limit);
  212. XeString *sscan_counted_string (XeString buf, XeString *newbuf);
  213. int sprint_application_data (XeString buf, XeString fmt, XeString path, XeString dir, XeString *argv, XeString *envp, int chars_used);
  214. int sscan_application_data (XeString buf, XeString fmt, XeString *path, XeString *dir, XeString **argv, XeString **envp, int offset);
  215. int sprint_device_data (XeString buf, XeString m0, XeString s0, XeString m1, XeString s1, XeString m2, XeString s2);
  216. int sscan_device_data (XeString buf, XeString *m0, XeString *s0, XeString *m1, XeString *s1, XeString *m2, XeString *s2);
  217. int sprint_logfile_data (XeString buf, XeString logfile, XeString proto_ver, XeString hostinfo);
  218. int sscan_logfile_data (XeString buf, XeString *logfile, XeString *proto_ver, XeString *hostinfo);
  219. int sprint_register_data (XeString buf, XeString username, XeString passwd, XeString proto_ver, XeString hostinfo);
  220. int sscan_register_data (XeString buf, XeString *username, XeString *passwd, XeString *proto_ver, XeString *hostinfo);
  221. int SPC_Query_Devices (SPC_Channel_Ptr channel);
  222. int SPC_Query_Logfile (SPC_Channel_Ptr channel);
  223. int SPC_Validate_User (XeString hostname, SPC_Connection_Ptr connection);
  224. int SPC_Get_Termio (protocol_request_ptr prot_request);
  225. int SPC_Get_Termios (protocol_request_ptr prot_request);
  226. XeString SPC_LocalHostinfo(void);
  227. int SPC_Send_Multi_Packet(SPC_Connection_Ptr connection,
  228. protocol_request_ptr prot,
  229. char **str_vect,
  230. int num_str,
  231. int req,
  232. XeString name,
  233. int errid);
  234. char **SPC_Get_Multi_Packet(SPC_Connection_Ptr connection,
  235. protocol_request_ptr prot,
  236. char **out,
  237. int *outlen,
  238. int request,
  239. XeString name);
  240. #endif /* _spc_proto_h */