home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #1
/
monster.zip
/
monster
/
OS2
/
LNVREM.ZIP
/
LNREMSRC.EXE
/
DECODE.C
next >
Wrap
Text File
|
1993-09-14
|
14KB
|
362 lines
/**********************************************************************************/
/* */
/* COPYRIGHT: (c) Copyright International Business Machines */
/* Corporation 1992 */
/* */
/* NOTICE: This program is supplied as an example only. No guarantees */
/* of any kind, either explicit or implicit, apply to this */
/* program. */
/* */
/* FILE: */
/* DEMO.C */
/* */
/* VERSION: */
/* 1.0 */
/* */
/* DESCRIPTION: */
/* TEST DRIVER TO DECODE NAMES FROM VIEW */
/* */
/* AUTHOR: */
/* J.M. Rzepka */
/* */
/* */
/*********************************************************************************/
/*
/* ------------------------------------------------------ */
/* ----------------------------------------------------------------- */
/* Headers */
/* ----------------------------------------------------------------- */
/* C Headers */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include<os2.h>
#include<time.h>
/* XMP / XOM Headers */
#include <xom.h>
#include <xmp.h>
#include <xmp_cmis.h>
#include <xmp_snmp.h>
/* #include <extdebug.h> */
/* Contents Package Headers */
#include <acse.h>
#include <dmi.h>
#include <ems.h>
#include <lnv.h>
#include <op1v4.h>
#include <op1v2.h>
#include <op1v1.h>
#include <gmi.h>
#include <gmo.h>
#include <gcd.h>
#include <gnm.h>
#include <osa.h>
#include <dsmcmtmd.h>
#include <lnh.h>
/* #include <dmoh.h> */
/* ----------------------------------------------------------------- */
/* Exports */
/* ----------------------------------------------------------------- */
OM_EXPORT(OM_C_EXTERNAL);
OM_EXPORT(MP_C_CONTEXT);
OM_EXPORT(MP_C_ENTITY_NAME);
OM_EXPORT(MP_C_ERROR);
OM_EXPORT(MP_C_NAME);
OM_EXPORT(MP_C_SESSION);
OM_EXPORT(MP_C_TITLE);
OM_EXPORT(OM_C_ENCODING);
/* CMIS Package */
/* package classes */
OM_EXPORT(C_LNV_CMOT_SYSTEM_ID);
OM_EXPORT(C_DMI_SYSTEM_ID);
OM_EXPORT(C_GNM_NAME_TYPE);
OM_EXPORT(GNM_A_NETWORK_ID);
/* ----------------------------------------------------------------- */
/* Public Session objects (STATIC DESCRIPTOR STRUCTURES) */
/* ----------------------------------------------------------------- */
/* CMIP SPECIFIC STRUCTURES */
static OM_descriptor req_title[] = {
OM_OID_DESC(OM_CLASS, MP_C_ENTITY_NAME),
{MP_ENTITY,OM_S_PRINTABLE_STRING,OM_STRING("Test Manager")},
OM_NULL_DESCRIPTOR
};
static OM_descriptor session_opts[] = {
OM_OID_DESC(OM_CLASS, MP_C_SESSION),
{MP_REQUESTOR_TITLE,OM_S_OBJECT,{0,req_title}},
OM_NULL_DESCRIPTOR
};
static OM_descriptor context_opts[] = {
OM_OID_DESC(OM_CLASS, MP_C_CONTEXT),
{MP_MODE,OM_S_ENUMERATION,MP_T_CONFIRMED},
{MP_ASYNCHRONOUS,OM_S_BOOLEAN,OM_FALSE},
OM_NULL_DESCRIPTOR
};
static OM_descriptor pub_decode_arg[] = {
OM_OID_DESC(OM_CLASS, OM_C_ENCODING),
{OM_OBJECT_CLASS,OM_S_OBJECT_IDENTIFIER_STRING,{0,NULL}},
{OM_OBJECT_ENCODING,OM_S_ENCODING_STRING,{0,NULL}},
{OM_RULES,OM_S_OBJECT_IDENTIFIER_STRING,{0,NULL}},
OM_NULL_DESCRIPTOR
};
/* ---------------------------------------------------------- */
/* Other Global Data */
/* ---------------------------------------------------------- */
OM_workspace ws; /* global workspace pointer */
MP_feature feature_list[] = {
{OM_STRING(OMP_O_OM_OM),OM_TRUE},
{OM_STRING(OMP_O_MP_COMMON_PKG),OM_TRUE},
{OM_STRING(OMP_O_MP_CMIS_PKG),OM_TRUE},
{OM_STRING(OMP_O_LNV),OM_TRUE},
{OM_STRING(OMP_O_ACSE),OM_TRUE},
{OM_STRING(OMP_O_SMI_PART2),OM_TRUE},
{OM_STRING(OMP_O_SMI_PART5),OM_TRUE},
{OM_STRING(OMP_O_OP1_VOL4),OM_TRUE},
{OM_STRING(OMP_O_OP1_VOL2),OM_TRUE},
{{0,NULL},OM_FALSE}}; /* includes all packages to be used */
typedef OM_return_code OM_status;
int flag;
OM_private_object bound_session;
OM_private_object session;
OM_private_object context;
OM_private_object decoded_arg;
OM_sint invoke_id;
MP_status mp_ret;
OM_return_code omstat;
OM_value_position total;
char error_text[100] ; /*display error msg text */
OM_status rc;
/* ----------------------------------------------------------- */
/* function: DNDecode */
/* */
/* description: process VIEW info and return command string */
/* */
/* ----------------------------------------------------------- */
ULONG DNDecode(PVOID y, NIDSIDSTRUC *pNIDSIDStruc )
{
ULONG rcode;
OM_private_object privateMOI,privateDecodeArg,privateMOC;
ULONG walk(OM_private_object decoded_arg,char *netid,char *sysid);
TOP_DN *x;
char netid[30],sysid[30];
x=y;
flag=0; /* indicate first data item is the netid */
/* Initialize the workspace */
ws =mp_initialize(); /* frame work initialization command */
mp_ret = mp_version(ws,feature_list); /* version command */
if (mp_ret != MP_SUCCESS) {
mp_error_message(mp_ret,100,error_text);
printf("mp_version : %s\n",error_text);
return((ULONG) mp_ret);
}
/* Build the session object */
omstat = om_create(MP_C_SESSION,OM_TRUE,ws,&session);
omstat = om_put(session,OM_REPLACE_ALL,session_opts,NULL,0,0);
if (omstat != OM_SUCCESS) {
printf("omput Failure: %d\n",omstat);
return((ULONG) omstat);
}
/* Initialize the context object */
omstat = om_create(MP_C_CONTEXT,OM_TRUE,ws,&context);
if (omstat != OM_SUCCESS) {
printf("omput Failure: %d\n",omstat);
return((ULONG) omstat); }
omstat = om_put(context,OM_REPLACE_ALL,context_opts,NULL,0,0);
if (omstat != OM_SUCCESS) {
printf("omput Failure: %d\n",omstat);
return((ULONG) omstat); }
/* Bind to the infrastructure */
mp_ret = mp_bind(session,ws,&bound_session); /* bind command */
printf("BIND COMPLETE\n");
if (mp_ret != MP_SUCCESS) {
mp_error_message(mp_ret,100,error_text);
printf("mp_bind : %s\n",error_text);
return((ULONG) mp_ret);
}
/* BUILD THE DECODED MOC & MOI FROM THE PASSED VALUE */
pub_decode_arg[1].value.string.length=x->encodedMOI->MOC.length;
pub_decode_arg[1].value.string.elements=x->encodedMOI->MOC.string;
pub_decode_arg[2].value.string.length=x->encodedMOI->Encoding.length;
pub_decode_arg[2].value.string.elements=x->encodedMOI->Encoding.string;
pub_decode_arg[3].value.string.length=x->encodedMOI->Rules.length;
pub_decode_arg[3].value.string.elements=x->encodedMOI->Rules.string;
omstat = om_create(OM_C_ENCODING,OM_FALSE,ws,&privateDecodeArg);
if (omstat != OM_SUCCESS){
printf( "om_create failure %d\n",omstat);
return((ULONG) omstat); }
omstat = om_put(privateDecodeArg,OM_REPLACE_ALL,pub_decode_arg,NULL,0,0);
if (omstat != OM_SUCCESS){
printf( "om_create failure %d\n",omstat);
return((ULONG) omstat); }
omstat = om_decode(privateDecodeArg,&privateMOI);
if (omstat != OM_SUCCESS){
printf( "om_create failure %d\n",omstat);
return((ULONG) omstat);}
/* EXTRACT THE NETID, AND SYSID FROM THE ENCODED NAME */
rcode=walk(privateMOI,netid,sysid);
printf("identifiers : %s %s %d\n",netid,sysid,rcode);
if (rcode == 0) {
pNIDSIDStruc->NetID= (PSZ) malloc(strlen(netid)+1);
pNIDSIDStruc->SysID= (PSZ) malloc(strlen(sysid)+1);
strcpy(pNIDSIDStruc->NetID,netid);
strcpy(pNIDSIDStruc->SysID,sysid);
}
/* house keeping delete structures created */
(void) om_delete(privateDecodeArg);
(void) om_delete(privateMOI);
mp_unbind(bound_session);
return(rcode);
}
/**********************************************************************************/
/* */
/* function walk() */
/* */
/* DESCRIPTION: Private Object Parser */
/* */
/* */
/**********************************************************************************/
ULONG walk(OM_private_object descr,char *netid,char *sysid) {
OM_descriptor *attr_descriptor; /* used to index through output */
OM_private_object pub_arg;
int i;
char *sattr;
ULONG rct;
/* make sure we have something to look at */
if (flag==2) return(rct);
if (descr == MP_ABSENT_OBJECT) {
printf("Status: Absent Object\n");
return(4);
}
omstat = om_get(descr,OM_EXCLUDE_SUBOBJECTS,NULL,OM_FALSE,0,
OM_ALL_VALUES,&pub_arg,&total);
if (omstat != OM_SUCCESS) {
printf("OMSTAT ERROR : %X occurred \n",omstat);
return((ULONG) omstat ); }
/* Traverse All Descriptors At This Level In Tree */
for(attr_descriptor=pub_arg;
attr_descriptor->type != OM_NO_MORE_TYPES;
++attr_descriptor) {
if (flag == 2) return(rct);
switch (attr_descriptor->syntax & OM_S_SYNTAX) {
case OM_S_OBJECT:
rct=walk(attr_descriptor->value.object.object,netid,sysid); /* Object Pointer Next Lvl */
break;
case OM_S_OBJECT_IDENTIFIER_STRING :
rct=1;
break;
case OM_S_GRAPHIC_STRING:
case OM_S_OCTET_STRING:
sattr=attr_descriptor->value.string.elements;
if (flag == 0) {
for (i=0;
i < attr_descriptor->value.string.length;
i++ ) {
netid[i]=sattr[i];
}
netid[attr_descriptor->value.string.length]=0;
printf("net id: %s\n",netid);
flag=1;
rct=1;
}
else
{
for (i=0;
i < attr_descriptor->value.string.length;
i++ ) {
sysid[i]=sattr[i];
}
sysid[attr_descriptor->value.string.length]=0;
printf("sysid: %s\n",sysid);
flag=2;
rct=0;
}
break;
default:
break;
rct=1;
} /* End Case Statement */
} /* End For Loop */
om_delete(pub_arg);
return(rct);
} /* End Walk */