mp_rpc_implement.C 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952
  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. //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
  24. //%% (c) Copyright 1993, 1994 International Business Machines Corp.
  25. //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  26. //%% (c) Copyright 1993, 1994 Novell, Inc.
  27. //%% $TOG: mp_rpc_implement.C /main/9 1999/10/14 18:42:58 mgreess $
  28. /*
  29. * mp_rpc_implement.C 1.40 29 Jul 1993
  30. *
  31. * mp_rpc_implement.cc -- implementation of RPC functions
  32. *
  33. * Copyright (c) 1990,1992 by Sun Microsystems, Inc.
  34. *
  35. * This file implements the RPC wrapper functions for each RPC
  36. * procedure number. The responsibility of each wrapper is to decode and
  37. * encode arguments and results and invoke the right methods
  38. * corresponding to each activity.
  39. *
  40. */
  41. #include <stdio.h>
  42. #include <errno.h>
  43. #include <stdlib.h>
  44. #include <string.h>
  45. #include <sys/param.h>
  46. #include <sys/types.h>
  47. #include <sys/stat.h>
  48. #include <sys/uio.h>
  49. #include <fcntl.h>
  50. #include <unistd.h>
  51. #if defined(__linux__) || defined(CSRG_BASED)
  52. /*# include <g++/minmax.h>*/
  53. #else
  54. # include <macros.h>
  55. #endif
  56. #include "tt_options.h"
  57. #include "util/tt_xdr_version.h"
  58. #include <rpc/rpc.h>
  59. #include <limits.h>
  60. #include "mp/mp_global.h"
  61. #include "mp_s_file.h"
  62. #include "mp_s_file_utils.h"
  63. #include "mp/mp_mp.h"
  64. #include "mp_s_mp.h"
  65. #include "mp_s_message.h"
  66. #include "mp_otype.h"
  67. #include "mp_signature.h"
  68. #include "mp/mp_arg.h"
  69. #include "mp_s_msg_context.h"
  70. #include "mp_s_pattern.h"
  71. #include "mp_s_procid.h"
  72. #include "mp/mp_rpc_fns.h"
  73. #include "mp_rpc_implement.h"
  74. #include "mp_s_session.h"
  75. #include "mp/mp_xdr_functions.h"
  76. #include "mp_s_xdr_functions.h"
  77. #include "util/tt_trace.h"
  78. #include "mp_typedb.h"
  79. #if defined(OPT_SECURE_RPC)
  80. static uid_t req_auth_uid;
  81. static gid_t req_auth_gid;
  82. static short req_auth_gidlen;
  83. // authdes_getucred() in 4.x is declared to take int* instead of gid_t*
  84. #if defined(OPT_BUG_SUNOS_4)
  85. static int req_auth_gids[10];
  86. #else
  87. static gid_t req_auth_gids[NGROUPS_MAX];
  88. #endif /* OPT_BUG_SUNOS_4 */
  89. #endif /* OPT_SECURE_RPC */
  90. #if defined(OPT_BUG_SUNOS_4)
  91. # define RPC_ARG_T char *
  92. #else
  93. # define RPC_ARG_T caddr_t
  94. #endif /* OPT_BUG_SUNOS_4 */
  95. #if defined(OPT_BUG_SUNOS_5)
  96. typedef void (*Hack_getucred)(const struct authdes_cred *,
  97. uid_t *,
  98. gid_t *,
  99. short *,
  100. gid_t *);
  101. #endif /* OPT_BUG_SUNOS_5 */
  102. void _tt_rpc_nullproc(SVCXPRT *);
  103. void _tt_rpc_dispatch(SVCXPRT *);
  104. void _tt_rpc_dispatch_with_context(SVCXPRT *);
  105. void _tt_rpc_update_msg(SVCXPRT *);
  106. void _tt_rpc_join_file(SVCXPRT *);
  107. void _tt_rpc_quit_file(SVCXPRT *);
  108. void _tt_rpc_join_session(SVCXPRT *);
  109. void _tt_rpc_quit_session(SVCXPRT *);
  110. void _tt_rpc_join_context(SVCXPRT *);
  111. void _tt_rpc_quit_context(SVCXPRT *);
  112. void _tt_rpc_next_message(SVCXPRT *);
  113. void _tt_rpc_add_pattern(SVCXPRT *);
  114. void _tt_rpc_add_pattern_with_context(SVCXPRT *);
  115. void _tt_rpc_del_pattern(SVCXPRT *);
  116. void _tt_rpc_declare_ptype(SVCXPRT *);
  117. void _tt_rpc_set_fd_channel(SVCXPRT *);
  118. void _tt_rpc_set_prop(SVCXPRT *);
  119. void _tt_rpc_add_prop(SVCXPRT *);
  120. void _tt_rpc_get_prop(SVCXPRT *);
  121. void _tt_rpc_prop_count(SVCXPRT *);
  122. void _tt_rpc_prop_name(SVCXPRT *);
  123. void _tt_rpc_prop_names_count(SVCXPRT *);
  124. void _tt_rpc_alloc_procid_key(SVCXPRT *);
  125. void _tt_rpc_close_procid(SVCXPRT *);
  126. void _tt_rpc_otype_deriveds_count(SVCXPRT *);
  127. void _tt_rpc_otype_derived(SVCXPRT *);
  128. void _tt_rpc_otype_base(SVCXPRT *);
  129. void _tt_rpc_otype_is_derived(SVCXPRT *);
  130. void _tt_rpc_otype_osig_count(SVCXPRT *);
  131. void _tt_rpc_otype_hsig_count(SVCXPRT *);
  132. void _tt_rpc_otype_osig_op(SVCXPRT *);
  133. void _tt_rpc_otype_hsig_op(SVCXPRT *);
  134. void _tt_rpc_otype_osig_args_count(SVCXPRT *);
  135. void _tt_rpc_otype_hsig_args_count(SVCXPRT *);
  136. void _tt_rpc_otype_osig_arg_mode(SVCXPRT *);
  137. void _tt_rpc_otype_hsig_arg_mode(SVCXPRT *);
  138. void _tt_rpc_otype_osig_arg_type(SVCXPRT *);
  139. void _tt_rpc_otype_hsig_arg_type(SVCXPRT *);
  140. void _tt_rpc_hdispatch(SVCXPRT *);
  141. void _tt_rpc_hupdate_msg(SVCXPRT *);
  142. void _tt_rpc_get_omap(SVCXPRT *);
  143. void _tt_rpc_add_omap(SVCXPRT *);
  144. void _tt_rpc_dispatch_2(SVCXPRT *);
  145. void _tt_rpc_dispatch_2_with_context(SVCXPRT *);
  146. void _tt_rpc_update_msg_2(SVCXPRT *);
  147. void _tt_rpc_msgread_2(SVCXPRT *);
  148. void _tt_rpc_vrfy_session(SVCXPRT *);
  149. void _tt_rpc_dispatch_on_exit(SVCXPRT *);
  150. void _tt_rpc_undeclare_ptype(SVCXPRT *);
  151. void _tt_rpc_exists_ptype(SVCXPRT *);
  152. void _tt_rpc_unblock_ptype(SVCXPRT *);
  153. void _tt_rpc_load_types(SVCXPRT *);
  154. typedef void (*_Tt_rpc_stub)(SVCXPRT *);
  155. /*
  156. * Dispatch table for rpc procedures. Note that the position of the
  157. * dispatch functions must correspond to the _Tt_rpc_procedure number
  158. * enum.
  159. */
  160. const _Tt_rpc_stub _tt_rpc_dispatch_table[TT_RPC_LAST] = {
  161. 0, /* 0 - TT_RPC_NULLPROC */
  162. _tt_rpc_dispatch, /* 1 - TT_RPC_DISPATCH */
  163. _tt_rpc_update_msg, /* 2 - TT_RPC_UPDATE_MSG */
  164. _tt_rpc_join_file, /* 3 - TT_RPC_JOIN_FILE */
  165. _tt_rpc_quit_file, /* 4 - TT_RPC_QUIT_FILE */
  166. _tt_rpc_join_session, /* 5 - TT_RPC_JOIN_SESSION */
  167. _tt_rpc_quit_session, /* 6 - TT_RPC_QUIT_SESSION */
  168. _tt_rpc_next_message, /* 7 - TT_RPC_NEXT_MESSAGE */
  169. _tt_rpc_add_pattern, /* 8 - TT_RPC_ADD_PATTERN */
  170. _tt_rpc_del_pattern, /* 9 - TT_RPC_DEL_PATTERN */
  171. _tt_rpc_declare_ptype, /* 10 - TT_RPC_DECLARE_PTYPE */
  172. _tt_rpc_set_fd_channel, /* 11 - TT_RPC_SET_FD_CHANNEL */
  173. _tt_rpc_set_prop, /* 12 - TT_RPC_SET_PROP */
  174. _tt_rpc_add_prop, /* 13 - TT_RPC_ADD_PROP */
  175. _tt_rpc_get_prop, /* 14 - TT_RPC_GET_PROP */
  176. _tt_rpc_prop_count, /* 15 - TT_RPC_PROP_COUNT */
  177. _tt_rpc_prop_name, /* 16 - TT_RPC_PROP_NAME */
  178. _tt_rpc_prop_names_count, /* 17 - TT_RPC_PROP_NAMES_COUNT */
  179. _tt_rpc_alloc_procid_key, /* 18 - TT_RPC_ALLOC_PROCID_KEY */
  180. _tt_rpc_close_procid, /* 19 - TT_RPC_CLOSE_PROCID */
  181. _tt_rpc_otype_deriveds_count, /* 20 - TT_RPC_OTYPE_DERIVEDS_COUNT */
  182. _tt_rpc_otype_derived, /* 21 - TT_RPC_OTYPE_DERIVED */
  183. _tt_rpc_otype_base, /* 22 - TT_RPC_OTYPE_BASE */
  184. _tt_rpc_otype_is_derived, /* 23 - TT_RPC_OTYPE_IS_DERIVED */
  185. _tt_rpc_otype_osig_count, /* 24 - TT_RPC_OTYPE_OSIG_COUNT */
  186. _tt_rpc_otype_hsig_count, /* 25 - TT_RPC_OTYPE_HSIG_COUNT */
  187. _tt_rpc_otype_osig_op, /* 26 - TT_RPC_OTYPE_OSIG_OP */
  188. _tt_rpc_otype_hsig_op, /* 27 - TT_RPC_OTYPE_HSIG_OP */
  189. _tt_rpc_otype_osig_args_count, /* 28 - TT_RPC_OTYPE_OSIG_ARGS_COUNT */
  190. _tt_rpc_otype_hsig_args_count, /* 29 - TT_RPC_OTYPE_HSIG_ARGS_COUNT */
  191. _tt_rpc_otype_osig_arg_mode, /* 30 - TT_RPC_OTYPE_OSIG_ARG_MODE */
  192. _tt_rpc_otype_hsig_arg_mode, /* 31 - TT_RPC_OTYPE_HSIG_ARG_MODE */
  193. _tt_rpc_otype_osig_arg_type, /* 32 - TT_RPC_OTYPE_OSIG_ARG_TYPE */
  194. _tt_rpc_otype_hsig_arg_type, /* 33 - TT_RPC_OTYPE_HSIG_ARG_TYPE */
  195. _tt_rpc_hdispatch, /* 34 - TT_RPC_HDISPATCH */
  196. _tt_rpc_hupdate_msg, /* 35 - TT_RPC_HUPDATE_MSG */
  197. _tt_rpc_dispatch_2, /* 36 - TT_RPC_DISPATCH_2 */
  198. _tt_rpc_update_msg_2, /* 37 - TT_RPC_UPDATE_MSG_2 */
  199. _tt_rpc_msgread_2, /* 38 - TT_RPC_MSGREAD_2 */
  200. _tt_rpc_dispatch_on_exit, /* 39 - TT_RPC_DISPATCH_ON_EXIT */
  201. _tt_rpc_undeclare_ptype, /* 40 - TT_RPC_UNDECLARE_PTYPE */
  202. _tt_rpc_exists_ptype, /* 41 - TT_RPC_EXISTS_PTYPE */
  203. _tt_rpc_unblock_ptype, /* 42 - TT_RPC_UNBLOCK_PTYPE */
  204. _tt_rpc_join_context, /* 43 - TT_RPC_JOIN_CONTEXT */
  205. _tt_rpc_quit_context, /* 44 - TT_RPC_QUIT_CONTEXT */
  206. _tt_rpc_dispatch_with_context, /* 45 - TT_RPC_DISPATCH_WITH_CONTEXT */
  207. _tt_rpc_dispatch_2_with_context,/* 46 - TT_RPC_DISPATCH_2_WITH_CONTEXT */
  208. _tt_rpc_add_pattern_with_context,/* 47 - TT_RPC_ADD_PATTERN_WITH_CONTEXT */
  209. _tt_rpc_load_types /* 48 - TT_RPC_LOAD_TYPES */
  210. };
  211. /*
  212. * Dispatch function invoked whenever an RPC request comes in.
  213. */
  214. void
  215. _tt_service_rpc(svc_req *rqstp, SVCXPRT *transp)
  216. {
  217. _Tt_auth_level session_auth;
  218. #if defined(OPT_SECURE_RPC)
  219. authdes_cred *des_cred;
  220. #endif
  221. // Increment the counter for the number of RPC calls
  222. // handled during the life of this process.
  223. _tt_global->event_counter++;
  224. //
  225. // authenticate request
  226. //
  227. session_auth = _tt_s_mp->initial_s_session->auth_level();
  228. switch (rqstp->rq_cred.oa_flavor) {
  229. case AUTH_UNIX:
  230. case AUTH_SHORT:
  231. if (session_auth == _TT_AUTH_DES ||
  232. session_auth == _TT_AUTH_ICEAUTH) {
  233. svcerr_auth(transp, AUTH_TOOWEAK);
  234. return;
  235. }
  236. else if (session_auth == _TT_AUTH_UNIX) {
  237. if (_tt_s_mp->unix_cred_chk_flag) {
  238. // "authunix_parms" is now deprecated in
  239. // favor of "authsys_parms", but
  240. // "authsys_parms" does not exist on
  241. // all platforms yet.
  242. authunix_parms* sys_cred =
  243. (authunix_parms *) rqstp->rq_clntcred;
  244. if (sys_cred->aup_uid != geteuid()) {
  245. svcerr_auth(transp, AUTH_BADCRED);
  246. return;
  247. }
  248. }
  249. // else, we are not doing auth checking
  250. }
  251. break;
  252. #if defined(OPT_SECURE_RPC)
  253. case AUTH_DES:
  254. if (session_auth != _TT_AUTH_DES) {
  255. svcerr_auth(transp, AUTH_TOOWEAK);
  256. return;
  257. }
  258. des_cred = (authdes_cred *)rqstp->rq_clntcred;
  259. #if !defined(OPT_BUG_SUNOS_5)
  260. if (! authdes_getucred(des_cred,
  261. &req_auth_uid,
  262. &req_auth_gid,
  263. &req_auth_gidlen,
  264. req_auth_gids)) {
  265. svcerr_auth(transp, AUTH_BADCRED);
  266. }
  267. #else
  268. Hack_getucred hack_getucred_p;
  269. hack_getucred_p = (Hack_getucred)authdes_getucred;
  270. if (! (*hack_getucred_p)(des_cred,
  271. &req_auth_uid,
  272. &req_auth_gid,
  273. &req_auth_gidlen,
  274. req_auth_gids)) {
  275. svcerr_auth(transp, AUTH_BADCRED);
  276. }
  277. #endif /* OPT_BUG_SUNOS_5 */
  278. // Now that we have the credentials, make sure they
  279. // are the right ones
  280. if (req_auth_uid == geteuid() &&
  281. req_auth_gid == getegid()) {
  282. break; // else fall through to svcerr_weakauth
  283. }
  284. #endif /* OPT_SECURE_RPC */
  285. default:
  286. if (session_auth == _TT_AUTH_ICEAUTH) {
  287. _Tt_string clnt_cookie;
  288. if (!_tt_svc_getargs(transp,
  289. (xdrproc_t) tt_xdr_string,
  290. (char *) &clnt_cookie)) {
  291. svcerr_auth(transp, AUTH_BADCRED);
  292. return;
  293. }
  294. const _Tt_string &svr_cookie =
  295. _tt_s_mp->initial_s_session->auth_cookie();
  296. if (clnt_cookie != svr_cookie) {
  297. svcerr_auth(transp, AUTH_BADCRED);
  298. return;
  299. }
  300. }
  301. }
  302. //
  303. // dispatch request to appropiate dispatch function
  304. //
  305. //
  306. // Set and reset xdr version on entry and exit. See tt_xdr_version.h
  307. //
  308. _Tt_xdr_version xvers((int)rqstp->rq_vers);
  309. switch (rqstp->rq_proc) {
  310. case NULLPROC:
  311. (void)svc_sendreply(transp, (xdrproc_t)xdr_void, 0);
  312. break;
  313. case TT_RPC_VRFY_SESSION:
  314. _tt_rpc_vrfy_session(transp);
  315. break;
  316. default:
  317. if (rqstp->rq_proc >= 1 && rqstp->rq_proc < TT_RPC_LAST) {
  318. (*_tt_rpc_dispatch_table[rqstp->rq_proc])(transp);
  319. } else {
  320. svcerr_noproc(transp);
  321. }
  322. break;
  323. }
  324. }
  325. /*
  326. * Called when a sender sends a message to the server.
  327. * This original version of _tt_rpc_dispatch() is a synchronous RPC
  328. * call, and it returns a _Tt_dispatch_reply_args, which contains
  329. * dispatch status and file-scoped queuing info. The new version,
  330. * _tt_rpc_dispatch_2(), is asynchronous and thus faster.
  331. */
  332. void
  333. _tt_rpc_dispatch(SVCXPRT *transp)
  334. {
  335. _Tt_s_message_ptr msg;
  336. _Tt_dispatch_reply_args args;
  337. msg = new _Tt_s_message();
  338. if (!_tt_svc_getargs(transp,
  339. (xdrproc_t)tt_xdr_message,
  340. (char *)&msg)) {
  341. svcerr_decode(transp);
  342. return;
  343. }
  344. args.status = TT_OK;
  345. _Tt_msg_trace trace( *msg, TTDR_MESSAGE_SEND );
  346. //
  347. // XXX Turn this off until we do TT_ERR_OVERFLOW right
  348. //
  349. //if (_tt_s_mp->active_messages > _tt_s_mp->max_active_messages)
  350. if (0)
  351. {
  352. args.status = TT_ERR_OVERFLOW;
  353. } else {
  354. // dispatch the message so that any information regarding
  355. // scope, and queueing can be relayed back to the sender.
  356. msg->dispatch( trace );
  357. msg->qmsg_info(args.qmsg_info);
  358. }
  359. if (msg->scope() != TT_SESSION) {
  360. // if no file-scope patterns exist for this file then
  361. // return an error to allow the client to remove this
  362. // session from the file's scope.
  363. if (! _tt_s_mp->in_file_scope(msg->file())) {
  364. args.status = TT_ERR_FILE;
  365. }
  366. }
  367. if (!svc_sendreply(transp,
  368. (xdrproc_t)tt_xdr_dispatch_reply_args,
  369. (RPC_ARG_T)&args)) {
  370. return;
  371. }
  372. if (args.status == TT_OK || args.status == TT_ERR_FILE) {
  373. // now deliver the message
  374. msg->deliver_to_observers_and_handlers( trace );
  375. }
  376. }
  377. /*
  378. * Called when a sender sends a contextful message
  379. * to the server.
  380. */
  381. void
  382. _tt_rpc_dispatch_with_context(SVCXPRT *transp)
  383. {
  384. //
  385. // In messages, xdr versioning for contexts isn't necessary,
  386. // since a bitmask controls what fields of a _Tt_message get
  387. // xdr'd. This separate RPC call exists only so that
  388. // context-aware clients can tell whether a server understands
  389. // contexts.
  390. //
  391. _tt_rpc_dispatch(transp);
  392. }
  393. /*
  394. * High-performance version of _tt_rpc_dispatch(). No information
  395. * is relayed back to the calling client.
  396. */
  397. void
  398. _tt_rpc_dispatch_2(SVCXPRT *transp)
  399. {
  400. _Tt_s_message_ptr msg;
  401. msg = new _Tt_s_message();
  402. if (!_tt_svc_getargs(transp,
  403. (xdrproc_t)tt_xdr_message,
  404. (char *)&msg)) {
  405. svcerr_decode(transp);
  406. return;
  407. }
  408. _Tt_msg_trace trace( *msg, TTDR_MESSAGE_SEND );
  409. msg->dispatch( trace );
  410. // XXX holtz 93/09/17 Should we really deliver() if dispatch() fails?
  411. // Note: this applies to every dispatch() call in this file.
  412. msg->deliver_to_observers_and_handlers( trace );
  413. }
  414. /*
  415. * Called when a sender sends a contextful session-scoped message
  416. * to the server.
  417. */
  418. void
  419. _tt_rpc_dispatch_2_with_context(SVCXPRT *transp)
  420. {
  421. //
  422. // In messages, xdr versioning for contexts isn't necessary,
  423. // since a bitmask controls what fields of a _Tt_message get
  424. // xdr'd. This separate RPC call exists only so that
  425. // context-aware clients can tell whether a server understands
  426. // contexts.
  427. //
  428. _tt_rpc_dispatch_2(transp);
  429. }
  430. /*
  431. * Called when a handler or voter updates a message in any way (ie. state change)
  432. */
  433. void
  434. _tt_update_msg(SVCXPRT *transp, int reply)
  435. {
  436. _Tt_s_procid_ptr proc;
  437. Tt_status status;
  438. if (!_tt_svc_getargs(transp,
  439. (xdrproc_t)tt_xdr_update_args,
  440. (char *)&(_tt_s_mp->update_args))) {
  441. svcerr_decode(transp);
  442. return;
  443. }
  444. int found = 0;
  445. _Tt_message_ptr &msg = _tt_s_mp->update_args.message;
  446. //
  447. // We have to rummage around in the message to see which
  448. // procid is talking to us.
  449. //
  450. if (! msg->handler().is_null()) {
  451. //
  452. // Assume the handler is the updater.
  453. //
  454. found = _tt_s_mp->find_proc(msg->handler(), proc, 0);
  455. } else if (msg->message_class() == TT_OFFER) {
  456. //
  457. // Assume the last voter is the updater.
  458. //
  459. _Tt_procid_list_ptr proc_list;
  460. switch (_tt_s_mp->update_args.newstate) {
  461. case TT_REJECTED:
  462. proc_list = msg->rejecters();
  463. break;
  464. case TT_ACCEPTED:
  465. proc_list = msg->accepters();
  466. break;
  467. case TT_ABSTAINED:
  468. proc_list = msg->abstainers();
  469. break;
  470. }
  471. if ((! proc_list.is_null()) && (proc_list->count() > 0)) {
  472. found = _tt_s_mp->find_proc(proc_list->bot(), proc, 0);
  473. }
  474. }
  475. if (found) {
  476. status = TT_OK;
  477. } else {
  478. status = TT_ERR_PROCID;
  479. }
  480. if (reply && (! svc_sendreply(transp, (xdrproc_t)xdr_int,
  481. (RPC_ARG_T)&status)))
  482. {
  483. return;
  484. }
  485. if (status != TT_OK) {
  486. return;
  487. }
  488. if (msg->is_observer()) {
  489. // Clears _handler when observer replies to START_MESSAGE
  490. // XXX _handler is used to tell us which procid is talking
  491. // to us, because nothing in the message tells us who
  492. // is observing it. Ugly.
  493. msg->clr_observer_procid();
  494. }
  495. proc->update_message(msg, _tt_s_mp->update_args.newstate);
  496. }
  497. /*
  498. * Called when a handler updates a message in any way (ie. state change)
  499. */
  500. void
  501. _tt_rpc_update_msg(SVCXPRT *transp)
  502. {
  503. _tt_update_msg(transp, 1);
  504. }
  505. /*
  506. * Asynchronous, higher-performance version of _tt_rpc_update_msg()
  507. */
  508. void
  509. _tt_rpc_update_msg_2(SVCXPRT *transp)
  510. {
  511. _tt_update_msg(transp, 0);
  512. }
  513. /*
  514. * Called when a process joins a file.
  515. */
  516. void
  517. _tt_rpc_join_file(SVCXPRT *transp)
  518. {
  519. _Tt_file_join_args args;
  520. _Tt_s_procid_ptr proc;
  521. Tt_status status;
  522. _Tt_s_file_ptr fptr;
  523. if (! _tt_svc_getargs(transp, (xdrproc_t)tt_xdr_file_join_args,
  524. (char *)&args)) {
  525. svcerr_decode(transp);
  526. }
  527. if (_tt_s_mp->find_proc(args.procid, proc, 1)) {
  528. fptr = new _Tt_s_file(args.path);
  529. status = fptr->s_join(proc);
  530. } else {
  531. status = TT_ERR_PROCID;
  532. }
  533. (void)svc_sendreply(transp, (xdrproc_t)xdr_int, (RPC_ARG_T)&status);
  534. }
  535. /*
  536. * Called when a process quits a file.
  537. */
  538. void
  539. _tt_rpc_quit_file(SVCXPRT *transp)
  540. {
  541. _Tt_file_join_args args;
  542. _Tt_s_procid_ptr proc;
  543. Tt_status status;
  544. _Tt_s_file_ptr fptr;
  545. if (! _tt_svc_getargs(transp, (xdrproc_t)tt_xdr_file_join_args,
  546. (char *)&args)) {
  547. svcerr_decode(transp);
  548. }
  549. if (_tt_s_mp->find_proc(args.procid, proc, 1)) {
  550. fptr = new _Tt_s_file(args.path);
  551. status = fptr->s_quit(proc);
  552. } else {
  553. status = TT_ERR_PROCID;
  554. }
  555. (void)svc_sendreply(transp, (xdrproc_t)xdr_int, (RPC_ARG_T)&status);
  556. }
  557. /*
  558. * Called when a procid joins a session.
  559. */
  560. void
  561. _tt_rpc_join_session(SVCXPRT *transp)
  562. {
  563. _Tt_procid_ptr cproc;
  564. _Tt_s_procid_ptr proc;
  565. Tt_status status;
  566. if (! _tt_svc_getargs(transp,
  567. (xdrproc_t)tt_xdr_procid,
  568. (char *)&cproc)) {
  569. svcerr_decode(transp);
  570. return;
  571. }
  572. if (_tt_s_mp->find_proc(cproc, proc, 1)) {
  573. _Tt_s_procid *sp = (_Tt_s_procid *)proc.c_pointer();
  574. if (cproc->start_token().len() != 0) {
  575. sp->set_start_token(cproc->start_token());
  576. }
  577. status = _tt_s_mp->initial_s_session->s_join(proc);
  578. } else {
  579. status = TT_ERR_PROCID;
  580. }
  581. if (svc_sendreply(transp, (xdrproc_t)xdr_int, (RPC_ARG_T)&status) == 0) {
  582. return;
  583. }
  584. }
  585. /*
  586. * Called when a procid quits a session.
  587. */
  588. void
  589. _tt_rpc_quit_session(SVCXPRT *transp)
  590. {
  591. _Tt_procid_ptr cproc;
  592. _Tt_s_procid_ptr proc;
  593. Tt_status status;
  594. if (! _tt_svc_getargs(transp,
  595. (xdrproc_t)tt_xdr_procid,
  596. (char *)&cproc)) {
  597. svcerr_decode(transp);
  598. return;
  599. }
  600. if (_tt_s_mp->find_proc(cproc, proc, 1)) {
  601. status = _tt_s_mp->initial_s_session->s_quit(proc);
  602. } else {
  603. status = TT_ERR_PROCID;
  604. }
  605. if (svc_sendreply(transp, (xdrproc_t)xdr_int, (RPC_ARG_T)&status) == 0) {
  606. return;
  607. }
  608. }
  609. /*
  610. * Called when a procid wants to join a context.
  611. */
  612. void
  613. _tt_rpc_join_context(SVCXPRT *transp)
  614. {
  615. _Tt_context_join_args args;
  616. _Tt_s_procid_ptr proc;
  617. Tt_status status;
  618. if (! _tt_svc_getargs( transp, (xdrproc_t)tt_xdr_context_join_args,
  619. (char *)&args))
  620. {
  621. svcerr_decode(transp);
  622. }
  623. if (_tt_s_mp->find_proc( args.procid, proc, 1 )) {
  624. status = ((_Tt_s_msg_context &)*args.context).s_join( proc );
  625. } else {
  626. status = TT_ERR_PROCID;
  627. }
  628. svc_sendreply( transp, (xdrproc_t)xdr_int, (RPC_ARG_T)&status );
  629. }
  630. /*
  631. * Called when a procid wants to quit a context.
  632. */
  633. void
  634. _tt_rpc_quit_context(SVCXPRT *transp)
  635. {
  636. _Tt_context_join_args args;
  637. _Tt_s_procid_ptr proc;
  638. Tt_status status;
  639. if (! _tt_svc_getargs( transp, (xdrproc_t)tt_xdr_context_join_args,
  640. (char *)&args))
  641. {
  642. svcerr_decode(transp);
  643. }
  644. if (_tt_s_mp->find_proc( args.procid, proc, 1 )) {
  645. status = ((_Tt_s_msg_context &)*args.context).s_quit( proc );
  646. } else {
  647. status = TT_ERR_PROCID;
  648. }
  649. svc_sendreply( transp, (xdrproc_t)xdr_int, (RPC_ARG_T)&status );
  650. }
  651. /*
  652. * Called when a procid wants to retrieve the next undelivered message
  653. * for it.
  654. */
  655. void
  656. _tt_rpc_next_message(SVCXPRT *transp)
  657. {
  658. _Tt_procid_ptr cproc;
  659. _Tt_next_message_args args;
  660. _Tt_s_procid_ptr proc;
  661. if (! _tt_svc_getargs(transp,
  662. (xdrproc_t)tt_xdr_procid,
  663. (char *)&cproc)) {
  664. svcerr_decode(transp);
  665. return;
  666. }
  667. // default is to tell client to clear fd, that way in case of
  668. // any errors, at least the client won't loop.
  669. args.clear_signal = 1;
  670. args.msgs = (_Tt_message_list *)0;
  671. if (_tt_s_mp->find_proc(cproc, proc, 0)) {
  672. _Tt_s_procid *sp = (_Tt_s_procid *)proc.c_pointer();
  673. sp->next_message(args);
  674. }
  675. if (svc_sendreply(transp,
  676. (xdrproc_t)tt_xdr_next_message_args,
  677. (RPC_ARG_T)&args) == 0) {
  678. return;
  679. }
  680. }
  681. /*
  682. * Called when a procid wants to register a new pattern.
  683. */
  684. void
  685. _tt_rpc_add_pattern(SVCXPRT *transp)
  686. {
  687. _Tt_s_procid_ptr proc;
  688. _Tt_s_add_pattern_args args;
  689. Tt_status status;
  690. if (! _tt_svc_getargs(transp,
  691. (xdrproc_t)tt_s_xdr_add_pattern_args,
  692. (char *)&args)) {
  693. svcerr_decode(transp);
  694. return;
  695. }
  696. if (_tt_s_mp->find_proc(args.procid, proc, 1)) {
  697. _Tt_s_procid *sp = (_Tt_s_procid *)proc.c_pointer();
  698. status = sp->add_pattern(args.pattern);
  699. } else {
  700. status = TT_ERR_PROCID;
  701. }
  702. if (svc_sendreply(transp,(xdrproc_t)xdr_int,(RPC_ARG_T)&status) == 0) {
  703. return;
  704. }
  705. }
  706. /*
  707. * Called when a procid wants to register a new context-ful pattern.
  708. */
  709. void
  710. _tt_rpc_add_pattern_with_context(SVCXPRT *transp)
  711. {
  712. //
  713. // Contexts are only xdr'd in _Tt_patterns in xdr version 3 or
  714. // later. The rpc protocol version number represents a floor
  715. // for the xdr version number. Even though this rpc call was
  716. // introduced into protocol version 2, it can be assumed that
  717. // the caller is using at least xdr version 3.
  718. //
  719. // _Tt_xdr_version xvers( max(_tt_global->xdr_version(),
  720. // TT_CONTEXTS_XDR_VERSION) );
  721. if(_tt_global->xdr_version() > TT_CONTEXTS_XDR_VERSION) {
  722. _Tt_xdr_version xvers(_tt_global->xdr_version() );
  723. } else {
  724. _Tt_xdr_version xvers(TT_CONTEXTS_XDR_VERSION);
  725. }
  726. _tt_rpc_add_pattern(transp);
  727. }
  728. /*
  729. * Called when a procid wants to unregister a pattern with the server.
  730. */
  731. void
  732. _tt_rpc_del_pattern(SVCXPRT *transp)
  733. {
  734. _Tt_s_procid_ptr proc;
  735. _Tt_s_del_pattern_args args;
  736. Tt_status status;
  737. if (! _tt_svc_getargs(transp,
  738. (xdrproc_t)tt_s_xdr_del_pattern_args,
  739. (char *)&args)) {
  740. svcerr_decode(transp);
  741. return;
  742. }
  743. if (_tt_s_mp->find_proc(args.procid, proc, 1)) {
  744. _Tt_s_procid *sp = (_Tt_s_procid *)proc.c_pointer();
  745. status = sp->del_pattern(args.pattern_id);
  746. } else {
  747. status = TT_ERR_PROCID;
  748. }
  749. if (svc_sendreply(transp,(xdrproc_t)xdr_int,(RPC_ARG_T)&status) == 0) {
  750. return;
  751. }
  752. }
  753. /*
  754. * Called by a procid to declare a ptype.
  755. */
  756. void
  757. _tt_rpc_declare_ptype(SVCXPRT *transp)
  758. {
  759. _Tt_declare_ptype_args args;
  760. _Tt_s_procid_ptr proc;
  761. Tt_status status;
  762. if (! _tt_svc_getargs(transp,
  763. (xdrproc_t)tt_xdr_declare_ptype_args,
  764. (char *)&args)) {
  765. svcerr_decode(transp);
  766. return;
  767. }
  768. if (_tt_s_mp->find_proc(args.procid, proc, 1)) {
  769. _Tt_s_procid *sp = (_Tt_s_procid *)proc.c_pointer();
  770. status = sp->declare_ptype(args.ptid);
  771. } else {
  772. status = TT_ERR_PROCID;
  773. }
  774. if (svc_sendreply(transp,(xdrproc_t)xdr_int,(RPC_ARG_T)&status) == 0) {
  775. return;
  776. }
  777. }
  778. /*
  779. * Called by a procid to undeclare a ptype.
  780. */
  781. void
  782. _tt_rpc_undeclare_ptype(SVCXPRT *transp)
  783. {
  784. _Tt_declare_ptype_args args;
  785. _Tt_s_procid_ptr proc;
  786. Tt_status status;
  787. if (! _tt_svc_getargs(transp,
  788. (xdrproc_t)tt_xdr_declare_ptype_args,
  789. (char *)&args)) {
  790. svcerr_decode(transp);
  791. return;
  792. }
  793. if (_tt_s_mp->find_proc(args.procid, proc, 1)) {
  794. _Tt_s_procid *sp = (_Tt_s_procid *)proc.c_pointer();
  795. status = sp->undeclare_ptype(args.ptid);
  796. } else {
  797. status = TT_ERR_PROCID;
  798. }
  799. if (svc_sendreply(transp,(xdrproc_t)xdr_int,(RPC_ARG_T)&status) == 0) {
  800. return;
  801. }
  802. }
  803. /*
  804. * Called by a procid to test existence of a ptype.
  805. */
  806. void
  807. _tt_rpc_exists_ptype(SVCXPRT *transp)
  808. {
  809. _Tt_declare_ptype_args args;
  810. _Tt_s_procid_ptr proc;
  811. Tt_status status;
  812. if (! _tt_svc_getargs(transp,
  813. (xdrproc_t)tt_xdr_declare_ptype_args,
  814. (char *)&args)) {
  815. svcerr_decode(transp);
  816. return;
  817. }
  818. if (_tt_s_mp->find_proc(args.procid, proc, 1)) {
  819. _Tt_s_procid *sp = (_Tt_s_procid *)proc.c_pointer();
  820. status = sp->exists_ptype(args.ptid);
  821. } else {
  822. status = TT_ERR_PROCID;
  823. }
  824. if (svc_sendreply(transp,(xdrproc_t)xdr_int,(RPC_ARG_T)&status) == 0) {
  825. return;
  826. }
  827. }
  828. /*
  829. * Called by a procid to unblock queued messages for its ptype.
  830. */
  831. void
  832. _tt_rpc_unblock_ptype(SVCXPRT *transp)
  833. {
  834. _Tt_declare_ptype_args args;
  835. _Tt_s_procid_ptr proc;
  836. Tt_status status;
  837. if (! _tt_svc_getargs(transp,
  838. (xdrproc_t)tt_xdr_declare_ptype_args,
  839. (char *)&args)) {
  840. svcerr_decode(transp);
  841. return;
  842. }
  843. if (_tt_s_mp->find_proc(args.procid, proc, 1)) {
  844. _Tt_s_procid *sp = (_Tt_s_procid *)proc.c_pointer();
  845. status = sp->unblock_ptype(args.ptid);
  846. } else {
  847. status = TT_ERR_PROCID;
  848. }
  849. if (svc_sendreply(transp,(xdrproc_t)xdr_int,(RPC_ARG_T)&status) == 0) {
  850. return;
  851. }
  852. }
  853. /*
  854. * Called by a procid to load new types into its associated ttsession.
  855. */
  856. void
  857. _tt_rpc_load_types(SVCXPRT *transp)
  858. {
  859. _Tt_load_types_args args;
  860. Tt_status status;
  861. XDR xdrs;
  862. if (! _tt_svc_getargs(transp,
  863. (xdrproc_t)tt_xdr_load_types_args,
  864. (char *)&args)) {
  865. svcerr_decode(transp);
  866. return;
  867. }
  868. xdrmem_create(&xdrs,
  869. (char *)args.xdrtypes,
  870. (u_int)args.xdrtypes.len(),
  871. XDR_DECODE);
  872. int junk;
  873. status = _Tt_typedb::merge_from(&xdrs,_tt_s_mp->tdb, junk);
  874. if (status==TT_OK) {
  875. _tt_s_mp->install_ptable(_tt_s_mp->tdb->ptable);
  876. _tt_s_mp->install_otable(_tt_s_mp->tdb->otable);
  877. }
  878. if (svc_sendreply(transp,(xdrproc_t)xdr_int,(RPC_ARG_T)&status) == 0) {
  879. return;
  880. }
  881. }
  882. /*
  883. * Called by a procid to notify the server of its fd signalling channel.
  884. */
  885. void
  886. _tt_rpc_set_fd_channel(SVCXPRT *transp)
  887. {
  888. _Tt_fd_args fd_args;
  889. _Tt_s_procid_ptr proc;
  890. Tt_status status;
  891. if (! _tt_svc_getargs(transp,
  892. (xdrproc_t)tt_xdr_fd_args,
  893. (char *)&fd_args)) {
  894. svcerr_decode(transp);
  895. return;
  896. }
  897. if (_tt_s_mp->find_proc(fd_args.procid, proc, 1)) {
  898. status = TT_OK;
  899. } else {
  900. status = TT_ERR_PROCID;
  901. }
  902. //
  903. // Note: it's important to reply immediately here because
  904. // setting up the channel involves connecting to the socket
  905. // on the client side so if we attempted to reply after
  906. // the operation then we would get deadlock.
  907. //
  908. if (svc_sendreply(transp,
  909. (xdrproc_t)xdr_int,
  910. (RPC_ARG_T)&status) == 0) {
  911. return;
  912. }
  913. if (status == TT_OK) {
  914. _Tt_s_procid *sp = (_Tt_s_procid *)proc.c_pointer();
  915. sp->set_start_token(fd_args.start_token);
  916. sp->set_fd_channel(fd_args.fd);
  917. }
  918. }
  919. /*
  920. * Set the value of a session property
  921. */
  922. void
  923. _tt_rpc_set_prop(SVCXPRT *transp)
  924. {
  925. _Tt_prop_args args;
  926. Tt_status status;
  927. if (! _tt_svc_getargs(transp,
  928. (xdrproc_t)tt_xdr_prop_args,
  929. (char *)&args)) {
  930. svcerr_decode(transp);
  931. return;
  932. }
  933. status = _tt_s_mp->initial_s_session->s_setprop(args.prop, args.value);
  934. if (svc_sendreply(transp,(xdrproc_t)xdr_int,(RPC_ARG_T)&status) == 0) {
  935. return;
  936. }
  937. }
  938. /*
  939. * Add a value to a session property
  940. */
  941. void
  942. _tt_rpc_add_prop(SVCXPRT *transp)
  943. {
  944. _Tt_prop_args args;
  945. Tt_status status;
  946. if (! _tt_svc_getargs(transp,
  947. (xdrproc_t)tt_xdr_prop_args,
  948. (char *)&args)) {
  949. svcerr_decode(transp);
  950. return;
  951. }
  952. status = _tt_s_mp->initial_s_session->s_addprop(args.prop, args.value);
  953. if (svc_sendreply(transp,(xdrproc_t)xdr_int,(RPC_ARG_T)&status) == 0) {
  954. return;
  955. }
  956. }
  957. /*
  958. * Get a value from a session property
  959. */
  960. void
  961. _tt_rpc_get_prop(SVCXPRT *transp)
  962. {
  963. _Tt_prop_args args;
  964. Tt_status status;
  965. _Tt_string value;
  966. _Tt_rpc_result result;
  967. if (! _tt_svc_getargs(transp,
  968. (xdrproc_t)tt_xdr_prop_args,
  969. (char *)&args)) {
  970. svcerr_decode(transp);
  971. return;
  972. }
  973. if ((status = _tt_s_mp->initial_s_session->s_getprop(args.prop, args.num, value))
  974. != TT_OK) {
  975. result.status = status;
  976. result.str_val = "";
  977. result.int_val = 0;
  978. } else {
  979. result.status = TT_OK;
  980. result.str_val = value;
  981. result.int_val = 0;
  982. }
  983. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  984. (RPC_ARG_T)&result) == 0) {
  985. return;
  986. }
  987. }
  988. /*
  989. * Return the number of values for a session property
  990. */
  991. void
  992. _tt_rpc_prop_count(SVCXPRT *transp)
  993. {
  994. _Tt_prop_args args;
  995. int cnt;
  996. _Tt_rpc_result result;
  997. if (! _tt_svc_getargs(transp,
  998. (xdrproc_t)tt_xdr_prop_args,
  999. (char *)&args)) {
  1000. svcerr_decode(transp);
  1001. return;
  1002. }
  1003. result.status = _tt_s_mp->initial_s_session->s_propcount(args.prop, cnt);
  1004. result.str_val = "";
  1005. if (result.status == TT_OK) {
  1006. result.int_val = cnt;
  1007. } else {
  1008. result.int_val = 0;
  1009. }
  1010. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1011. (RPC_ARG_T)&result) == 0) {
  1012. return;
  1013. }
  1014. }
  1015. /*
  1016. * Return a session property name
  1017. */
  1018. void
  1019. _tt_rpc_prop_name(SVCXPRT *transp)
  1020. {
  1021. _Tt_prop_args args;
  1022. Tt_status status;
  1023. _Tt_string prop;
  1024. _Tt_rpc_result result;
  1025. if (! _tt_svc_getargs(transp,
  1026. (xdrproc_t)tt_xdr_prop_args,
  1027. (char *)&args)) {
  1028. svcerr_decode(transp);
  1029. return;
  1030. }
  1031. if ((status = _tt_s_mp->initial_s_session->s_propname(args.num, prop))
  1032. != TT_OK) {
  1033. result.status = status;
  1034. result.str_val = "";
  1035. result.int_val = 0;
  1036. } else {
  1037. result.status = TT_OK;
  1038. result.str_val = prop;
  1039. result.int_val = 0;
  1040. }
  1041. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1042. (RPC_ARG_T)&result) == 0) {
  1043. return;
  1044. }
  1045. }
  1046. /*
  1047. * Return the number of session properties
  1048. */
  1049. void
  1050. _tt_rpc_prop_names_count(SVCXPRT *transp)
  1051. {
  1052. _Tt_prop_args args;
  1053. int cnt;
  1054. _Tt_rpc_result result;
  1055. if (! _tt_svc_getargs(transp,
  1056. (xdrproc_t)tt_xdr_prop_args,
  1057. (char *)&args)) {
  1058. svcerr_decode(transp);
  1059. return;
  1060. }
  1061. result.status = _tt_s_mp->initial_s_session->s_propnames_count(cnt);
  1062. result.str_val = "";
  1063. if (result.status == TT_OK) {
  1064. result.int_val = cnt;
  1065. } else {
  1066. result.int_val = 0;
  1067. }
  1068. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1069. (RPC_ARG_T)&result) == 0) {
  1070. return;
  1071. }
  1072. }
  1073. void
  1074. _tt_rpc_alloc_procid_key(SVCXPRT *transp)
  1075. {
  1076. _Tt_string result;
  1077. if (! _tt_svc_getargs(transp,(xdrproc_t)xdr_void,0)) {
  1078. svcerr_decode(transp);
  1079. return;
  1080. }
  1081. result = _tt_s_mp->alloc_procid_key();
  1082. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_string,
  1083. (RPC_ARG_T)&result) == 0) {
  1084. return;
  1085. }
  1086. }
  1087. void
  1088. _tt_rpc_close_procid(SVCXPRT *transp)
  1089. {
  1090. _Tt_procid_ptr p;
  1091. _Tt_s_procid_ptr rp;
  1092. Tt_status status;
  1093. if (! _tt_svc_getargs(transp,
  1094. (xdrproc_t)tt_xdr_procid,
  1095. (char *)&p)) {
  1096. svcerr_decode(transp);
  1097. }
  1098. if (_tt_s_mp->find_proc(p, rp, 0)) {
  1099. status = _tt_s_mp->s_remove_procid(*rp);
  1100. } else {
  1101. status = TT_ERR_PROCID;
  1102. }
  1103. (void)svc_sendreply(transp,(xdrproc_t)xdr_int, (RPC_ARG_T)&status);
  1104. }
  1105. void
  1106. _tt_rpc_vrfy_session(SVCXPRT *transp)
  1107. {
  1108. _Tt_string id;
  1109. if (! _tt_svc_getargs(transp, (xdrproc_t)xdr_void, 0)) {
  1110. svcerr_decode(transp);
  1111. return;
  1112. }
  1113. if (_tt_global->xdr_version() == 1) {
  1114. id = _tt_s_mp->initial_s_session->id();
  1115. } else {
  1116. id = _tt_s_mp->initial_s_session->process_tree_id();
  1117. }
  1118. if (!svc_sendreply(transp,
  1119. (xdrproc_t)tt_xdr_string,
  1120. (RPC_ARG_T)&id)) {
  1121. svcerr_decode(transp);
  1122. }
  1123. }
  1124. /*
  1125. * Return the number of otypes derived from a base otype
  1126. */
  1127. void
  1128. _tt_rpc_otype_deriveds_count(SVCXPRT *transp)
  1129. {
  1130. _Tt_otype_args args;
  1131. _Tt_rpc_result result;
  1132. _Tt_otype_ptr base_otype;
  1133. if (! _tt_svc_getargs(transp,
  1134. (xdrproc_t)tt_xdr_otype_args,
  1135. (char *)&args)) {
  1136. svcerr_decode(transp);
  1137. return;
  1138. }
  1139. result.str_val = "";
  1140. base_otype = _tt_s_mp->otable->lookup(args.base_otid);
  1141. if (base_otype.is_null()) {
  1142. result.status = TT_ERR_OTYPE;
  1143. } else {
  1144. result.int_val = base_otype->children()->count();
  1145. result.status = TT_OK;
  1146. }
  1147. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1148. (RPC_ARG_T)&result) == 0) {
  1149. return;
  1150. }
  1151. }
  1152. /*
  1153. * Return the n'th otype derived from a base otype
  1154. */
  1155. void
  1156. _tt_rpc_otype_derived(SVCXPRT *transp)
  1157. {
  1158. _Tt_otype_args args;
  1159. _Tt_rpc_result result;
  1160. _Tt_string_list_ptr children;
  1161. _Tt_otype_ptr base_otype;
  1162. if (! _tt_svc_getargs(transp,
  1163. (xdrproc_t)tt_xdr_otype_args,
  1164. (char *)&args)) {
  1165. svcerr_decode(transp);
  1166. return;
  1167. }
  1168. result.str_val = "";
  1169. base_otype = _tt_s_mp->otable->lookup(args.base_otid);
  1170. if (base_otype.is_null()) {
  1171. result.status = TT_ERR_OTYPE;
  1172. } else {
  1173. children = base_otype->children();
  1174. if (args.num<0 || children->count()<args.num) {
  1175. result.status = TT_ERR_NUM;
  1176. result.str_val = "";
  1177. } else if (children->count()==args.num) {
  1178. result.status = TT_OK;
  1179. result.str_val = (char *)0;
  1180. } else {
  1181. result.status = TT_OK;
  1182. result.str_val = (*children)[args.num];
  1183. }
  1184. }
  1185. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1186. (RPC_ARG_T)&result) == 0) {
  1187. return;
  1188. }
  1189. }
  1190. /*
  1191. * Return the otype that is the base of a derived otype
  1192. */
  1193. void
  1194. _tt_rpc_otype_base(SVCXPRT *transp)
  1195. {
  1196. _Tt_otype_args args;
  1197. _Tt_rpc_result result;
  1198. _Tt_string_list_ptr parents;
  1199. _Tt_otype_ptr derived_otype;
  1200. if (! _tt_svc_getargs(transp,
  1201. (xdrproc_t)tt_xdr_otype_args,
  1202. (char *)&args)) {
  1203. svcerr_decode(transp);
  1204. return;
  1205. }
  1206. derived_otype = _tt_s_mp->otable->lookup(args.derived_otid);
  1207. if (derived_otype.is_null()) {
  1208. result.str_val = (char *)0;
  1209. result.status = TT_ERR_OTYPE;
  1210. } else {
  1211. parents = derived_otype->parents();
  1212. if (parents.is_null() || parents->is_empty()) {
  1213. result.status = TT_OK;
  1214. result.str_val = (char *)0;
  1215. } else {
  1216. result.status = TT_OK;
  1217. result.str_val = parents->top();
  1218. }
  1219. }
  1220. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1221. (RPC_ARG_T)&result) == 0) {
  1222. return;
  1223. }
  1224. }
  1225. /*
  1226. * Return 1 iff the derived otype derives directly or indirectly from the
  1227. * base otype.
  1228. */
  1229. void
  1230. _tt_rpc_otype_is_derived(SVCXPRT *transp)
  1231. {
  1232. _Tt_otype_args args;
  1233. _Tt_rpc_result result;
  1234. _Tt_string_list_ptr parents;
  1235. _Tt_otype_ptr derived_otype;
  1236. if (! _tt_svc_getargs(transp,
  1237. (xdrproc_t)tt_xdr_otype_args,
  1238. (char *)&args)) {
  1239. svcerr_decode(transp);
  1240. return;
  1241. }
  1242. result.status = TT_OK;
  1243. result.str_val = "";
  1244. if (args.derived_otid==args.base_otid) {
  1245. result.int_val = 1;
  1246. } else {
  1247. derived_otype = _tt_s_mp->otable->lookup(args.derived_otid);
  1248. if (derived_otype.is_null()) {
  1249. result.status = TT_ERR_OTYPE;
  1250. } else {
  1251. parents = derived_otype->parents();
  1252. result.int_val = 0;
  1253. _Tt_otype_ptr parent;
  1254. while (!parents->is_empty()) {
  1255. parent = _tt_s_mp->otable->
  1256. lookup(parents->top());
  1257. if (parent.is_null()) {
  1258. break;
  1259. } else if (parent->otid()==args.base_otid) {
  1260. result.int_val = 1;
  1261. break;
  1262. } else {
  1263. parents = parent->parents();
  1264. }
  1265. }
  1266. }
  1267. }
  1268. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1269. (RPC_ARG_T)&result) == 0) {
  1270. return;
  1271. }
  1272. }
  1273. /*
  1274. * Return the number of observer signatures for the specified otype
  1275. */
  1276. void
  1277. _tt_rpc_otype_osig_count(SVCXPRT *transp)
  1278. {
  1279. _Tt_otype_args args;
  1280. _Tt_rpc_result result;
  1281. _Tt_otype_ptr otype;
  1282. if (! _tt_svc_getargs(transp,
  1283. (xdrproc_t)tt_xdr_otype_args,
  1284. (char *)&args)) {
  1285. svcerr_decode(transp);
  1286. return;
  1287. }
  1288. result.status = TT_OK;
  1289. result.str_val = "";
  1290. result.int_val = 0;
  1291. otype = _tt_s_mp->otable->lookup(args.base_otid);
  1292. if (otype.is_null()) {
  1293. result.status = TT_ERR_OTYPE;
  1294. } else {
  1295. _Tt_signature_list_ptr sigs = otype->osigs();
  1296. result.int_val = sigs->count();
  1297. }
  1298. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1299. (RPC_ARG_T)&result) == 0) {
  1300. return;
  1301. }
  1302. }
  1303. /*
  1304. * Return the number of handler signatures for the specified otype
  1305. */
  1306. void
  1307. _tt_rpc_otype_hsig_count(SVCXPRT *transp)
  1308. {
  1309. _Tt_otype_args args;
  1310. _Tt_rpc_result result;
  1311. _Tt_otype_ptr otype;
  1312. if (! _tt_svc_getargs(transp,
  1313. (xdrproc_t)tt_xdr_otype_args,
  1314. (char *)&args)) {
  1315. svcerr_decode(transp);
  1316. return;
  1317. }
  1318. result.status = TT_OK;
  1319. result.str_val = "";
  1320. result.int_val = 0;
  1321. otype = _tt_s_mp->otable->lookup(args.base_otid);
  1322. if (otype.is_null()) {
  1323. result.status = TT_ERR_OTYPE;
  1324. } else {
  1325. _Tt_signature_list_ptr sigs = otype->hsigs();
  1326. result.int_val = sigs->count();
  1327. }
  1328. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1329. (RPC_ARG_T)&result) == 0) {
  1330. return;
  1331. }
  1332. }
  1333. /*
  1334. * Return the op for an observer signature of an otype
  1335. */
  1336. void
  1337. _tt_rpc_otype_osig_op(SVCXPRT *transp)
  1338. {
  1339. _Tt_otype_args args;
  1340. _Tt_rpc_result result;
  1341. _Tt_otype_ptr otype;
  1342. if (! _tt_svc_getargs(transp,
  1343. (xdrproc_t)tt_xdr_otype_args,
  1344. (char *)&args)) {
  1345. svcerr_decode(transp);
  1346. return;
  1347. }
  1348. result.status = TT_OK;
  1349. result.str_val = "";
  1350. result.int_val = 0;
  1351. otype = _tt_s_mp->otable->lookup(args.base_otid);
  1352. if (otype.is_null()) {
  1353. result.status = TT_ERR_OTYPE;
  1354. } else {
  1355. _Tt_signature_list_ptr sigs = otype->osigs();
  1356. if (args.num < 0 || args.num >= sigs->count()) {
  1357. result.status = TT_ERR_NUM;
  1358. } else {
  1359. _Tt_signature_ptr sig = (*sigs)[args.num];
  1360. result.str_val = sig->op();
  1361. }
  1362. }
  1363. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1364. (RPC_ARG_T)&result) == 0) {
  1365. return;
  1366. }
  1367. }
  1368. /*
  1369. * Return the op for a handler signature of an otype
  1370. */
  1371. void
  1372. _tt_rpc_otype_hsig_op(SVCXPRT *transp)
  1373. {
  1374. _Tt_otype_args args;
  1375. _Tt_rpc_result result;
  1376. _Tt_otype_ptr otype;
  1377. if (! _tt_svc_getargs(transp,
  1378. (xdrproc_t)tt_xdr_otype_args,
  1379. (char *)&args)) {
  1380. svcerr_decode(transp);
  1381. return;
  1382. }
  1383. result.status = TT_OK;
  1384. result.str_val = "";
  1385. result.int_val = 0;
  1386. otype = _tt_s_mp->otable->lookup(args.base_otid);
  1387. if (otype.is_null()) {
  1388. result.status = TT_ERR_OTYPE;
  1389. } else {
  1390. _Tt_signature_list_ptr sigs = otype->hsigs();
  1391. if (args.num < 0 || args.num >= sigs->count()) {
  1392. result.status = TT_ERR_NUM;
  1393. } else {
  1394. _Tt_signature_ptr sig = (*sigs)[args.num];
  1395. result.str_val = sig->op();
  1396. }
  1397. }
  1398. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1399. (RPC_ARG_T)&result) == 0) {
  1400. return;
  1401. }
  1402. }
  1403. /*
  1404. * Return the number of arguments of an observer signature of an otype
  1405. */
  1406. void
  1407. _tt_rpc_otype_osig_args_count(SVCXPRT *transp)
  1408. {
  1409. _Tt_otype_args args;
  1410. _Tt_rpc_result result;
  1411. _Tt_otype_ptr otype;
  1412. if (! _tt_svc_getargs(transp,
  1413. (xdrproc_t)tt_xdr_otype_args,
  1414. (char *)&args)) {
  1415. svcerr_decode(transp);
  1416. return;
  1417. }
  1418. result.status = TT_OK;
  1419. result.str_val = "";
  1420. result.int_val = 0;
  1421. otype = _tt_s_mp->otable->lookup(args.base_otid);
  1422. if (otype.is_null()) {
  1423. result.status = TT_ERR_OTYPE;
  1424. } else {
  1425. _Tt_signature_list_ptr sigs = otype->osigs();
  1426. if (args.num < 0 || args.num >= sigs->count()) {
  1427. result.status = TT_ERR_NUM;
  1428. } else {
  1429. _Tt_signature_ptr sig = (*sigs)[args.num];
  1430. _Tt_arg_list_ptr sargs = sig->args();
  1431. result.int_val = sargs->count();
  1432. }
  1433. }
  1434. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1435. (RPC_ARG_T)&result) == 0) {
  1436. return;
  1437. }
  1438. }
  1439. /*
  1440. * Return the number of arguments of a handler signature of an otype
  1441. */
  1442. void
  1443. _tt_rpc_otype_hsig_args_count(SVCXPRT *transp)
  1444. {
  1445. _Tt_otype_args args;
  1446. _Tt_rpc_result result;
  1447. _Tt_otype_ptr otype;
  1448. if (! _tt_svc_getargs(transp,
  1449. (xdrproc_t)tt_xdr_otype_args,
  1450. (char *)&args)) {
  1451. svcerr_decode(transp);
  1452. return;
  1453. }
  1454. result.status = TT_OK;
  1455. result.str_val = "";
  1456. result.int_val = 0;
  1457. otype = _tt_s_mp->otable->lookup(args.base_otid);
  1458. if (otype.is_null()) {
  1459. result.status = TT_ERR_OTYPE;
  1460. } else {
  1461. _Tt_signature_list_ptr sigs = otype->hsigs();
  1462. if (args.num < 0 || args.num >= sigs->count()) {
  1463. result.status = TT_ERR_NUM;
  1464. } else {
  1465. _Tt_signature_ptr sig = (*sigs)[args.num];
  1466. _Tt_arg_list_ptr sargs = sig->args();
  1467. result.int_val = sargs->count();
  1468. }
  1469. }
  1470. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1471. (RPC_ARG_T)&result) == 0) {
  1472. return;
  1473. }
  1474. }
  1475. /*
  1476. * Return the mode of the specified arg of an observer signature of an otype
  1477. */
  1478. void
  1479. _tt_rpc_otype_osig_arg_mode(SVCXPRT *transp)
  1480. {
  1481. _Tt_otype_args args;
  1482. _Tt_rpc_result result;
  1483. _Tt_otype_ptr otype;
  1484. if (! _tt_svc_getargs(transp,
  1485. (xdrproc_t)tt_xdr_otype_args,
  1486. (char *)&args)) {
  1487. svcerr_decode(transp);
  1488. return;
  1489. }
  1490. result.status = TT_OK;
  1491. result.str_val = "";
  1492. result.int_val = 0;
  1493. otype = _tt_s_mp->otable->lookup(args.base_otid);
  1494. if (otype.is_null()) {
  1495. result.status = TT_ERR_OTYPE;
  1496. } else {
  1497. _Tt_signature_list_ptr sigs = otype->osigs();
  1498. if (args.num < 0 || args.num >= sigs->count()) {
  1499. result.status = TT_ERR_NUM;
  1500. } else {
  1501. _Tt_signature_ptr sig = (*sigs)[args.num];
  1502. _Tt_arg_list_ptr sargs = sig->args();
  1503. if (args.num2 < 0 || args.num2 >= sargs->count()) {
  1504. result.status = TT_ERR_NUM;
  1505. } else {
  1506. _Tt_arg_ptr sarg = (*sargs)[args.num2];
  1507. result.int_val = (int)sarg->mode();
  1508. }
  1509. }
  1510. }
  1511. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1512. (RPC_ARG_T)&result) == 0) {
  1513. return;
  1514. }
  1515. }
  1516. /*
  1517. * Return the mode of the specified arg of a handler signature of an otype
  1518. */
  1519. void
  1520. _tt_rpc_otype_hsig_arg_mode(SVCXPRT *transp)
  1521. {
  1522. _Tt_otype_args args;
  1523. _Tt_rpc_result result;
  1524. _Tt_otype_ptr otype;
  1525. if (! _tt_svc_getargs(transp,
  1526. (xdrproc_t)tt_xdr_otype_args,
  1527. (char *)&args)) {
  1528. svcerr_decode(transp);
  1529. return;
  1530. }
  1531. result.status = TT_OK;
  1532. result.str_val = "";
  1533. result.int_val = 0;
  1534. otype = _tt_s_mp->otable->lookup(args.base_otid);
  1535. if (otype.is_null()) {
  1536. result.status = TT_ERR_OTYPE;
  1537. } else {
  1538. _Tt_signature_list_ptr sigs = otype->hsigs();
  1539. if (args.num < 0 || args.num >= sigs->count()) {
  1540. result.status = TT_ERR_NUM;
  1541. } else {
  1542. _Tt_signature_ptr sig = (*sigs)[args.num];
  1543. _Tt_arg_list_ptr sargs = sig->args();
  1544. if (args.num2 < 0 || args.num2 >= sargs->count()) {
  1545. result.status = TT_ERR_NUM;
  1546. } else {
  1547. _Tt_arg_ptr sarg = (*sargs)[args.num2];
  1548. result.int_val = (int)sarg->mode();
  1549. }
  1550. }
  1551. }
  1552. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1553. (RPC_ARG_T)&result) == 0) {
  1554. return;
  1555. }
  1556. }
  1557. /*
  1558. * Return the type of the specified arg of an observer signature of an otype
  1559. */
  1560. void
  1561. _tt_rpc_otype_osig_arg_type(SVCXPRT *transp)
  1562. {
  1563. _Tt_otype_args args;
  1564. _Tt_rpc_result result;
  1565. _Tt_otype_ptr otype;
  1566. if (! _tt_svc_getargs(transp,
  1567. (xdrproc_t)tt_xdr_otype_args,
  1568. (char *)&args)) {
  1569. svcerr_decode(transp);
  1570. return;
  1571. }
  1572. result.status = TT_OK;
  1573. result.str_val = "";
  1574. result.int_val = 0;
  1575. otype = _tt_s_mp->otable->lookup(args.base_otid);
  1576. if (otype.is_null()) {
  1577. result.status = TT_ERR_OTYPE;
  1578. } else {
  1579. _Tt_signature_list_ptr sigs = otype->osigs();
  1580. if (args.num < 0 || args.num >= sigs->count()) {
  1581. result.status = TT_ERR_NUM;
  1582. } else {
  1583. _Tt_signature_ptr sig = (*sigs)[args.num];
  1584. _Tt_arg_list_ptr sargs = sig->args();
  1585. if (args.num2 < 0 || args.num2 >= sargs->count()) {
  1586. result.status = TT_ERR_NUM;
  1587. } else {
  1588. _Tt_arg_ptr sarg = (*sargs)[args.num2];
  1589. result.str_val = sarg->type();
  1590. }
  1591. }
  1592. }
  1593. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1594. (RPC_ARG_T)&result) == 0) {
  1595. return;
  1596. }
  1597. }
  1598. /*
  1599. * Return the type of the specified arg of a handler signature of an otype
  1600. */
  1601. void
  1602. _tt_rpc_otype_hsig_arg_type(SVCXPRT *transp)
  1603. {
  1604. _Tt_otype_args args;
  1605. _Tt_rpc_result result;
  1606. _Tt_otype_ptr otype;
  1607. if (! _tt_svc_getargs(transp,
  1608. (xdrproc_t)tt_xdr_otype_args,
  1609. (char *)&args)) {
  1610. svcerr_decode(transp);
  1611. return;
  1612. }
  1613. result.status = TT_OK;
  1614. result.str_val = "";
  1615. result.int_val = 0;
  1616. otype = _tt_s_mp->otable->lookup(args.base_otid);
  1617. if (otype.is_null()) {
  1618. result.status = TT_ERR_OTYPE;
  1619. } else {
  1620. _Tt_signature_list_ptr sigs = otype->hsigs();
  1621. if (args.num < 0 || args.num >= sigs->count()) {
  1622. result.status = TT_ERR_NUM;
  1623. } else {
  1624. _Tt_signature_ptr sig = (*sigs)[args.num];
  1625. _Tt_arg_list_ptr sargs = sig->args();
  1626. if (args.num2 < 0 || args.num2 >= sargs->count()) {
  1627. result.status = TT_ERR_NUM;
  1628. } else {
  1629. _Tt_arg_ptr sarg = (*sargs)[args.num2];
  1630. result.str_val = sarg->type();
  1631. }
  1632. }
  1633. }
  1634. if (svc_sendreply(transp, (xdrproc_t)tt_xdr_rpc_result,
  1635. (RPC_ARG_T)&result) == 0) {
  1636. return;
  1637. }
  1638. }
  1639. //
  1640. // Horizontal (inter-ttsession) dispatch
  1641. //
  1642. void
  1643. _tt_rpc_hdispatch(SVCXPRT *transp)
  1644. {
  1645. _Tt_s_message_ptr msg;
  1646. _Tt_qmsg_info_ptr qm = (_Tt_qmsg_info *)0;
  1647. _Tt_dispatch_reply_args args;
  1648. msg = new _Tt_s_message();
  1649. if (!_tt_svc_getargs(transp,
  1650. (xdrproc_t)tt_xdr_message,
  1651. (char *)&msg)) {
  1652. svcerr_decode(transp);
  1653. return;
  1654. }
  1655. _Tt_msg_trace trace( *msg, TTDR_HDISPATCH );
  1656. (void)msg->dispatch( trace );
  1657. (void)msg->deliver_to_observers_and_handlers( trace );
  1658. }
  1659. //
  1660. // Horizontal (inter-ttsession) update
  1661. //
  1662. void
  1663. _tt_rpc_hupdate_msg(SVCXPRT *transp)
  1664. {
  1665. _Tt_s_procid_ptr sender;
  1666. _Tt_s_update_args args;
  1667. if (!_tt_svc_getargs(transp,
  1668. (xdrproc_t)tt_s_xdr_update_args,
  1669. (char *)&args))
  1670. {
  1671. svcerr_decode(transp);
  1672. return;
  1673. }
  1674. if (! _tt_s_mp->find_proc(args.message->sender(), sender, 0)) {
  1675. return;
  1676. }
  1677. if ( (args.newstate == TT_FAILED)
  1678. && (args.message->status() == TT_ERR_NO_MATCH)
  1679. && (args.message->handler().is_null()))
  1680. {
  1681. //
  1682. // No remote session could find a handler.
  1683. // Simulate a rejection, and redeliver the message.
  1684. // _tried prevents re-offers, but any new handler
  1685. // will get a crack at the request, which is nice.
  1686. // _rsessions will be empty, so if we again find no
  1687. // handler, we will perform disposition instead of
  1688. // hdispatch()ing to remote sessions.
  1689. //
  1690. args.message->set_state(TT_SENT);
  1691. args.message->set_status((int)TT_OK);
  1692. _Tt_msg_trace trace( *args.message, TTDR_HUPDATE );
  1693. if (args.message->indoctrinate( trace ) == TT_OK) {
  1694. args.message->change_state( 0, TT_REJECTED, trace );
  1695. }
  1696. } else {
  1697. args.message->set_state(args.newstate);
  1698. // Tracing occurs inside ::add_message()
  1699. sender->add_message(args.message);
  1700. }
  1701. }
  1702. void
  1703. _tt_rpc_msgread_2(SVCXPRT *transp)
  1704. {
  1705. #ifdef OPT_ADDMSG_DIRECT
  1706. _Tt_procid_ptr p;
  1707. _Tt_s_procid_ptr rp;
  1708. if (! _tt_svc_getargs(transp,
  1709. (xdrproc_t)tt_xdr_procid,
  1710. (char *)&p)) {
  1711. svcerr_decode(transp);
  1712. }
  1713. if (_tt_s_mp->find_proc(p, rp, 0)) {
  1714. rp->msgread();
  1715. }
  1716. #else
  1717. svcerr_noproc(transp);
  1718. #endif // OPT_ADDMSG_DIRECT
  1719. }
  1720. /*
  1721. * Called when a sender sends a message to the server for delivery on exit.
  1722. */
  1723. void
  1724. _tt_rpc_dispatch_on_exit(SVCXPRT *transp)
  1725. {
  1726. _Tt_s_message_ptr msg;
  1727. _Tt_s_procid_ptr proc;
  1728. _Tt_dispatch_reply_args args;
  1729. msg = new _Tt_s_message();
  1730. if (!_tt_svc_getargs(transp,
  1731. (xdrproc_t)tt_xdr_message,
  1732. (char *)&msg)) {
  1733. svcerr_decode(transp);
  1734. return;
  1735. }
  1736. args.status = TT_OK;
  1737. if (_tt_s_mp->find_proc(msg->sender(),proc, 0)) {
  1738. (void)proc->add_on_exit_message(msg);
  1739. } else {
  1740. args.status = TT_ERR_PROCID;
  1741. }
  1742. if (!svc_sendreply(transp,
  1743. (xdrproc_t)tt_xdr_dispatch_reply_args,
  1744. (RPC_ARG_T)&args)) {
  1745. return;
  1746. }
  1747. }