midrange.com code scratchpad
Name:
Monty James
Scriptlanguage:
C++
Tabwidth:
4
Date:
03/25/2019 09:45:17 pm
IP:
Logged
Description:
Add EIM Identifier and associations
Code:
  1. #include <eim.h>                   
  2. #include <stdio.h>                 
  3. #include <errno.h>                 
  4.                                    
  5. int main (int argc, char * argv[]) 
  6. {                                  
  7.     int   rc;                      
  8.     char  eimerr[200];             
  9.     EimRC      * err;              
  10.     EimHandle  handle;             
  11.     EimIdentifierInfo x;           
  12.     EimConnectInfo con;            
  13.     char  unique[30];              
  14.     char  rtnstr[20];              
  15.     char       * message;          
  16.     unsigned int sizeOfUnique = 30;
  17.                                    
  18.     /* error structure */          
  19.     memset (eimerr,0x00,200);      
  20.     err = (EimRC *)eimerr; 
  21.     err->memoryProvidedByCaller = 200;                               
  22.                                                                      
  23.     /* Create new eim handle. */                                     
  24.     if (0 != (rc = eimCreateHandle(&handle,                          
  25.                                     NULL,                            
  26.                                     err)))                           
  27.                                                                      
  28.     {                                                                
  29.        message = eimErr2String(err);                                 
  30.        sprintf(argv[9], "EIM API Handle Error Message: %s", message);
  31.        free(message);                                                
  32.                                                                      
  33.        /*replace the NULL terminator with a space */                 
  34.        argv[9] [strlen(argv[9])] = ' ';                              
  35.        return -1;                                                    
  36.     }                                                                
  37.                                                                      
  38.     /* connection information */                                     
  39.     con.type = EIM_SIMPLE;                                           
  40.     con.creds.simpleCreds.protect = EIM_PROTECT_NO;                  
  41.     con.creds.simpleCreds.bindDn = argv[5]; 
  42.     con.creds.simpleCreds.bindPw = argv[6];                            
  43.     con.ssl = NULL;                                                    
  44.     /* Connect to system configuration */                              
  45.     if (0!= (rc = eimConnect (&handle,                                 
  46.                                con,                                    
  47.                                err)))                                  
  48.     {                                                                  
  49.        message = eimErr2String(err);                                   
  50.        sprintf(argv[9], "EIM API Connect Error Message: %s", message); 
  51.        free(message);                                                  
  52.                                                                        
  53.        /*replace the NULL terminator with a space */                   
  54.        argv[9] [strlen(argv[9])] = ' ';                                
  55.        return -1;                                                      
  56.     }                                                                  
  57.                                                                        
  58.     /* Erase identifier */                                             
  59.     x.idtype = EIM_UNIQUE_NAME;                                        
  60.     x.id.uniqueName = argv[1];                                         
  61.     /* delete identifier */                                            
  62.     if (0 != (rc = eimRemoveIdentifier (&handle,
  63.                                         &x,                            
  64.                                         err)))                         
  65.     {                                                                  
  66.        message = eimErr2String(err);                                   
  67.        sprintf(argv[9], "EIM API Remove Error Message: %s", message);  
  68.        free(message);                                                  
  69.                                                                        
  70.    /*  /*replace the NULL terminator with a space */                   
  71.    /*  argv[9] [strlen(argv[9])] = ' '; */                             
  72.    /*  return -1;                       */                             
  73.     }                                                                  
  74.                                                                        
  75.     x.idtype = EIM_UNIQUE_NAME;                                        
  76.     x.id.uniqueName = argv[1];                                         
  77.     if (0 != (rc = eimAddIdentifier (&handle, argv[1], EIM_FAIL, &sizeOfUnique,
  78.         unique, argv[2], err)))                                        
  79.                                                                        
  80.     {                                                                  
  81.        message = eimErr2String(err);                                   
  82.        sprintf(argv[9], "EIM API Add ID Error Message: %s", message);  
  83.        free(message); 
  84.                                                                      
  85.        /*replace the NULL terminator with a space */                 
  86.        argv[9] [strlen(argv[9])] = ' ';                              
  87.        return -1;                                                    
  88.     }                                                                
  89.                                                                      
  90.     x.idtype = EIM_UNIQUE_NAME;                                      
  91.     x.id.uniqueName = argv[1];                                       
  92.     /* Add source association */                                     
  93.     if (0 != (rc = eimAddAssociation (&handle,                       
  94.                                      EIM_SOURCE,                     
  95.                                      &x,                             
  96.                                      argv[7],                        
  97.                                      argv[3],                        
  98.                                      err)))                          
  99.     {                                                                
  100.        message = eimErr2String(err);                                 
  101.        sprintf(argv[9], "EIM API Source Error Message: %s", message);
  102.        free(message);                                                
  103.                                                                      
  104.     /*replace the NULL terminator with a space */ 
  105.     argv[9] [strlen(argv[9])] = ' ';                                 
  106.     return -1;                                                       
  107.     }                                                                
  108.                                                                      
  109.     /* Add target association */                                     
  110.     if (0 != (rc = eimAddAssociation (&handle,                       
  111.                                      EIM_TARGET,                     
  112.                                      &x,                             
  113.                                      argv[8],                        
  114.                                      argv[4],                        
  115.                                      err)))                          
  116.     {                                                                
  117.        message = eimErr2String(err);                                 
  118.        sprintf(argv[9], "EIM API Target Error Message: %s", message);
  119.        free(message);                                                
  120.                                                                      
  121.        /*replace the NULL terminator with a space */                 
  122.        argv[9] [strlen(argv[9])] = ' ';                              
  123.        return -1;                                                    
  124.     }                                                                
  125.  
  126.     /* destroy handle */                             
  127.     rc = eimDestroyHandle (&handle, err);            
  128.     message = eimErr2String(err);                    
  129.     sprintf(argv[9], "EIM API Message: %s", message);
  130.     argv[9] [strlen(argv[9])] = ' ';                 
  131.     free(message);                                   
  132.     return 0;                                        
  133.  }                                                   
© 2004-2019 by midrange.com generated in 0.153s valid xhtml & css