home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / OS2 / LNVREM.ZIP / LNREMSRC.EXE / DECODE.C next >
Text File  |  1993-09-14  |  14KB  |  362 lines

  1. /**********************************************************************************/
  2. /*                                                                                          */
  3. /* COPYRIGHT:  (c) Copyright International Business Machines                */
  4. /*             Corporation 1992                                                        */
  5. /*                                                                                          */
  6. /* NOTICE:  This program is supplied as an example only. No guarantees  */
  7. /*          of any kind, either explicit or implicit, apply to this                 */
  8. /*          program.                                                                     */
  9. /*                                                                                          */
  10. /* FILE:                                                                                   */
  11. /*   DEMO.C                                                                             */
  12. /*                                                                                          */
  13. /* VERSION:                                                                              */
  14. /*  1.0                                                                                    */
  15. /*                                                                                          */
  16. /* DESCRIPTION:                                                                        */
  17. /* TEST DRIVER TO DECODE NAMES FROM VIEW                                */
  18. /*                                                                                          */
  19. /* AUTHOR:                                                                              */
  20. /*  J.M. Rzepka                                                                         */
  21. /*                                                                                         */
  22. /*                                                                                         */
  23. /*********************************************************************************/
  24. /* 
  25. /* ------------------------------------------------------ */
  26.  
  27.  
  28. /* ----------------------------------------------------------------- */
  29. /* Headers                                                           */
  30. /* ----------------------------------------------------------------- */
  31.  
  32. /* C Headers                                                         */
  33.  
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <math.h>
  38. #include<os2.h>
  39. #include<time.h>
  40.  
  41. /* XMP / XOM Headers                                                 */
  42.  
  43. #include <xom.h>
  44. #include <xmp.h>
  45. #include <xmp_cmis.h>
  46. #include <xmp_snmp.h>
  47. /* #include <extdebug.h> */
  48.  
  49. /* Contents Package Headers                                          */
  50. #include <acse.h>
  51. #include <dmi.h>
  52. #include <ems.h>
  53. #include <lnv.h>
  54. #include <op1v4.h>
  55. #include <op1v2.h>
  56. #include <op1v1.h>
  57. #include <gmi.h>
  58. #include <gmo.h>
  59. #include <gcd.h>
  60. #include <gnm.h>
  61. #include <osa.h>
  62. #include <dsmcmtmd.h>
  63. #include <lnh.h>
  64. /* #include <dmoh.h> */
  65.  
  66. /* ----------------------------------------------------------------- */
  67. /* Exports                                                           */
  68. /* ----------------------------------------------------------------- */
  69.  
  70. OM_EXPORT(OM_C_EXTERNAL);
  71. OM_EXPORT(MP_C_CONTEXT);
  72. OM_EXPORT(MP_C_ENTITY_NAME);
  73. OM_EXPORT(MP_C_ERROR);
  74. OM_EXPORT(MP_C_NAME);
  75. OM_EXPORT(MP_C_SESSION);
  76. OM_EXPORT(MP_C_TITLE);
  77. OM_EXPORT(OM_C_ENCODING);
  78.  
  79.  
  80.  
  81. /*            CMIS Package   */
  82.  
  83. /*     package classes     */
  84.  
  85. OM_EXPORT(C_LNV_CMOT_SYSTEM_ID);
  86. OM_EXPORT(C_DMI_SYSTEM_ID);
  87. OM_EXPORT(C_GNM_NAME_TYPE);
  88. OM_EXPORT(GNM_A_NETWORK_ID);
  89.  
  90.  
  91. /* ----------------------------------------------------------------- */
  92. /* Public Session objects (STATIC DESCRIPTOR STRUCTURES)         */
  93. /* ----------------------------------------------------------------- */
  94.  
  95.  
  96.    /*         CMIP SPECIFIC STRUCTURES       */
  97.  
  98.  
  99. static OM_descriptor    req_title[] = {
  100.     OM_OID_DESC(OM_CLASS, MP_C_ENTITY_NAME),
  101.     {MP_ENTITY,OM_S_PRINTABLE_STRING,OM_STRING("Test Manager")},
  102.     OM_NULL_DESCRIPTOR
  103. };
  104.  
  105.  
  106. static OM_descriptor    session_opts[] = {
  107.     OM_OID_DESC(OM_CLASS, MP_C_SESSION),
  108.     {MP_REQUESTOR_TITLE,OM_S_OBJECT,{0,req_title}},
  109.     OM_NULL_DESCRIPTOR
  110. };
  111.  
  112.  
  113. static OM_descriptor    context_opts[] = {
  114.     OM_OID_DESC(OM_CLASS, MP_C_CONTEXT),
  115.     {MP_MODE,OM_S_ENUMERATION,MP_T_CONFIRMED},
  116.     {MP_ASYNCHRONOUS,OM_S_BOOLEAN,OM_FALSE},
  117.     OM_NULL_DESCRIPTOR
  118. };
  119.  
  120.  
  121. static OM_descriptor pub_decode_arg[] = {
  122.     OM_OID_DESC(OM_CLASS, OM_C_ENCODING),
  123.     {OM_OBJECT_CLASS,OM_S_OBJECT_IDENTIFIER_STRING,{0,NULL}},
  124.     {OM_OBJECT_ENCODING,OM_S_ENCODING_STRING,{0,NULL}},
  125.     {OM_RULES,OM_S_OBJECT_IDENTIFIER_STRING,{0,NULL}},
  126.     OM_NULL_DESCRIPTOR
  127. };
  128.  
  129. /* ---------------------------------------------------------- */
  130. /* Other Global Data                                                                                                  */
  131. /* ---------------------------------------------------------- */
  132.  
  133. OM_workspace        ws; /* global workspace pointer */
  134. MP_feature  feature_list[] = {
  135.     {OM_STRING(OMP_O_OM_OM),OM_TRUE},
  136.     {OM_STRING(OMP_O_MP_COMMON_PKG),OM_TRUE},
  137.     {OM_STRING(OMP_O_MP_CMIS_PKG),OM_TRUE},
  138.     {OM_STRING(OMP_O_LNV),OM_TRUE},
  139.     {OM_STRING(OMP_O_ACSE),OM_TRUE}, 
  140.     {OM_STRING(OMP_O_SMI_PART2),OM_TRUE},
  141.     {OM_STRING(OMP_O_SMI_PART5),OM_TRUE},
  142.     {OM_STRING(OMP_O_OP1_VOL4),OM_TRUE}, 
  143.     {OM_STRING(OMP_O_OP1_VOL2),OM_TRUE}, 
  144.     {{0,NULL},OM_FALSE}};  /* includes all packages to be used */
  145.  
  146.  
  147.     typedef  OM_return_code  OM_status;
  148.  
  149.     int          flag;
  150.     OM_private_object       bound_session;
  151.     OM_private_object       session;
  152.     OM_private_object       context;
  153.     OM_private_object       decoded_arg; 
  154.     OM_sint                    invoke_id;
  155.     MP_status                 mp_ret;
  156.     OM_return_code         omstat;
  157.     OM_value_position      total;
  158.     char                        error_text[100] ;  /*display error msg text */     
  159.         OM_status                 rc;
  160.     
  161.  
  162. /* ----------------------------------------------------------- */
  163. /* function:  DNDecode                                                                          */                                                                     
  164. /*                                                                                                  */
  165. /*  description:   process VIEW info and return command string                      */
  166. /*                                                                                                  */
  167. /* ----------------------------------------------------------- */
  168.  
  169.  
  170. ULONG DNDecode(PVOID y, NIDSIDSTRUC *pNIDSIDStruc )
  171. {
  172.    ULONG    rcode;
  173.    OM_private_object  privateMOI,privateDecodeArg,privateMOC;
  174.    ULONG  walk(OM_private_object decoded_arg,char *netid,char *sysid);
  175.    TOP_DN    *x;
  176.    char       netid[30],sysid[30];
  177.  
  178.     x=y;
  179.     flag=0;     /* indicate first data item is the netid  */
  180.   
  181.        /*              Initialize the workspace                                */
  182.  
  183.      ws =mp_initialize();                        /* frame work initialization command  */
  184.      mp_ret = mp_version(ws,feature_list); /* version command */
  185.      if (mp_ret != MP_SUCCESS)  {
  186.        mp_error_message(mp_ret,100,error_text);
  187.        printf("mp_version : %s\n",error_text);
  188.        return((ULONG) mp_ret);  
  189.       }
  190.   
  191.       /*                        Build the session object                                 */
  192.  
  193.     omstat = om_create(MP_C_SESSION,OM_TRUE,ws,&session);
  194.     omstat = om_put(session,OM_REPLACE_ALL,session_opts,NULL,0,0);
  195.     if (omstat != OM_SUCCESS) {
  196.       printf("omput Failure:  %d\n",omstat);
  197.       return((ULONG) omstat); 
  198.      }
  199.  
  200.     /*                        Initialize the context object                       */
  201.  
  202.       omstat = om_create(MP_C_CONTEXT,OM_TRUE,ws,&context);
  203.       if (omstat != OM_SUCCESS)  { 
  204.         printf("omput Failure:  %d\n",omstat);
  205.         return((ULONG) omstat);   } 
  206.       omstat = om_put(context,OM_REPLACE_ALL,context_opts,NULL,0,0); 
  207.       if (omstat != OM_SUCCESS) {
  208.         printf("omput Failure:  %d\n",omstat);
  209.         return((ULONG) omstat);    }
  210.  
  211.      /*                      Bind to the infrastructure                      */
  212.  
  213.       
  214.       mp_ret = mp_bind(session,ws,&bound_session);  /* bind command */
  215.       printf("BIND COMPLETE\n"); 
  216.         if (mp_ret != MP_SUCCESS) {
  217.           mp_error_message(mp_ret,100,error_text);
  218.           printf("mp_bind : %s\n",error_text);
  219.           return((ULONG) mp_ret);
  220.        }
  221.  
  222.  
  223.      /*   BUILD THE DECODED MOC & MOI FROM THE PASSED VALUE    */
  224.  
  225.     pub_decode_arg[1].value.string.length=x->encodedMOI->MOC.length;
  226.     pub_decode_arg[1].value.string.elements=x->encodedMOI->MOC.string;
  227.     pub_decode_arg[2].value.string.length=x->encodedMOI->Encoding.length;
  228.     pub_decode_arg[2].value.string.elements=x->encodedMOI->Encoding.string;
  229.     pub_decode_arg[3].value.string.length=x->encodedMOI->Rules.length;
  230.     pub_decode_arg[3].value.string.elements=x->encodedMOI->Rules.string;
  231.  
  232.     omstat = om_create(OM_C_ENCODING,OM_FALSE,ws,&privateDecodeArg);
  233.     if (omstat != OM_SUCCESS){
  234.       printf( "om_create failure %d\n",omstat);
  235.       return((ULONG) omstat);  }
  236.     omstat = om_put(privateDecodeArg,OM_REPLACE_ALL,pub_decode_arg,NULL,0,0);
  237.     if (omstat != OM_SUCCESS){
  238.       printf( "om_create failure %d\n",omstat);
  239.       return((ULONG) omstat); }
  240.     omstat = om_decode(privateDecodeArg,&privateMOI);
  241.     if (omstat != OM_SUCCESS){
  242.       printf( "om_create failure %d\n",omstat); 
  243.       return((ULONG) omstat);}
  244.         
  245.   /* EXTRACT THE NETID, AND SYSID FROM THE ENCODED NAME   */
  246.  
  247.     rcode=walk(privateMOI,netid,sysid);
  248.     printf("identifiers : %s  %s  %d\n",netid,sysid,rcode);
  249.     if (rcode == 0)     {
  250.     pNIDSIDStruc->NetID= (PSZ) malloc(strlen(netid)+1);
  251.     pNIDSIDStruc->SysID= (PSZ) malloc(strlen(sysid)+1);
  252.     strcpy(pNIDSIDStruc->NetID,netid);
  253.     strcpy(pNIDSIDStruc->SysID,sysid);
  254.     }
  255.    
  256.      
  257.   /*  house keeping   delete structures created     */
  258.  
  259.     (void) om_delete(privateDecodeArg);
  260.     (void) om_delete(privateMOI);
  261.     mp_unbind(bound_session);
  262.     return(rcode); 
  263. }
  264.  
  265.  
  266.  
  267.  
  268. /**********************************************************************************/
  269. /*                                                                                          */
  270. /* function walk()                                                                       */
  271. /*                                                                                          */
  272. /* DESCRIPTION:    Private Object Parser                                          */
  273. /*                                                                                          */
  274. /*                                                                                          */
  275. /**********************************************************************************/
  276.  
  277.  
  278. ULONG walk(OM_private_object descr,char *netid,char *sysid)  {       
  279.   
  280.    OM_descriptor         *attr_descriptor;  /* used to index through output */
  281.    OM_private_object    pub_arg;
  282.    int                        i;
  283.    char                     *sattr;
  284.    ULONG                   rct;
  285.  
  286.    /*   make sure we have something to look at    */ 
  287.  
  288.        if (flag==2) return(rct);
  289.        if (descr == MP_ABSENT_OBJECT) {
  290.        printf("Status: Absent Object\n");
  291.       return(4);
  292.              }
  293.  
  294.       omstat =  om_get(descr,OM_EXCLUDE_SUBOBJECTS,NULL,OM_FALSE,0,
  295.                             OM_ALL_VALUES,&pub_arg,&total);
  296.       if (omstat != OM_SUCCESS) {
  297.        printf("OMSTAT ERROR : %X occurred \n",omstat);
  298.        return((ULONG) omstat ); }      
  299.  
  300.     /* Traverse All Descriptors At This Level In Tree   */
  301.  
  302.     for(attr_descriptor=pub_arg;
  303.         attr_descriptor->type != OM_NO_MORE_TYPES; 
  304.         ++attr_descriptor) {
  305.   
  306.         if (flag == 2) return(rct);
  307.         switch (attr_descriptor->syntax & OM_S_SYNTAX) {
  308.         case OM_S_OBJECT:
  309.         rct=walk(attr_descriptor->value.object.object,netid,sysid); /* Object Pointer Next Lvl */
  310.         break;
  311.  
  312.         case OM_S_OBJECT_IDENTIFIER_STRING : 
  313.         rct=1;
  314.         break;
  315.  
  316.         case OM_S_GRAPHIC_STRING:
  317.         case OM_S_OCTET_STRING:
  318.         sattr=attr_descriptor->value.string.elements;
  319.         if (flag == 0) {
  320.           for (i=0;
  321.              i < attr_descriptor->value.string.length;
  322.              i++ )  {
  323.              netid[i]=sattr[i];
  324.              }
  325.  
  326.              netid[attr_descriptor->value.string.length]=0; 
  327.              printf("net id: %s\n",netid);
  328.              flag=1;
  329.              rct=1;             
  330.             }
  331.  
  332.         else
  333.              {
  334.              for (i=0;
  335.              i < attr_descriptor->value.string.length;
  336.              i++ )  {
  337.              sysid[i]=sattr[i];
  338.              }
  339.  
  340.              sysid[attr_descriptor->value.string.length]=0;  
  341.              printf("sysid: %s\n",sysid);
  342.              flag=2;
  343.              rct=0;
  344.             }
  345.          break;
  346.  
  347.  
  348.  
  349.        default:
  350.              break; 
  351.              rct=1;   
  352.              } /* End Case Statement  */
  353.  
  354.                     }    /* End For Loop          */
  355.   
  356.          om_delete(pub_arg);
  357.          return(rct);
  358.       }           /*  End Walk              */
  359.  
  360.  
  361.  
  362.