(file) Return to snmpDeliverTrap_emanate.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Handler / snmpIndicationHandler

Diff for /pegasus/src/Pegasus/Handler/snmpIndicationHandler/snmpDeliverTrap_emanate.cpp between version 1.3 and 1.6

version 1.3, 2002/03/14 00:07:48 version 1.6, 2002/04/17 22:46:33
Line 34 
Line 34 
 #include <ctype.h> #include <ctype.h>
 #include <sys/stat.h> #include <sys/stat.h>
 #include "snmpDeliverTrap_emanate.h" #include "snmpDeliverTrap_emanate.h"
   #include "prnt_lib.h"
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
Line 102 
Line 103 
     Array<String>& vbTypes,     Array<String>& vbTypes,
     Array<String>& vbValues)     Array<String>& vbValues)
 { {
     initialize();      OctetString*    newValue;
   
     void*   newValue;  
     char*   entV2Trap;  
     int     vb_link_flag = 0;  
  
     VarBind *vb = NULL;     VarBind *vb = NULL;
     VarBind *vb2 = NULL;     VarBind *vb2 = NULL;
       VarBind *vb3 = NULL;
  
     OID     *object = NULL;     OID     *object = NULL;
  
       // Initializing with Master agent
       initialize();
   
       // TRAP OID: getting trapOid
       char* _trapOid = trapOid.allocateCString();
       _trapOid[strlen(_trapOid)-1] = '\0';
       OID *sendtrapOid = MakeOIDFromDot(_trapOid);
   
       // Destination : converting destination into Transport
       char* trap_dest = destination.allocateCString();
       TransportInfo   global_ti;
       global_ti.type = SR_IP_TRANSPORT;
       global_ti.t_ipAddr = inet_addr(trap_dest);
       global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort());
       delete [] trap_dest;
   
       // Community Name
       char* _community = community.allocateCString();
       OctetString* community_name = MakeOctetStringFromText(_community);
       delete [] _community;
   
     // getting IP address of the host     // getting IP address of the host
     char* hostname = System::getHostName().allocateCString();     char* hostname = System::getHostName().allocateCString();
     char **p;     char **p;
Line 122 
Line 141 
     p = hp->h_addr_list;     p = hp->h_addr_list;
     (void)memcpy(&in.s_addr, *p, sizeof(in.s_addr));     (void)memcpy(&in.s_addr, *p, sizeof(in.s_addr));
     char* IP_string = inet_ntoa(in);     char* IP_string = inet_ntoa(in);
       delete [] hostname;
     // converting destination into Transport  
     TransportInfo   global_ti;  
     global_ti.type = SR_IP_TRANSPORT;  
     // address to which to send trap  
     global_ti.t_ipAddr = inet_addr(destination.allocateCString());  
     // port to which to send trap  
     global_ti.t_ipPort = htons((unsigned short)GetSNMPTrapPort());  
  
     // formatting agent(host) address into OctetString format     // formatting agent(host) address into OctetString format
     OctetString* agent_addr;     OctetString* agent_addr;
Line 153 
Line 165 
     agent_addr->octet_ptr[2] = (unsigned char)s3;     agent_addr->octet_ptr[2] = (unsigned char)s3;
     agent_addr->octet_ptr[3] = (unsigned char)s4;     agent_addr->octet_ptr[3] = (unsigned char)s4;
  
     // ATTN : Write code to get enterprise, genTrap and specTrap      // ATTN-NU-20020312 : Write code to get enterprise, genTrap and
     // from trapOid.      // specTrap from trapOid.
   
       //NU_SNMP
  
     // << 03-12-2002 : NU (HP)      SR_INT32 genTrap = 0;
       SR_INT32 specTrap = 0;
  
     String enterprise;      OID* enterpriseOid ;
   
       Array<String> standard_traps;
   
       standard_traps.append(String("1.3.6.1.6.3.1.1.5.1"));
       standard_traps.append(String("1.3.6.1.6.3.1.1.5.2"));
       standard_traps.append(String("1.3.6.1.6.3.1.1.5.3"));
       standard_traps.append(String("1.3.6.1.6.3.1.1.5.4"));
       standard_traps.append(String("1.3.6.1.6.3.1.1.5.5"));
       standard_traps.append(String("1.3.6.1.6.3.1.1.5.6"));
   
       Array<String> oids;
       String tmpoid = trapOid;
   
       while(tmpoid.find(".") != PEG_NOT_FOUND)
       {
           oids.append(tmpoid.subString(0, tmpoid.find(".")));
           tmpoid = tmpoid.subString(tmpoid.find(".") + 1);
       }
       oids.append(tmpoid);
   
       String ent;
       if (oids[oids.size()-2] == "0")
       {
           ent = oids[0];
           for (Uint8 i = 1; i < oids.size()-2; i++)
               ent = ent + "." + oids[i];
       }
   
       if (Contains(standard_traps, trapOid))
       {
           ent = oids[0];
           for (Uint8 i = 1; i < oids.size()-1; i++)
               ent = ent + "." + oids[i];
   
           char* gtrap = ent.allocateCString();
           genTrap = atoi(gtrap) - 1;
           enterpriseOid = sendtrapOid;
           delete [] gtrap;
       }
       else
       {
           genTrap = 6;
  
     OID* enterpriseOid = MakeOIDFromDot(enterprise.allocateCString());          ent = oids[0];
           for (Uint8 i = 1; i < oids.size()-1; i++)
               ent = ent + "." + oids[i];
           char* strap = oids[oids.size()-1].allocateCString();
           specTrap = atoi(strap);
           delete [] strap;
   
           if (oids[oids.size()-2] == "0")
           {
               ent = oids[0];
               for (Uint8 i = 1; i < oids.size()-2; i++)
                   ent = ent + "." + oids[i];
   
               char* _ent = ent.allocateCString();
               enterpriseOid = MakeOIDFromDot(_ent);
               delete [] _ent;
           }
           else
           {
               ent = oids[0];
               for (Uint8 i = 1; i < oids.size()-1; i++)
                   ent = ent + "." + oids[i];
  
     // getting trap data for do_trap()              char* _ent = ent.allocateCString();
     entV2Trap = trapOid.allocateCString();              enterpriseOid = MakeOIDFromDot(_ent);
               delete [] _ent;
           }
       }
  
     // getting trapOid      char* _vbOid;
     OID *sendtrapOid = MakeOIDFromDot(trapOid.allocateCString());      char* _vbValue;
  
     for(Uint8 i = 0; i < vbOids.size(); i++)      for(Uint32 i = 0; i < vbOids.size(); i++)
     {     {
         if ((object = MakeOIDFromDot(vbOids[i].allocateCString())) == NULL)          _vbOid = vbOids[i].allocateCString();
           _vbValue = vbValues[i].allocateCString();
   
           if ((object = MakeOIDFromDot(_vbOid)) == NULL)
         {         {
             cout << "Invalid OID received: " << vbOids[i] << endl;             cout << "Invalid OID received: " << vbOids[i] << endl;
             return;             return;
         }         }
  
         if (strcmp(vbTypes[i].allocateCString(),"OctetString") == 0)          if (vbTypes[i] == String("OctetString"))
         {         {
             newValue = MakeOctetStringFromText(vbValues[i].allocateCString());              newValue = CloneOctetString(MakeOctetStringFromText(_vbValue));
             if ((vb = MakeVarBindWithValue(object,              if (newValue == NULL)
               {
                   cout << "Invalid Value provided : " << vbValues[i] << endl;
                   return;
               }
               if ((vb2 = MakeVarBindWithValue(object,
                 (OID *) NULL,                 (OID *) NULL,
                 OCTET_PRIM_TYPE,                 OCTET_PRIM_TYPE,
                 newValue)) == NULL)                 newValue)) == NULL)
Line 190 
Line 279 
         }         }
         else         else
         {         {
             newValue = MakeOctetString(              int vbvalue = atoi(_vbValue);
                 (unsigned char *) vbValues[i].allocateCString(),              void* value = &vbvalue;
                 strlen(vbValues[i].allocateCString()));  
  
             if ((vb = MakeVarBindWithValue(object,              if (newValue == NULL)
               {
                   cout << "Invalid Value provided : " << vbValues[i] << endl;
                   return;
               }
               if ((vb2 = MakeVarBindWithValue(object,
                 (OID *) NULL,                 (OID *) NULL,
                 INTEGER_TYPE,                 INTEGER_TYPE,
                 newValue)) == NULL)                  value)) == NULL)
             {             {
                 cout << "Invalid Integer Value: " << vbValues[i] << endl;                 cout << "Invalid Integer Value: " << vbValues[i] << endl;
                 return;                 return;
             }             }
         }         }
           if (i == 0)
         if (!vb_link_flag)  
         {         {
             vb_link_flag = 1;              vb = vb2;
             vb2 = vb;              vb3 = vb2;
             FreeOID(object);  
         }         }
         else         else
         {         {
             vb2->next_var = vb;              vb3->next_var = vb2;
             vb2 = vb;              vb3 = vb3->next_var;
             FreeOID(object);  
         }         }
   
           FreeOID(object);
     }     }
  
     vb_link_flag = 0;      delete [] _vbValue;
     vb2->next_var = NULL;      delete [] _vbOid;
     vb->next_var = NULL;  
       vb3->next_var = NULL;
  
     // Now sending the trap     // Now sending the trap
     if (trapType == String("SNMPGeneric"))      if (trapType == String("SNMPv1"))
     {  
         do_trap(6, 4, vb2, enterpriseOid, entV2Trap);  
         FreeVarBindList(vb);  
         FreeVarBindList(vb2);  
     }  
     else if (trapType == String("SNMPv1"))  
     {     {
         SendNotificationToDestSMIv1Params(         SendNotificationToDestSMIv1Params(
             1,                                  // notifyType              1,                                  // notifyType - TRAP
             6,                                  // genTrap              genTrap,                            // genTrap
             1,                                  // specTrap              specTrap,                           // specTrap
             enterpriseOid,                      // enterprise             enterpriseOid,                      // enterprise
             agent_addr,                         // agent_addr             agent_addr,                         // agent_addr
             vb2,                                // vb              vb,                                 // vb
             NULL,                               // contextName             NULL,                               // contextName
             1,                                  // retryCount             1,                                  // retryCount
             1,                                  // timeout             1,                                  // timeout
             MakeOctetStringFromText(community.allocateCString()),       // securityName,              community_name,                     // securityName,
             SR_SECURITY_LEVEL_NOAUTH,           // securityLevel             SR_SECURITY_LEVEL_NOAUTH,           // securityLevel
             SR_SECURITY_MODEL_V1,               // securityModel             SR_SECURITY_MODEL_V1,               // securityModel
             &global_ti,                         // Transport Info             &global_ti,                         // Transport Info
             0);                                 // cfg_chk             0);                                 // cfg_chk
   
         FreeVarBindList(vb);  
         FreeVarBindList(vb2);  
     }     }
     else if (trapType == String("SNMPv2"))     else if (trapType == String("SNMPv2"))
     {     {
         SendNotificationToDestSMIv2Params(         SendNotificationToDestSMIv2Params(
             1,                                  // notifyType              1,                                  // notifyType - NOTIFICATION
             sendtrapOid,                        // snmpTrapOID             sendtrapOid,                        // snmpTrapOID
             agent_addr,                         // agent_addr             agent_addr,                         // agent_addr
             vb2,                                // vb              vb,                                 // vb
             NULL,                               // contextName             NULL,                               // contextName
             1,                                  // retryCount             1,                                  // retryCount
             100,                                // timeout             100,                                // timeout
             MakeOctetStringFromText(community.allocateCString()),       // securityName or community              community_name,                     // securityName or community
             SR_SECURITY_LEVEL_NOAUTH,           // securityLevel             SR_SECURITY_LEVEL_NOAUTH,           // securityLevel
             SR_SECURITY_MODEL_V1,               // securityModel             SR_SECURITY_MODEL_V1,               // securityModel
             &global_ti,                         // TransportInfo             &global_ti,                         // TransportInfo
Line 271 
Line 355 
     else     else
     {     {
         cout << "Trap type not supported : " << trapType << endl;         cout << "Trap type not supported : " << trapType << endl;
           delete [] _trapOid;
         exit(2);         exit(2);
     }     }
   
       FreeVarBindList(vb);
       FreeVarBindList(vb2);
       FreeVarBindList(vb3);
   
       delete [] _trapOid;
 } }
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END


Legend:
Removed from v.1.3  
changed lines
  Added in v.1.6

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2