ua_services_view.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. #include "ua_server_internal.h"
  2. #include "ua_services.h"
  3. #include "ua_statuscodes.h"
  4. #include "ua_nodestore.h"
  5. #include "ua_util.h"
  6. static UA_StatusCode fillrefdescr(UA_NodeStore *ns, const UA_Node *curr, UA_ReferenceNode *ref,
  7. UA_UInt32 mask, UA_ReferenceDescription *descr)
  8. {
  9. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  10. UA_ReferenceDescription_init(descr);
  11. retval |= UA_NodeId_copy(&curr->nodeId, &descr->nodeId.nodeId);
  12. //TODO: ExpandedNodeId is mocked up
  13. descr->nodeId.serverIndex = 0;
  14. descr->nodeId.namespaceUri.length = -1;
  15. if(mask & UA_BROWSERESULTMASK_REFERENCETYPEID)
  16. retval |= UA_NodeId_copy(&ref->referenceTypeId, &descr->referenceTypeId);
  17. if(mask & UA_BROWSERESULTMASK_ISFORWARD)
  18. descr->isForward = !ref->isInverse;
  19. if(mask & UA_BROWSERESULTMASK_NODECLASS)
  20. retval |= UA_NodeClass_copy(&curr->nodeClass, &descr->nodeClass);
  21. if(mask & UA_BROWSERESULTMASK_BROWSENAME)
  22. retval |= UA_QualifiedName_copy(&curr->browseName, &descr->browseName);
  23. if(mask & UA_BROWSERESULTMASK_DISPLAYNAME)
  24. retval |= UA_LocalizedText_copy(&curr->displayName, &descr->displayName);
  25. if(mask & UA_BROWSERESULTMASK_TYPEDEFINITION){
  26. if(curr->nodeClass == UA_NODECLASS_OBJECT || curr->nodeClass == UA_NODECLASS_VARIABLE) {
  27. for(UA_Int32 i = 0; i < curr->referencesSize; i++) {
  28. UA_ReferenceNode *refnode = &curr->references[i];
  29. if(refnode->referenceTypeId.identifier.numeric != UA_NS0ID_HASTYPEDEFINITION)
  30. continue;
  31. retval |= UA_ExpandedNodeId_copy(&refnode->targetId, &descr->typeDefinition);
  32. break;
  33. }
  34. }
  35. }
  36. if(retval)
  37. UA_ReferenceDescription_deleteMembers(descr);
  38. return retval;
  39. }
  40. /* Tests if the node is relevant to the browse request and shall be returned. If
  41. so, it is retrieved from the Nodestore. If not, null is returned. */
  42. static const UA_Node *relevant_node(UA_NodeStore *ns, const UA_BrowseDescription *descr,
  43. UA_Boolean return_all, UA_ReferenceNode *reference,
  44. UA_NodeId *relevant, size_t relevant_count)
  45. {
  46. if(reference->isInverse == UA_TRUE && descr->browseDirection == UA_BROWSEDIRECTION_FORWARD)
  47. return UA_NULL;
  48. else if(reference->isInverse == UA_FALSE && descr->browseDirection == UA_BROWSEDIRECTION_INVERSE)
  49. return UA_NULL;
  50. if(!return_all) {
  51. for(size_t i = 0; i < relevant_count; i++) {
  52. if(UA_NodeId_equal(&reference->referenceTypeId, &relevant[i]))
  53. goto is_relevant;
  54. }
  55. return UA_NULL;
  56. }
  57. is_relevant: ;
  58. const UA_Node *node = UA_NodeStore_get(ns, &reference->targetId.nodeId);
  59. if(node && descr->nodeClassMask != 0 && (node->nodeClass & descr->nodeClassMask) == 0) {
  60. UA_NodeStore_release(node);
  61. return UA_NULL;
  62. }
  63. return node;
  64. }
  65. /**
  66. * We find all subtypes by a single iteration over the array. We start with an array with a single
  67. * root nodeid at the beginning. When we find relevant references, we add the nodeids to the back of
  68. * the array and increase the size. Since the hierarchy is not cyclic, we can safely progress in the
  69. * array to process the newly found referencetype nodeids (emulated recursion).
  70. */
  71. static UA_StatusCode findsubtypes(UA_NodeStore *ns, const UA_NodeId *root, UA_NodeId **reftypes,
  72. size_t *reftypes_count)
  73. {
  74. size_t results_size = 20; // probably too big, but saves mallocs
  75. UA_NodeId *results = UA_malloc(sizeof(UA_NodeId) * results_size);
  76. if(!results)
  77. return UA_STATUSCODE_BADOUTOFMEMORY;
  78. const UA_Node *node = UA_NodeStore_get(ns, root);
  79. if(!node || node->nodeClass != UA_NODECLASS_REFERENCETYPE) {
  80. UA_NodeStore_release(node);
  81. UA_free(results);
  82. return UA_STATUSCODE_BADREFERENCETYPEIDINVALID;
  83. }
  84. UA_NodeStore_release(node);
  85. UA_StatusCode retval = UA_NodeId_copy(root, &results[0]);
  86. if(retval != UA_STATUSCODE_GOOD) {
  87. UA_free(results);
  88. return retval;
  89. }
  90. size_t index = 0; // where are we currently in the array?
  91. size_t last = 0; // where is the last element in the array?
  92. do {
  93. node = UA_NodeStore_get(ns, &results[index]);
  94. if(!node || node->nodeClass != UA_NODECLASS_REFERENCETYPE)
  95. continue;
  96. for(UA_Int32 i = 0; i < node->referencesSize; i++) {
  97. if(node->references[i].referenceTypeId.identifier.numeric != UA_NS0ID_HASSUBTYPE ||
  98. node->references[i].isInverse == UA_TRUE)
  99. continue;
  100. if(++last >= results_size) { // is the array big enough?
  101. UA_NodeId *new_results = UA_realloc(results, sizeof(UA_NodeId) * results_size * 2);
  102. if(!new_results) {
  103. retval = UA_STATUSCODE_BADOUTOFMEMORY;
  104. break;
  105. }
  106. results = new_results;
  107. results_size *= 2;
  108. }
  109. retval = UA_NodeId_copy(&node->references[i].targetId.nodeId, &results[last]);
  110. if(retval != UA_STATUSCODE_GOOD) {
  111. last--; // for array_delete
  112. break;
  113. }
  114. }
  115. UA_NodeStore_release(node);
  116. } while(++index <= last && retval == UA_STATUSCODE_GOOD);
  117. if(retval) {
  118. UA_Array_delete(results, &UA_TYPES[UA_TYPES_NODEID], last);
  119. return retval;
  120. }
  121. *reftypes = results;
  122. *reftypes_count = last + 1;
  123. return UA_STATUSCODE_GOOD;
  124. }
  125. /* Results for a single browsedescription. Call this either with an existing continuationpoint from
  126. which we take the entire context for the search. Or, call with a browsedescription and maxrefs
  127. value. If we need to create a new continuationpoint, it will be alloced and the new pointer
  128. stored in *cp.
  129. */
  130. static void browse(UA_NodeStore *ns, struct ContinuationPointEntry **cp, const UA_BrowseDescription *descr,
  131. UA_UInt32 maxrefs, UA_BrowseResult *result)
  132. {
  133. UA_UInt32 continuationIndex = 0;
  134. if(*cp) {
  135. descr = &(*cp)->browseDescription;
  136. maxrefs = (*cp)->maxReferences;
  137. continuationIndex = (*cp)->continuationIndex;
  138. }
  139. if(descr->browseDirection != UA_BROWSEDIRECTION_BOTH &&
  140. descr->browseDirection != UA_BROWSEDIRECTION_FORWARD &&
  141. descr->browseDirection != UA_BROWSEDIRECTION_INVERSE) {
  142. result->statusCode = UA_STATUSCODE_BADBROWSEDIRECTIONINVALID;
  143. return;
  144. }
  145. size_t relevant_refs_size = 0;
  146. UA_NodeId *relevant_refs = UA_NULL;
  147. // what are the relevant references?
  148. UA_Boolean all_refs = UA_NodeId_isNull(&descr->referenceTypeId);
  149. //check if reference type id exists
  150. if(!all_refs && UA_NodeStore_get(ns, &descr->referenceTypeId) == UA_NULL) {
  151. result->statusCode = UA_STATUSCODE_BADREFERENCETYPEIDINVALID;
  152. return;
  153. }
  154. if(!all_refs) {
  155. if(descr->includeSubtypes) {
  156. result->statusCode = findsubtypes(ns, &descr->referenceTypeId, &relevant_refs,
  157. &relevant_refs_size);
  158. if(result->statusCode != UA_STATUSCODE_GOOD)
  159. return;
  160. } else {
  161. relevant_refs = (UA_NodeId*)(uintptr_t)&descr->referenceTypeId;
  162. relevant_refs_size = 1;
  163. }
  164. }
  165. // get the node
  166. const UA_Node *node = UA_NodeStore_get(ns, &descr->nodeId);
  167. if(!node) {
  168. result->statusCode = UA_STATUSCODE_BADNODEIDUNKNOWN;
  169. if(!all_refs && descr->includeSubtypes)
  170. UA_Array_delete(relevant_refs, &UA_TYPES[UA_TYPES_NODEID], relevant_refs_size);
  171. return;
  172. }
  173. if(node->referencesSize <= 0) {
  174. result->referencesSize = 0;
  175. goto cleanup;
  176. }
  177. UA_UInt32 real_maxrefs = maxrefs;
  178. if(real_maxrefs == 0)
  179. real_maxrefs = node->referencesSize;
  180. result->references = UA_malloc(sizeof(UA_ReferenceDescription) * real_maxrefs);
  181. if(!result->references) {
  182. result->statusCode = UA_STATUSCODE_BADOUTOFMEMORY;
  183. goto cleanup;
  184. }
  185. size_t count = 0;
  186. size_t skipped = 0;
  187. for(UA_Int32 i = 0; i < node->referencesSize && count < real_maxrefs; i++) {
  188. const UA_Node *current = relevant_node(ns, descr, all_refs, &node->references[i],
  189. relevant_refs, relevant_refs_size);
  190. if(!current)
  191. continue;
  192. if(skipped < continuationIndex) {
  193. UA_NodeStore_release(current);
  194. skipped++;
  195. continue;
  196. }
  197. UA_StatusCode retval = fillrefdescr(ns, current, &node->references[i], descr->resultMask,
  198. &result->references[count]);
  199. UA_NodeStore_release(current);
  200. if(retval != UA_STATUSCODE_GOOD) {
  201. UA_Array_delete(result->references, &UA_TYPES[UA_TYPES_REFERENCEDESCRIPTION], count);
  202. result->references = UA_NULL;
  203. count = 0;
  204. result->statusCode = UA_STATUSCODE_UNCERTAINNOTALLNODESAVAILABLE;
  205. goto cleanup;
  206. }
  207. count++;
  208. }
  209. if(*cp) {
  210. (*cp)->continuationIndex += count;
  211. if((*cp)->continuationIndex == node->referencesSize) {
  212. /* remove a finished continuationPoint */
  213. UA_ByteString_deleteMembers(&(*cp)->identifier);
  214. UA_BrowseDescription_deleteMembers(&(*cp)->browseDescription);
  215. LIST_REMOVE(*cp, pointers);
  216. UA_free(*cp);
  217. *cp = UA_NULL;
  218. }
  219. } else if(maxrefs != 0 && count >= maxrefs) {
  220. /* create a continuationPoint */
  221. *cp = UA_malloc(sizeof(struct ContinuationPointEntry));
  222. UA_BrowseDescription_copy(descr,&(*cp)->browseDescription);
  223. (*cp)->maxReferences = maxrefs;
  224. (*cp)->continuationIndex = count;
  225. UA_Guid *ident = UA_Guid_new();
  226. UA_UInt32 seed = (uintptr_t)*cp;
  227. *ident = UA_Guid_random(&seed);
  228. (*cp)->identifier.data = (UA_Byte*)ident;
  229. (*cp)->identifier.length = sizeof(UA_Guid);
  230. }
  231. if(count > 0)
  232. result->referencesSize = count;
  233. else {
  234. UA_free(result->references);
  235. result->references = UA_NULL;
  236. }
  237. cleanup:
  238. UA_NodeStore_release(node);
  239. if(!all_refs && descr->includeSubtypes)
  240. UA_Array_delete(relevant_refs, &UA_TYPES[UA_TYPES_NODEID], relevant_refs_size);
  241. }
  242. void Service_Browse(UA_Server *server, UA_Session *session, const UA_BrowseRequest *request,
  243. UA_BrowseResponse *response) {
  244. if(!UA_NodeId_isNull(&request->view.viewId)) {
  245. response->responseHeader.serviceResult = UA_STATUSCODE_BADVIEWIDUNKNOWN;
  246. return;
  247. }
  248. if(request->nodesToBrowseSize <= 0) {
  249. response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
  250. return;
  251. }
  252. size_t size = request->nodesToBrowseSize;
  253. response->results = UA_Array_new(&UA_TYPES[UA_TYPES_BROWSERESULT], size);
  254. if(!response->results) {
  255. response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
  256. return;
  257. }
  258. /* ### Begin External Namespaces */
  259. UA_Boolean *isExternal = UA_alloca(sizeof(UA_Boolean) * size);
  260. UA_memset(isExternal, UA_FALSE, sizeof(UA_Boolean) * size);
  261. UA_UInt32 *indices = UA_alloca(sizeof(UA_UInt32) * size);
  262. for(UA_Int32 j = 0;j<server->externalNamespacesSize;j++) {
  263. size_t indexSize = 0;
  264. for(size_t i = 0;i < size;i++) {
  265. if(request->nodesToBrowse[i].nodeId.namespaceIndex != server->externalNamespaces[j].index)
  266. continue;
  267. isExternal[i] = UA_TRUE;
  268. indices[indexSize] = i;
  269. indexSize++;
  270. }
  271. if(indexSize == 0)
  272. continue;
  273. UA_ExternalNodeStore *ens = &server->externalNamespaces[j].externalNodeStore;
  274. ens->browseNodes(ens->ensHandle, &request->requestHeader, request->nodesToBrowse, indices, indexSize,
  275. request->requestedMaxReferencesPerNode, response->results, response->diagnosticInfos);
  276. }
  277. /* ### End External Namespaces */
  278. response->resultsSize = size;
  279. for(size_t i = 0; i < size; i++) {
  280. if(!isExternal[i]) {
  281. struct ContinuationPointEntry *cp = UA_NULL;
  282. browse(server->nodestore, &cp, &request->nodesToBrowse[i],
  283. request->requestedMaxReferencesPerNode, &response->results[i]);
  284. if(cp) {
  285. LIST_INSERT_HEAD(&session->continuationPoints, cp, pointers);
  286. UA_ByteString_copy(&cp->identifier, &response->results[i].continuationPoint);
  287. }
  288. }
  289. }
  290. }
  291. void Service_BrowseNext(UA_Server *server, UA_Session *session, const UA_BrowseNextRequest *request,
  292. UA_BrowseNextResponse *response) {
  293. if(request->continuationPointsSize <= 0) {
  294. response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
  295. return;
  296. }
  297. size_t size = request->continuationPointsSize;
  298. if(!request->releaseContinuationPoints) {
  299. response->results = UA_Array_new(&UA_TYPES[UA_TYPES_BROWSERESULT], size);
  300. if(!response->results) {
  301. response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
  302. return;
  303. }
  304. response->resultsSize = size;
  305. for(size_t i = 0; i < size; i++) {
  306. struct ContinuationPointEntry *cp = UA_NULL;
  307. struct ContinuationPointEntry *search_cp;
  308. LIST_FOREACH(search_cp, &session->continuationPoints, pointers) {
  309. if(UA_ByteString_equal(&search_cp->identifier, &request->continuationPoints[i])) {
  310. cp = search_cp;
  311. break;
  312. }
  313. }
  314. if(!cp)
  315. response->results[i].statusCode = UA_STATUSCODE_BADCONTINUATIONPOINTINVALID;
  316. else
  317. browse(server->nodestore, &cp, UA_NULL, 0, &response->results[i]);
  318. }
  319. } else {
  320. for(size_t i = 0; i < size; i++) {
  321. struct ContinuationPointEntry *cp = UA_NULL;
  322. LIST_FOREACH(cp, &session->continuationPoints, pointers) {
  323. if(UA_ByteString_equal(&cp->identifier, &request->continuationPoints[i])) {
  324. UA_ByteString_deleteMembers(&cp->identifier);
  325. UA_BrowseDescription_deleteMembers(&cp->browseDescription);
  326. LIST_REMOVE(cp, pointers);
  327. UA_free(cp);
  328. break;
  329. }
  330. }
  331. }
  332. }
  333. }
  334. /***********************/
  335. /* TranslateBrowsePath */
  336. /***********************/
  337. static UA_StatusCode
  338. walkBrowsePath(UA_Server *server, UA_Session *session, const UA_Node *node, const UA_RelativePath *path,
  339. UA_Int32 pathindex, UA_BrowsePathTarget **targets, UA_Int32 *targets_size,
  340. UA_Int32 *target_count)
  341. {
  342. const UA_RelativePathElement *elem = &path->elements[pathindex];
  343. if(elem->targetName.name.length == -1)
  344. return UA_STATUSCODE_BADBROWSENAMEINVALID;
  345. UA_StatusCode retval = UA_STATUSCODE_GOOD;
  346. UA_NodeId *reftypes;
  347. size_t reftypes_count = 1; // all_refs or no subtypes => 1
  348. UA_Boolean all_refs = UA_FALSE;
  349. if(UA_NodeId_isNull(&elem->referenceTypeId))
  350. all_refs = UA_TRUE;
  351. else if(!elem->includeSubtypes)
  352. reftypes = (UA_NodeId*)(uintptr_t)&elem->referenceTypeId; // ptr magic due to const cast
  353. else
  354. retval = findsubtypes(server->nodestore, &elem->referenceTypeId, &reftypes, &reftypes_count);
  355. for(UA_Int32 i = 0; i < node->referencesSize && retval == UA_STATUSCODE_GOOD; i++) {
  356. UA_Boolean match = all_refs;
  357. for(size_t j = 0; j < reftypes_count && !match; j++) {
  358. if(node->references[i].isInverse == elem->isInverse &&
  359. UA_NodeId_equal(&node->references[i].referenceTypeId, &reftypes[j]))
  360. match = UA_TRUE;
  361. }
  362. if(!match)
  363. continue;
  364. // get the node, todo: expandednodeid
  365. const UA_Node *next = UA_NodeStore_get(server->nodestore, &node->references[i].targetId.nodeId);
  366. if(!next)
  367. continue;
  368. // test the browsename
  369. if(elem->targetName.namespaceIndex != next->browseName.namespaceIndex ||
  370. !UA_String_equal(&elem->targetName.name, &next->browseName.name)) {
  371. UA_NodeStore_release(next);
  372. continue;
  373. }
  374. if(pathindex + 1 < path->elementsSize) {
  375. // recursion if the path is longer
  376. retval = walkBrowsePath(server, session, next, path, pathindex + 1,
  377. targets, targets_size, target_count);
  378. UA_NodeStore_release(next);
  379. } else {
  380. // add the browsetarget
  381. if(*target_count >= *targets_size) {
  382. UA_BrowsePathTarget *newtargets;
  383. newtargets = UA_realloc(targets, sizeof(UA_BrowsePathTarget) * (*targets_size) * 2);
  384. if(!newtargets) {
  385. retval = UA_STATUSCODE_BADOUTOFMEMORY;
  386. UA_NodeStore_release(next);
  387. break;
  388. }
  389. *targets = newtargets;
  390. *targets_size *= 2;
  391. }
  392. UA_BrowsePathTarget *res = *targets;
  393. UA_ExpandedNodeId_init(&res[*target_count].targetId);
  394. retval = UA_NodeId_copy(&next->nodeId, &res[*target_count].targetId.nodeId);
  395. UA_NodeStore_release(next);
  396. if(retval != UA_STATUSCODE_GOOD)
  397. break;
  398. res[*target_count].remainingPathIndex = UA_UINT32_MAX;
  399. *target_count += 1;
  400. }
  401. }
  402. if(!all_refs && elem->includeSubtypes)
  403. UA_Array_delete(reftypes, &UA_TYPES[UA_TYPES_NODEID], (UA_Int32)reftypes_count);
  404. return retval;
  405. }
  406. static void translateBrowsePath(UA_Server *server, UA_Session *session, const UA_BrowsePath *path,
  407. UA_BrowsePathResult *result) {
  408. if(path->relativePath.elementsSize <= 0) {
  409. result->statusCode = UA_STATUSCODE_BADNOTHINGTODO;
  410. return;
  411. }
  412. UA_Int32 arraySize = 10;
  413. result->targets = UA_malloc(sizeof(UA_BrowsePathTarget) * arraySize);
  414. if(!result->targets) {
  415. result->statusCode = UA_STATUSCODE_BADOUTOFMEMORY;
  416. return;
  417. }
  418. result->targetsSize = 0;
  419. const UA_Node *firstNode = UA_NodeStore_get(server->nodestore, &path->startingNode);
  420. if(!firstNode) {
  421. result->statusCode = UA_STATUSCODE_BADNODEIDUNKNOWN;
  422. UA_free(result->targets);
  423. result->targets = UA_NULL;
  424. return;
  425. }
  426. result->statusCode = walkBrowsePath(server, session, firstNode, &path->relativePath, 0,
  427. &result->targets, &arraySize, &result->targetsSize);
  428. UA_NodeStore_release(firstNode);
  429. if(result->targetsSize == 0 && result->statusCode == UA_STATUSCODE_GOOD)
  430. result->statusCode = UA_STATUSCODE_BADNOMATCH;
  431. if(result->statusCode != UA_STATUSCODE_GOOD) {
  432. UA_Array_delete(result->targets, &UA_TYPES[UA_TYPES_BROWSEPATHTARGET], result->targetsSize);
  433. result->targets = UA_NULL;
  434. result->targetsSize = -1;
  435. }
  436. }
  437. void Service_TranslateBrowsePathsToNodeIds(UA_Server *server, UA_Session *session,
  438. const UA_TranslateBrowsePathsToNodeIdsRequest *request,
  439. UA_TranslateBrowsePathsToNodeIdsResponse *response) {
  440. if(request->browsePathsSize <= 0) {
  441. response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
  442. return;
  443. }
  444. size_t size = request->browsePathsSize;
  445. response->results = UA_Array_new(&UA_TYPES[UA_TYPES_BROWSEPATHRESULT], size);
  446. if(!response->results) {
  447. response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
  448. return;
  449. }
  450. /* ### Begin External Namespaces */
  451. UA_Boolean *isExternal = UA_alloca(sizeof(UA_Boolean) * size);
  452. UA_memset(isExternal, UA_FALSE, sizeof(UA_Boolean) * size);
  453. UA_UInt32 *indices = UA_alloca(sizeof(UA_UInt32) * size);
  454. for(UA_Int32 j = 0;j<server->externalNamespacesSize;j++) {
  455. size_t indexSize = 0;
  456. for(size_t i = 0;i < size;i++) {
  457. if(request->browsePaths[i].startingNode.namespaceIndex != server->externalNamespaces[j].index)
  458. continue;
  459. isExternal[i] = UA_TRUE;
  460. indices[indexSize] = i;
  461. indexSize++;
  462. }
  463. if(indexSize == 0)
  464. continue;
  465. UA_ExternalNodeStore *ens = &server->externalNamespaces[j].externalNodeStore;
  466. ens->translateBrowsePathsToNodeIds(ens->ensHandle, &request->requestHeader, request->browsePaths,
  467. indices, indexSize, response->results, response->diagnosticInfos);
  468. }
  469. /* ### End External Namespaces */
  470. response->resultsSize = size;
  471. for(size_t i = 0; i < size; i++){
  472. if(!isExternal[i])
  473. translateBrowsePath(server, session, &request->browsePaths[i], &response->results[i]);
  474. }
  475. }
  476. void Service_RegisterNodes(UA_Server *server, UA_Session *session, const UA_RegisterNodesRequest *request,
  477. UA_RegisterNodesResponse *response) {
  478. //TODO: hang the nodeids to the session if really needed
  479. response->responseHeader.timestamp = UA_DateTime_now();
  480. response->registeredNodeIdsSize = request->nodesToRegisterSize;
  481. response->registeredNodeIds = request->nodesToRegister;
  482. if(request->nodesToRegisterSize==0)
  483. response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
  484. if(UA_NodeId_equal(&request->requestHeader.authenticationToken, &UA_NODEID_NULL) ||
  485. !UA_NodeId_equal(&request->requestHeader.authenticationToken, &session->authenticationToken))
  486. response->responseHeader.serviceResult = UA_STATUSCODE_BADSESSIONIDINVALID;
  487. }
  488. void Service_UnregisterNodes(UA_Server *server, UA_Session *session, const UA_UnregisterNodesRequest *request,
  489. UA_UnregisterNodesResponse *response) {
  490. //TODO: remove the nodeids from the session if really needed
  491. response->responseHeader.timestamp = UA_DateTime_now();
  492. if(request->nodesToUnregisterSize==0)
  493. response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
  494. if(UA_NodeId_equal(&request->requestHeader.authenticationToken, &UA_NODEID_NULL) ||
  495. !UA_NodeId_equal(&request->requestHeader.authenticationToken, &session->authenticationToken))
  496. response->responseHeader.serviceResult = UA_STATUSCODE_BADSESSIONIDINVALID;
  497. }