PageRenderTime 56ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/sblim-cmpi-network-1.4.0/cmpiOSBase_NetworkPortImplementsIPEndpoint.c

#
C | 405 lines | 282 code | 73 blank | 50 comment | 77 complexity | 4fdb7a16f0a136b0745039537b9df37b MD5 | raw file
Possible License(s): EPL-1.0
  1. /*
  2. * cmpiOSBase_NetworkPortImplementsIPEndpoint.c
  3. *
  4. * (C) Copyright IBM Corp. 2002, 2009
  5. *
  6. * THIS FILE IS PROVIDED UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE
  7. * ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE
  8. * CONSTITUTES RECIPIENTS ACCEPTANCE OF THE AGREEMENT.
  9. *
  10. * You can obtain a current copy of the Eclipse Public License from
  11. * http://www.opensource.org/licenses/eclipse-1.0.php
  12. *
  13. * Author: Heidi Neumann <heidineu@de.ibm.com>
  14. * Contributors:
  15. *
  16. * Interface Type : Common Magabeablity Programming Interface ( CMPI )
  17. *
  18. * Description:
  19. * This is the factory implementation for creating instances of CIM
  20. * class Linux_NetworkPortImplementsIPEndpoint.
  21. *
  22. */
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "cmpidt.h"
  27. #include "cmpimacs.h"
  28. #include "cmpiOSBase_Common.h"
  29. #include "OSBase_Common.h"
  30. #include "OSBase_CommonNetwork.h"
  31. #include "cmpiOSBase_NetworkPortImplementsIPEndpoint.h"
  32. /* ---------------------------------------------------------------------------*/
  33. /* private declarations */
  34. /* ---------------------------------------------------------------------------*/
  35. /* ---------------------------------------------------------------------------*/
  36. /* Factory functions */
  37. /* ---------------------------------------------------------------------------*/
  38. int _assoc_create_inst_NetworkPortImplementsIPEndpoint( const CMPIBroker * _broker,
  39. const CMPIContext * ctx,
  40. const CMPIResult * rslt,
  41. const CMPIObjectPath * cop,
  42. int inst,
  43. CMPIStatus * rc) {
  44. CMPIObjectPath * op = NULL;
  45. CMPIEnumeration * en = NULL;
  46. CMPIData data ;
  47. int cmdrc = 0;
  48. _OSBASE_TRACE(2,("--- _assoc_create_inst_NetworkPortImplementsIPEndpoint() called"));
  49. op = CMNewObjectPath( _broker, CMGetCharPtr(CMGetNameSpace(cop,rc)),
  50. _RefRightClass, rc );
  51. if( CMIsNullObject(op) ) {
  52. CMSetStatusWithChars( _broker, rc,
  53. CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed." );
  54. _OSBASE_TRACE(2,("--- _assoc_create_inst_NetworkPortImplementsIPEndpoint() failed : %s",CMGetCharPtr(rc->msg)));
  55. return -1;
  56. }
  57. en = CBEnumInstanceNames( _broker, ctx, op, rc);
  58. if( en == NULL ) {
  59. CMSetStatusWithChars( _broker, rc,
  60. CMPI_RC_ERR_FAILED, "CBEnumInstanceNames( _broker, ctx, op, rc)" );
  61. _OSBASE_TRACE(2,("--- _assoc_create_inst_NetworkPortImplementsIPEndpoint() failed : %s",CMGetCharPtr(rc->msg)));
  62. return -1;
  63. }
  64. /* this approach works only from OperatingSystem to the CMPIInstance(s)
  65. * of the different supported LocalFileSystems
  66. */
  67. while( CMHasNext( en, rc) ) {
  68. data = CMGetNext( en, rc);
  69. if( data.value.ref == NULL ) {
  70. CMSetStatusWithChars( _broker, rc,
  71. CMPI_RC_ERR_FAILED, "CMGetNext( en, rc)" );
  72. _OSBASE_TRACE(2,("--- _assoc_create_inst_NetworkPortImplementsIPEndpoint() failed : %s",CMGetCharPtr(rc->msg)));
  73. return -1;
  74. }
  75. cmdrc = _assoc_NetworkPortImplementsIPEndpoint( _broker, ctx,rslt,data.value.ref,
  76. inst,0,rc);
  77. }
  78. _OSBASE_TRACE(2,("--- _assoc_create_inst_NetworkPortImplementsIPEndpoint() exited"));
  79. return 0;
  80. }
  81. CMPIInstance * _assoc_get_networkPort_INST( const CMPIBroker * _broker,
  82. const CMPIContext * ctx,
  83. const CMPIObjectPath * ref,
  84. CMPIStatus * rc) {
  85. CMPIInstance * ci = NULL;
  86. CMPIStatus nprc = {CMPI_RC_OK, NULL};
  87. CMPIObjectPath * op = NULL;
  88. CMPIString * name = NULL;
  89. CMPIString * npname = NULL;
  90. char * targetClass[3] = { _RefLeftClassEth, _RefLeftClassTr, _RefLeftClassLo };
  91. char * ptr = NULL;
  92. char * npptr = NULL;
  93. char * id = NULL;
  94. int i = 0;
  95. int linkTech = 0;
  96. _OSBASE_TRACE(2,("--- _assoc_get_networkPort_INST() called"));
  97. name = CMGetKey( ref, "Name", rc).value.string;
  98. if( name == NULL ) { goto exit; }
  99. ptr = CMGetCharPtr(name);
  100. /* tool method call to get the unique name of the system */
  101. if( !get_system_name() ) {
  102. CMSetStatusWithChars( _broker, rc,
  103. CMPI_RC_ERR_FAILED, "no host name found" );
  104. _OSBASE_TRACE(2,("--- _assoc_get_networkPort_INST() failed : %s",CMGetCharPtr(rc->msg)));
  105. goto exit;
  106. }
  107. id = calloc(1,(strlen(ptr)-4));
  108. strcpy(id,ptr+5);
  109. for (i = 0; i < 3; i++)
  110. {
  111. /* create CMPIObjectPath of subclass of NetworkPort */
  112. op = CMNewObjectPath( _broker, CMGetCharPtr(CMGetNameSpace(ref,rc)), targetClass[i], rc );
  113. if (CMIsNullObject(op))
  114. {
  115. CMSetStatusWithChars(_broker, rc, CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed.");
  116. _OSBASE_TRACE(2,("--- _assoc_get_networkPort_INST() failed : %s",CMGetCharPtr(rc->msg)));
  117. ci = NULL;
  118. goto exit;
  119. }
  120. CMSetNameSpace(op,CMGetCharPtr(CMGetNameSpace(ref,rc)));
  121. CMAddKey(op, "SystemCreationClassName", CSCreationClassName, CMPI_chars);
  122. CMAddKey(op, "SystemName", get_system_name(), CMPI_chars);
  123. CMAddKey(op, "CreationClassName", targetClass[i], CMPI_chars);
  124. CMAddKey(op, "DeviceID", id, CMPI_chars);
  125. ci = CBGetInstance(_broker,ctx,op,NULL,rc);
  126. if (ci == NULL)
  127. {
  128. CMSetStatusWithChars(_broker, rc, CMPI_RC_ERR_FAILED, "CBGetInstance(_broker,ctx,op,NULL,rc)");
  129. _OSBASE_TRACE(2,("--- _assoc_get_networkPort_INST() failed : %s",CMGetCharPtr(rc->msg)));
  130. goto exit;
  131. }
  132. npname = CMGetProperty( ci, "Name", &nprc).value.string;
  133. npptr = CMGetCharPtr(npname);
  134. linkTech = CMGetProperty( ci, "LinkTechnology", &nprc).value.uint16;
  135. if (strstr(ptr, npptr) && (linkTech == 2 && i == 0 ||
  136. linkTech == 7 && i == 1 || linkTech == 1 && i == 2))
  137. break;
  138. }
  139. exit:
  140. if(id) free(id);
  141. _OSBASE_TRACE(2,("--- _assoc_get_networkPort_INST() exited"));
  142. return ci;
  143. }
  144. CMPIInstance * _assoc_get_ipEndpoint_INST( const CMPIBroker * _broker,
  145. const CMPIContext * ctx,
  146. const CMPIObjectPath * ref,
  147. CMPIStatus * rc) {
  148. CMPIInstance * ci = NULL;
  149. CMPIObjectPath * op = NULL;
  150. CMPIData id;
  151. char * name = NULL;
  152. _OSBASE_TRACE(2,("--- _assoc_get_ipEndpoint_INST() called"));
  153. id = CMGetKey( ref, "DeviceID", rc);
  154. if( id.value.string == NULL ) {
  155. CMSetStatusWithChars( _broker, rc,
  156. CMPI_RC_ERR_FAILED, "CMGetKey( ref, 'DeviceID', rc)" );
  157. _OSBASE_TRACE(2,("--- _assoc_get_ipEndpoint_INST() failed : %s",CMGetCharPtr(rc->msg)));
  158. goto exit;
  159. }
  160. /* tool method call to get the unique name of the system */
  161. if( !get_system_name() ) {
  162. CMSetStatusWithChars( _broker, rc,
  163. CMPI_RC_ERR_FAILED, "no host name found" );
  164. _OSBASE_TRACE(2,("--- _assoc_get_ipEndpoint_INST() failed : %s",CMGetCharPtr(rc->msg)));
  165. goto exit;
  166. }
  167. /* create CMPIObjectPath of "Linux_IPProtocolEndpoint" */
  168. op = CMNewObjectPath( _broker, CMGetCharPtr(CMGetNameSpace(ref,rc)),
  169. _RefRightClass, rc );
  170. if( CMIsNullObject(op) ) {
  171. CMSetStatusWithChars( _broker, rc,
  172. CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed." );
  173. _OSBASE_TRACE(2,("--- _assoc_get_ipEndpoint_INST() failed : %s",CMGetCharPtr(rc->msg)));
  174. goto exit;
  175. }
  176. name = _get_ipProtocolEndpoint_name(CMGetCharPtr(id.value.string));
  177. CMSetNameSpace(op,CMGetCharPtr(CMGetNameSpace(ref,rc)));
  178. CMAddKey(op, "SystemCreationClassName", CSCreationClassName, CMPI_chars);
  179. CMAddKey(op, "SystemName", get_system_name(), CMPI_chars);
  180. CMAddKey(op, "CreationClassName", _RefRightClass, CMPI_chars);
  181. CMAddKey(op, "Name", name, CMPI_chars);
  182. ci = CBGetInstance(_broker,ctx,op,NULL,rc);
  183. if( ci == NULL ) {
  184. CMSetStatusWithChars( _broker, rc,
  185. CMPI_RC_ERR_FAILED, "CBGetInstance(_broker,ctx,op,NULL,rc)" );
  186. _OSBASE_TRACE(2,("--- _assoc_get_ipEndpoint_INST() failed : %s",CMGetCharPtr(rc->msg)));
  187. }
  188. if(name) free(name);
  189. exit:
  190. _OSBASE_TRACE(2,("--- _assoc_get_ipEndpoint_INST() exited"));
  191. return ci;
  192. }
  193. CMPIObjectPath * _assoc_get_assoc_OP_NetworkPortImplementsIPEndpoint(
  194. const CMPIBroker * _broker,
  195. const CMPIObjectPath * ref_left,
  196. const CMPIObjectPath * ref_right,
  197. CMPIStatus * rc) {
  198. CMPIObjectPath * op = NULL;
  199. CMPIInstance * ci = NULL;
  200. _OSBASE_TRACE(4,("--- _assoc_get_assoc_OP_NetworkPortImplementsIPEndpoint() called"));
  201. ci = _assoc_get_assoc_INST_NetworkPortImplementsIPEndpoint(_broker,
  202. ref_left,ref_right,
  203. rc);
  204. if( ci == NULL ) { return NULL; }
  205. op = CMGetObjectPath(ci,rc);
  206. CMSetNameSpace(op,CMGetCharPtr(CMGetNameSpace(ref_left,rc)));
  207. _OSBASE_TRACE(4,("--- _assoc_get_assoc_OP_NetworkPortImplementsIPEndpoint() exited"));
  208. return op;
  209. }
  210. CMPIInstance * _assoc_get_assoc_INST_NetworkPortImplementsIPEndpoint(
  211. const CMPIBroker * _broker,
  212. const CMPIObjectPath * ref_left,
  213. const CMPIObjectPath * ref_right,
  214. CMPIStatus * rc) {
  215. CMPIObjectPath * op = NULL;
  216. CMPIInstance * ci = NULL;
  217. _OSBASE_TRACE(4,("--- _assoc_get_assoc_INST_NetworkPortImplementsIPEndpoint() called"));
  218. /* create CMPIObjectPath of this association <_ClassName> */
  219. op = CMNewObjectPath( _broker, CMGetCharPtr(CMGetNameSpace(ref_left,rc)),
  220. _ClassName, rc );
  221. if( CMIsNullObject(op) ) {
  222. CMSetStatusWithChars( _broker, rc,
  223. CMPI_RC_ERR_FAILED, "Create CMPIObjectPath failed." );
  224. _OSBASE_TRACE(4,("--- _assoc_get_assoc_INST_NetworkPortImplementsIPEndpoint() failed : %s",CMGetCharPtr(rc->msg)));
  225. goto exit;
  226. }
  227. ci = CMNewInstance( _broker, op, rc);
  228. if( CMIsNullObject(ci) ) {
  229. CMSetStatusWithChars( _broker, rc,
  230. CMPI_RC_ERR_FAILED, "Create CMPIInstance failed." );
  231. _OSBASE_TRACE(4,("--- _assoc_get_assoc_INST_NetworkPortImplementsIPEndpoint() failed : %s",CMGetCharPtr(rc->msg)));
  232. goto exit;
  233. }
  234. CMSetProperty( ci, _RefLeft, (CMPIValue*)&(ref_left), CMPI_ref );
  235. CMSetProperty( ci, _RefRight, (CMPIValue*)&(ref_right), CMPI_ref );
  236. exit:
  237. _OSBASE_TRACE(4,("--- _assoc_get_assoc_INST_NetworkPortImplementsIPEndpoint() exited"));
  238. return ci;
  239. }
  240. /* combination of int <inst> and int <associators> :
  241. * 0 0 -> referenceNames()
  242. * 1 0 -> references()
  243. * 0 1 -> associatorNames()
  244. * 1 1 -> associators()
  245. */
  246. int _assoc_NetworkPortImplementsIPEndpoint( const CMPIBroker * _broker,
  247. const CMPIContext * ctx,
  248. const CMPIResult * rslt,
  249. const CMPIObjectPath * ref,
  250. int inst,
  251. int associators,
  252. CMPIStatus * rc) {
  253. CMPIInstance * cis = NULL;
  254. CMPIInstance * ci = NULL;
  255. CMPIInstance * rci = NULL;
  256. CMPIObjectPath * op = NULL;
  257. CMPIObjectPath * rop = NULL;
  258. const char * targetClass = NULL;
  259. int cmdrc = 0;
  260. _OSBASE_TRACE(2,("--- _assoc_NetworkPortImplementsIPEndpoint() called"));
  261. /* check if source instance does exist */
  262. cis = CBGetInstance(_broker, ctx, ref, NULL, rc);
  263. if( cis == NULL ) {
  264. if( rc->rc == CMPI_RC_ERR_FAILED ) {
  265. CMSetStatusWithChars( _broker, rc,
  266. CMPI_RC_ERR_FAILED, "GetInstance of source object failed.");
  267. }
  268. if( rc->rc == CMPI_RC_ERR_NOT_FOUND ) {
  269. CMSetStatusWithChars( _broker, rc,
  270. CMPI_RC_ERR_NOT_FOUND, "Source object not found.");
  271. }
  272. _OSBASE_TRACE(2,("--- _assoc_NetworkPortImplementsIPEndpoint() failed : %s",
  273. CMGetCharPtr(rc->msg)));
  274. return -1;
  275. }
  276. targetClass = _assoc_targetClass_Name(_broker,ref,_RefLeftClass,_RefRightClass,rc);
  277. if( targetClass == NULL ) { goto exit; }
  278. if( strcasecmp(targetClass,_RefRightClass) == 0 ) {
  279. /* returned instances are of type "Linux_IPProtocolEndpoint" */
  280. ci = _assoc_get_ipEndpoint_INST( _broker, ctx, ref, rc);
  281. }
  282. else if( strcasecmp(targetClass,_RefLeftClass) == 0 ) {
  283. /* returned instances are subclasses of type CIM_NetworkPort */
  284. ci = _assoc_get_networkPort_INST( _broker, ctx, ref, rc);
  285. }
  286. else { goto exit; }
  287. if( ci == NULL ) {
  288. CMSetStatus(rc,CMPI_RC_OK);
  289. goto exit;
  290. }
  291. op = CMGetObjectPath(ci,rc);
  292. if( op == NULL ) { goto exit; }
  293. CMSetNameSpace(op,CMGetCharPtr(CMGetNameSpace(ref,rc)));
  294. if( associators == 0 ) {
  295. /* references() || referenceNames() */
  296. if( inst == 0 ) {
  297. if( strcasecmp(targetClass,_RefRightClass) == 0 ) {
  298. rop = _assoc_get_assoc_OP_NetworkPortImplementsIPEndpoint( _broker, ref, op,rc );
  299. }
  300. else if( strcasecmp(targetClass,_RefLeftClass) == 0 ) {
  301. rop = _assoc_get_assoc_OP_NetworkPortImplementsIPEndpoint( _broker, op, ref, rc );
  302. }
  303. if( op == NULL ) { goto exit; }
  304. CMReturnObjectPath( rslt, rop );
  305. }
  306. else { /* inst == 1 */
  307. if( strcasecmp(targetClass,_RefRightClass) == 0 ) {
  308. rci = _assoc_get_assoc_INST_NetworkPortImplementsIPEndpoint( _broker, ref, op,rc );
  309. }
  310. else if( strcasecmp(targetClass,_RefLeftClass) == 0 ) {
  311. rci = _assoc_get_assoc_INST_NetworkPortImplementsIPEndpoint( _broker, op, ref, rc );
  312. }
  313. if( rci == NULL ) { goto exit; }
  314. CMReturnInstance( rslt, rci );
  315. }
  316. }
  317. else { /* associators == 1 */
  318. /* associators() || associatorNames() */
  319. if( inst == 0 ) {
  320. CMReturnObjectPath( rslt, op );
  321. }
  322. else { /* inst == 1 */
  323. CMReturnInstance( rslt, ci );
  324. }
  325. }
  326. exit:
  327. _OSBASE_TRACE(2,("--- _assoc_NetworkPortImplementsIPEndpoint() exited"));
  328. return cmdrc;
  329. }
  330. /* ---------------------------------------------------------------------------*/
  331. /* end of cmpiOSBase_NetworkPortImplementsIPEndpoint.c */
  332. /* ---------------------------------------------------------------------------*/