spc-proto.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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_TERMIO 22 /* This is obsolete, (hpux binary version) */
  90. #define RESET_TERMIOS 23
  91. /* New B.00 protocol requests */
  92. #define CHANNEL_SEND_EOF 24 /* Send EOF to standard input of sub process */
  93. #define CHANNEL_TERMIOS 25 /* Send termios info for a particular pty */
  94. #define APP_B00_SPAWN 26 /* Enhanced spawn */
  95. #define NREQS 27 /* total number of requests. If
  96. any are added, this should constant
  97. should reflect the new total */
  98. #define PROT_TO_CONNECTOR(a) a
  99. #define CONNECTOR_TO_PROT(a) a
  100. #define PDRP(_pdata) _pdata->data+REQUEST_HEADER_LENGTH
  101. #define WRITE_INT(pdata, val)\
  102. sprintf_len(PDRP(pdata), (XeString)"%x", val)
  103. #define READ_INT(pdata, val) sscanf(PDRP(pdata), (XeString)"%x", &val)
  104. #define WRITE_STRING(pdata, name)\
  105. sprintf_len(PDRP(pdata), (XeString)"%s", name)
  106. #define READ_STRING(pdata, name) sscanf(PDRP(pdata), (XeString)"%s", name)
  107. #define READ_STRING_NO_COPY(pdata, name) (name = PDRP(pdata))
  108. #define WRITE_ABORT WRITE_INT
  109. #define READ_ABORT READ_INT
  110. #define WRITE_OPEN WRITE_INT
  111. #define READ_OPEN READ_INT
  112. #define WRITE_ATTACH WRITE_INT
  113. #define READ_ATTACH READ_INT
  114. #define WRITE_APPLICATION_DIED WRITE_INT
  115. #define READ_APPLICATION_DIED READ_INT
  116. #define WRITE_DEBUG WRITE_STRING
  117. #define READ_DEBUG READ_STRING
  118. #define WRITE_ERROR WRITE_INT
  119. #define READ_ERROR READ_INT
  120. #define WRITE_REGISTER(pdata, name, passwd, proto_ver, hostinfo)\
  121. sprint_register_data(PDRP(pdata), name, passwd, proto_ver, hostinfo)
  122. #define READ_REGISTER(pdata, name, passwd, proto_rev, hostinfo)\
  123. sscan_register_data(PDRP(pdata), &name, &passwd, &proto_rev, &hostinfo)
  124. #define WRITE_REPLY(pdata, val, err)\
  125. sprintf_len(PDRP(pdata), (XeString)"%x %x", val, err)
  126. #define READ_REPLY(pdata, val, err)\
  127. sscanf(PDRP(pdata), (XeString)"%x %x", &val, &err)
  128. #define WRITE_DEVICE_REPLY(pdata, m0, s0, m1, s1, m2, s2) \
  129. sprint_device_data(PDRP(pdata), m0, s0, m1, s1, m2, s2)
  130. #define READ_DEVICE_REPLY(pdata, m0, s0, m1, s1, m2, s2) \
  131. sscan_device_data(PDRP(pdata), m0, s0, m1, s1, m2, s2)
  132. #define WRITE_LOGFILE_REPLY(pdata, logfile, proto_ver, hostinfo) \
  133. sprint_logfile_data(PDRP(pdata), logfile, proto_ver, hostinfo)
  134. #define READ_LOGFILE_REPLY(pdata, logfile, proto_ver, hostinfo) \
  135. sscan_logfile_data(PDRP(pdata), logfile, proto_ver, hostinfo)
  136. #define WRITE_APPLICATION_SPAWN(pdata, path, dir, argv, envp) \
  137. sprint_application_data(PDRP(pdata), (XeString)"%s %d %d ", \
  138. path, dir, argv, envp, REQUEST_HEADER_LENGTH)
  139. #define READ_APPLICATION_SPAWN(pdata, path, dir, argv, envp) \
  140. sscan_application_data(PDRP(pdata), (XeString)"%s %d %d ", \
  141. &path, &dir, &argv, &envp, REQUEST_HEADER_LENGTH)
  142. #define WRITE_ENVIRON_RESET(pdata, numenv) \
  143. sprintf_len(PDRP(pdata), (XeString)"%d ", numenv)
  144. #define READ_ENVIRON_RESET(pdata, numenv) \
  145. sscanf(PDRP(pdata), (XeString)"%d ", &numenv)
  146. #define WRITE_APP_DATA(pdata, buffer, len) \
  147. (memcpy(PDRP(pdata), buffer, len), len)
  148. /* New B.00 protocol requests */
  149. #define WRITE_TERMIOS(pdata, connector, side, buffer) \
  150. sprintf_len(PDRP(pdata), (XeString)"%d %d %s", connector, side, buffer)
  151. #define READ_TERMIOS(pdata, connector, side, buffer) \
  152. sscanf(PDRP(pdata), (XeString)"%d %d %s", &connector, &side, buffer)
  153. /* Writing a header is special, as we don't want to be offset by
  154. REQUEST_HEADER_LENGTH */
  155. #define WRITE_HEADER(pdata, cid, type, len, seq) \
  156. sprintf_len(pdata->data, (XeString)"%08x%02x%04x%04x", cid, type, len, seq)
  157. #define READ_HEADER(pdata, cid, type, len, seq) \
  158. sscanf(pdata->data, (XeString)"%8x%2x%4x%4x", cid, type, len, seq)
  159. #define min(a, b) (((a) < (b)) ? (a) : (b))
  160. /*
  161. **
  162. ** The test here is reversed, that is, we check only for those
  163. ** requests where there is no reply expected, and assume the other
  164. ** ones do expect replies.
  165. **
  166. */
  167. #define NO_REPLY_VAL (-1)
  168. #define REPLY_EXPECTED(a, retval) \
  169. (((a==REPLY) || \
  170. (a==APPLICATION_DATA) || \
  171. (a==APPLICATION_STDOUT) || \
  172. (a==APPLICATION_STDERR) || \
  173. (a==REGISTER) || \
  174. (a==QUERY_LOGFILE) || \
  175. (a==QUERY_DEVICES) || \
  176. (a==ABORT) || \
  177. (a==SERVER_ERROR) \
  178. ) ? NO_REPLY_VAL : retval)
  179. typedef struct _prot_request {
  180. buffered_data_ptr dataptr;
  181. int seqno;
  182. int request_type;
  183. SPC_Channel_Ptr channel;
  184. struct _prot_request *next;
  185. } protocol_request, *protocol_request_ptr;
  186. typedef int (*protocol_request_handler)(protocol_request_ptr);
  187. /* spc-proto.c */
  188. buffered_data_ptr SPC_New_Buffered_Data_Ptr (void);
  189. void SPC_Reset_Protocol_Ptr (protocol_request_ptr prot, SPC_Channel_Ptr channel, XeChar req, int len);
  190. protocol_request_ptr SPC_New_Protocol_Ptr (SPC_Channel_Ptr channel, XeChar req, int len);
  191. void SPC_Free_Protocol_Ptr (protocol_request_ptr prot);
  192. SPC_Channel_Ptr SPC_Lookup_Channel (int cid, SPC_Connection_Ptr connection);
  193. SPC_Connection_Ptr SPC_Alloc_Connection (void);
  194. SPC_Connection_Ptr SPC_Lookup_Connection (XeString hostname);
  195. SPC_Connection_Ptr SPC_Lookup_Connection_Fd (int fd);
  196. SPC_Connection_Ptr SPC_Make_Connection (XeString hostname);
  197. void SPC_Add_Connection (SPC_Connection_Ptr connection);
  198. void SPC_Close_Connection (SPC_Connection_Ptr connection);
  199. int SPC_Read_Chars (SPC_Connection_Ptr connection, int request_len, XeString charptr);
  200. int SPC_Write_Chars (int fd, XeString charptr, int request_len);
  201. protocol_request_ptr SPC_Read_Protocol (SPC_Connection_Ptr connection);
  202. protocol_request_ptr SPC_Filter_Connection (SPC_Connection_Ptr connection, SPC_Channel_Ptr channel, int reqtype, int deletep);
  203. void SPC_Flush_Queued_Data (SPC_Channel_Ptr channel);
  204. int SPC_Read_Remote_Data (SPC_Channel_Ptr channel, int connector, XeString client_buffer, int nbytes);
  205. int print_protocol_request (XeString name, protocol_request_ptr proto);
  206. int SPC_Write_Protocol_Request (SPC_Connection_Ptr connection, SPC_Channel_Ptr channel, int request, ...);
  207. int SPC_Write_Single_Prot_Request (SPC_Connection_Ptr connection, XeString name, protocol_request_ptr prot);
  208. int SPC_Waitfor_Reply (SPC_Connection_Ptr connection, SPC_Channel_Ptr channel, int seqno);
  209. int SPC_Dispatch_Protocol (protocol_request_ptr proto, protocol_request_handler *);
  210. int SPC_Write_Reply (SPC_Connection_Ptr conn, protocol_request_ptr proto, int retval, int errval);
  211. int SPC_Send_Environ (SPC_Connection_Ptr connection, protocol_request_ptr prot);
  212. int sprint_counted_string (XeString buf, int count, XeString *vect, int limit);
  213. XeString *sscan_counted_string (XeString buf, XeString *newbuf);
  214. int sprint_application_data (XeString buf, XeString fmt, XeString path, XeString dir, XeString *argv, XeString *envp, int chars_used);
  215. int sscan_application_data (XeString buf, XeString fmt, XeString *path, XeString *dir, XeString **argv, XeString **envp, int offset);
  216. int sprint_device_data (XeString buf, XeString m0, XeString s0, XeString m1, XeString s1, XeString m2, XeString s2);
  217. int sscan_device_data (XeString buf, XeString *m0, XeString *s0, XeString *m1, XeString *s1, XeString *m2, XeString *s2);
  218. int sprint_logfile_data (XeString buf, XeString logfile, XeString proto_ver, XeString hostinfo);
  219. int sscan_logfile_data (XeString buf, XeString *logfile, XeString *proto_ver, XeString *hostinfo);
  220. int sprint_register_data (XeString buf, XeString username, XeString passwd, XeString proto_ver, XeString hostinfo);
  221. int sscan_register_data (XeString buf, XeString *username, XeString *passwd, XeString *proto_ver, XeString *hostinfo);
  222. int SPC_Query_Devices (SPC_Channel_Ptr channel);
  223. int SPC_Query_Logfile (SPC_Channel_Ptr channel);
  224. int SPC_Validate_User (XeString hostname, SPC_Connection_Ptr connection);
  225. int SPC_Get_Termio (protocol_request_ptr prot_request);
  226. int SPC_Get_Termios (protocol_request_ptr prot_request);
  227. XeString SPC_LocalHostinfo(void);
  228. int SPC_Send_Multi_Packet(SPC_Connection_Ptr connection,
  229. protocol_request_ptr prot,
  230. char **str_vect,
  231. int num_str,
  232. int req,
  233. XeString name,
  234. int errid);
  235. char **SPC_Get_Multi_Packet(SPC_Connection_Ptr connection,
  236. protocol_request_ptr prot,
  237. char **out,
  238. int *outlen,
  239. int request,
  240. XeString name);
  241. #endif /* _spc_proto_h */