Beispiel #1
0
//===============[Oid::operator += const Oid) ]========================
// append operator, appends an Oid
//
// allocate some space for a max oid string
// extract current string into space
// concat new string
// free up existing oid
// make a new oid from string
// delete allocated space
Oid& Oid::operator+=(const Oid &o)
{
  SmiLPUINT32 new_oid;

  if (o.smival.value.oid.len == 0)
    return *this;

  new_oid = (SmiLPUINT32) new unsigned long[smival.value.oid.len + o.smival.value.oid.len];
  if (new_oid == 0)
  {
    delete_oid_ptr();
    return *this;
  }

  if (smival.value.oid.ptr)
  {
    MEMCPY((SmiLPBYTE) new_oid,
           (SmiLPBYTE) smival.value.oid.ptr,
           (size_t) (smival.value.oid.len*sizeof(SmiUINT32)));

    delete [] smival.value.oid.ptr;
  }

  // out with the old, in with the new...
  smival.value.oid.ptr = new_oid;

  MEMCPY((SmiLPBYTE) &new_oid[smival.value.oid.len],
         (SmiLPBYTE) o.smival.value.oid.ptr,
         (size_t) (o.smival.value.oid.len*sizeof(SmiUINT32)));

  smival.value.oid.len += o.smival.value.oid.len;

  m_changed = true;
  return *this;
}
Beispiel #2
0
//==============[Oid:: operator += const char *a ]=========================
// append operator, appends a string
//
// allocate some space for a max oid string
// extract current string into space
// concat new string
// free up existing oid
// make a new oid from string
// delete allocated space
Oid& Oid::operator+=(const char *a)
{
  unsigned int n;

  if (!a) return *this;

  if (*a == '.') ++a;

  n = (smival.value.oid.len * SNMPCHARSIZE) + (smival.value.oid.len)
       + 1 + SAFE_UINT_CAST(strlen(a));
  char *ptr = new char[n];
  if (ptr)
  {
    /// @todo optimze this function (avoid conversion to string)
    OidToStr(&smival.value.oid, n, ptr);
    if (ptr[0])
      STRCAT(ptr,".");
    STRCAT(ptr,a);

    delete_oid_ptr();

    StrToOid(ptr, &smival.value.oid);
    delete [] ptr;
  }
  return *this;
}
Beispiel #3
0
//=============[Oid::operator = const char * dotted_string ]==============
// assignment to a string operator overloaded
//
// free the existing oid
// create the new oid from the string
// return this object
Oid& Oid::operator=(const char *dotted_oid_string)
{
  delete_oid_ptr();

  // assign the new value
  StrToOid(dotted_oid_string, &smival.value.oid);
  return *this;
}
Beispiel #4
0
//===============[Oid::trim(unsigned int) ]============================
// trim off the n leftmost values of an oid
// Note!, does not adjust actual space for
// speed
void Oid::trim(const unsigned long n)
{
  // verify that n is legal
  if ((n <= smival.value.oid.len) && (n > 0))
  {
    smival.value.oid.len -= n;
    if (smival.value.oid.len == 0)
      delete_oid_ptr();
  }
}
Beispiel #5
0
//===============[Oid::set_data ]==---=====================================
// copy data from raw form...
void Oid::set_data(const unsigned long *raw_oid,
		   const unsigned int oid_len)
{
  if (smival.value.oid.len < oid_len)
  {
    delete_oid_ptr();

    smival.value.oid.ptr = (SmiLPUINT32) new unsigned long[oid_len];
    if (!smival.value.oid.ptr) return;
  }
  MEMCPY((SmiLPBYTE) smival.value.oid.ptr,
         (SmiLPBYTE) raw_oid,
         (size_t) (oid_len*sizeof(SmiUINT32)));
  smival.value.oid.len = oid_len;
}
Beispiel #6
0
//=============[Oid:: operator = const Oid &oid ]==========================
// assignment to another oid object overloaded
//
// free the existing oid
// create a new one from the object passed in
Oid& Oid::operator=(const Oid &oid)
{
  if (this == &oid) return *this;  // protect against assignment from self

  delete_oid_ptr();

  // check for zero len on source
  if (oid.smival.value.oid.len == 0)
    return *this;

  // allocate some memory for the oid
  smival.value.oid.ptr = (SmiLPUINT32) new unsigned long[oid.smival.value.oid.len];
  if (smival.value.oid.ptr)
    OidCopy((SmiLPOID)&(oid.smival.value.oid), (SmiLPOID)&smival.value.oid);
  return *this;
}
Beispiel #7
0
// Set the data from raw form.
void Oid::set_data(const char *str, const unsigned int str_len)
{
  if (smival.value.oid.len < str_len)
  {
    delete_oid_ptr();

    smival.value.oid.ptr = (SmiLPUINT32) new unsigned long[str_len];
    if (!smival.value.oid.ptr) return;
  }

  if ((!str) || (str_len == 0))
    return;

  for (unsigned int i=0; i<str_len; i++)
    smival.value.oid.ptr[i] = str[i];

  smival.value.oid.len = str_len;
  m_changed = true;
}
Beispiel #8
0
//=============[Oid::~Oid]==============================================
Oid::~Oid()
{
  delete_oid_ptr();
  if (iv_str)      delete [] iv_str;        // free up the output string
  if (iv_part_str) delete [] iv_part_str;   // free up the output string
}