midrange.com code scratchpad
Name:
Monty James
Scriptlanguage:
C++
Tabwidth:
4
Date:
03/25/2019 10:04:00 pm
IP:
Logged
Description:
Get EIM Unique Name
Code:
  1. #include <eim.h>                             
  2. #include <stddef.h>                          
  3. #include <stdio.h>                           
  4. #include <stdlib.h>                          
  5. #include <xxdtaa.h>                          
  6. #include <QSYSINC/MIH/CPYBLA>                
  7.                                              
  8. #define START 1                              
  9. #define LENGTH 60                            
  10.                                              
  11. void printListData(void * entry, int offset);
  12.                                              
  13. int main(int argc, char *argv[])             
  14. {                                            
  15.     int           rc;                        
  16.     int           i;                         
  17.     char          eimerr[200];               
  18.     EimRC       * err;                       
  19.     EimHandle     handle;                    
  20.     EimIdentifierInfo x;
  21.     EimConnectInfo con;                                         
  22.     char          unique[30];                                   
  23.     char          listData[1000];                               
  24.     char          rtnstr[20];                                   
  25.     char        * message;                                      
  26.     char          newdata[60];                                  
  27.     char          result[30];                                   
  28.     EimList     * list = (EimList * ) listData;                 
  29.                                                                 
  30.     /* Set up error structure.                 */               
  31.     memset(eimerr,0x00,200);                                    
  32.     err = (EimRC *)eimerr;                                      
  33.     err->memoryProvidedByCaller = 200;                          
  34.                                                                 
  35.     /* Create a new eim handle. Use the eim configuration URL */
  36.     if (0 != (rc = eimCreateHandle(&handle,                     
  37.                                    NULL,                        
  38.                                    err)))                       
  39.     {                                                           
  40.         message = eimErr2String(err);                           
  41.         sprintf(argv[5], "EIM API Error Message: %s",message);
  42.         free(message);                                        
  43.                                                               
  44.         /* Replace the NULL terminator with a space */        
  45.         argv[5][strlen(argv[5])] = ' ';                       
  46.         return -1;                                            
  47.     }                                                         
  48.                                                               
  49.     /* Connection informatiom */                              
  50.     con.type = EIM_SIMPLE;                                    
  51.     con.creds.simpleCreds.protect = EIM_PROTECT_NO;           
  52.     con.creds.simpleCreds.bindDn = argv[2];                   
  53.     con.creds.simpleCreds.bindPw = argv[3];                   
  54.     con.ssl = NULL;                                           
  55.     /* Connect to the system configuration */                 
  56.     if (0!= (rc = eimConnect(&handle,                         
  57.                              con,                             
  58.                              err)))                           
  59.     {                                                         
  60.         message = eimErr2String(err);                         
  61.         sprintf(argv[5], "EIM API Error Message: %s",message);
  62.         free(message);
  63.                                                                  
  64.         /* Replace the NULL terminator with a space */           
  65.         argv[5][strlen(argv[5])] = ' ';                          
  66.         return -1;                                               
  67.     }                                                            
  68.                                                                  
  69.     /* Get associated identifiers               */               
  70.     if (0 != (rc = eimGetAssociatedIdentifiers(&handle,          
  71.                                                EIM_TARGET,       
  72.                                                argv[4],          
  73.                                                argv[1],          
  74.                                                1000,             
  75.                                                list,             
  76.                                                err)))            
  77.     {                                                            
  78.         message = eimErr2String(err);                            
  79.         sprintf(argv[5], "Get Associated Identifiers error:  %s",
  80.                 message);                                        
  81.         free(message);                                           
  82.        eimDestroyHandle(&handle, err);                           
  83.        return -1; 
  84.     }                                                          
  85.                                                                
  86.     /* Print the results                        */             
  87.     EimIdentifier * entry;                                     
  88.                                                                
  89.     entry = (EimIdentifier *)((char *)list + list->firstEntry);
  90.                                                                
  91.     if (list->entriesReturned < 1)                             
  92.        return 0;                                               
  93.                                                                
  94.     /* Print out results */                                    
  95.     printListData(entry, offsetof(EimIdentifier, uniquename)); 
  96.                                                                
  97.     /* Destroy the handle                       */             
  98.     rc = eimDestroyHandle(&handle, err);                       
  99.                                                                
  100.     return 0;                                                  
  101. }                                                              
  102.                                                                
  103. void printListData(void * entry, int offset)                   
  104. {
  105.     EimListData * listData;                               
  106.     char * data;                                          
  107.     int dataLength;                                       
  108.     unsigned int  sizeofUnique = 30;                      
  109.     _DTAA_NAME_T dtaname;                                 
  110.                                                           
  111.     memset( &dtaname, ' 'sizeof(dtaname));              
  112.     cpybla(dtaname.dtaa_name, "EIMUNIQ", 7);              
  113.     cpybla(dtaname.dtaa_lib, "QTEMP", 5);                 
  114.                                                           
  115.        listData = (EimListData *)((char *)entry + offset);
  116.        data = (char *)entry + listData->disp;             
  117.        dataLength = listData->length;                     
  118.                                                           
  119.        if (dataLength > 0)                                
  120.           QXXCHGDA(dtaname, START, dataLength, data);     
  121. }                                                         
© 2004-2019 by midrange.com generated in 0.116s valid xhtml & css