RMON_ENTRY_T *ROWAPI_get_clone (TABLE_DEFINTION_T * table_ptr, u_long ctrl_index, size_t body_size) { register RMON_ENTRY_T *eptr; if (ctrl_index < 1 || ctrl_index > 0xFFFFu) { ag_trace ("%s: index %ld out of range (1..65535)", table_ptr->name, (long) ctrl_index); return NULL; } /* * get it */ eptr = ROWAPI_find (table_ptr, ctrl_index); if (!eptr) { /* try to create */ if (0 != ROWAPI_new (table_ptr, ctrl_index)) { return NULL; } /* * get it */ eptr = ROWAPI_find (table_ptr, ctrl_index); if (!eptr) /* it is unbelievable, but ... :( */ return NULL; } eptr->new_status = eptr->status; eptr->tmp = AGMALLOC (body_size); if (!eptr->tmp) { if (eptr->only_just_created) rowapi_delete (eptr); return NULL; } memcpy (eptr->tmp, eptr->body, body_size); if (table_ptr->ClbkClone) table_ptr->ClbkClone (eptr); if (eptr->new_owner) AGFREE (eptr->new_owner); return eptr->tmp; }
static void rowapi_too_long_creation_callback(unsigned int clientreg, void *clientarg) { RMON_ENTRY_T *eptr; TABLE_DEFINTION_T *table_ptr; eptr = (RMON_ENTRY_T *) clientarg; table_ptr = (TABLE_DEFINTION_T *) eptr->table_ptr; if (RMON1_ENTRY_VALID != eptr->status) { ag_trace("row #%d in %s was under creation more then %ld sec.", eptr->ctrl_index, table_ptr->name, (long) MAX_CREATION_TIME); rowapi_delete(eptr); } else { snmp_alarm_unregister(eptr->timer_id); } }
void ROWAPI_delete_clone(TABLE_DEFINTION_T * table_ptr, u_long ctrl_index) { register RMON_ENTRY_T *eptr; eptr = ROWAPI_find(table_ptr, ctrl_index); if (eptr) { if (eptr->new_owner) AGFREE(eptr->new_owner); if (eptr->tmp) { if (table_ptr->ClbkDelete) table_ptr->ClbkDelete((RMON_ENTRY_T *) eptr->tmp); AGFREE(eptr->tmp); } if (eptr->only_just_created) { rowapi_delete(eptr); } } }
int ROWAPI_commit(TABLE_DEFINTION_T * table_ptr, u_long ctrl_index) { register RMON_ENTRY_T *eptr; eptr = ROWAPI_find(table_ptr, ctrl_index); if (!eptr) { ag_trace("Smth wrong ?"); return SNMP_ERR_GENERR; } eptr->only_just_created = 0; switch (eptr->new_status) { /* this status we want to set */ case RMON1_ENTRY_CREATE_REQUEST: /* copy tmp => eprt */ if (eptr->new_owner) { if (eptr->owner) AGFREE(eptr->owner); eptr->owner = AGSTRDUP(eptr->new_owner); } if (table_ptr->ClbkCopy && eptr->tmp) table_ptr->ClbkCopy(eptr); break; case RMON1_ENTRY_INVALID: ROWAPI_delete_clone(table_ptr, ctrl_index); rowapi_delete(eptr); #if 0 /* for debug */ dbg_f_AG_MEM_REPORT(); #endif break; case RMON1_ENTRY_VALID: /* copy tmp => eprt and activate */ /* * Our MIB understanding extension: we permit to set * VALID when entry doesn't exit, in this case PDU has to have * the nessessary & valid set of non-default values */ if (eptr->new_owner) { if (eptr->owner) AGFREE(eptr->owner); eptr->owner = AGSTRDUP(eptr->new_owner); } if (table_ptr->ClbkCopy && eptr->tmp) table_ptr->ClbkCopy(eptr); if (RMON1_ENTRY_VALID != eptr->status) { rowapi_activate(table_ptr, eptr); } break; case RMON1_ENTRY_UNDER_CREATION: /* deactivate (if need) and copy tmp => eprt */ /* * Our MIB understanding extension: we permit to travel from * VALID to 'UNDER_CREATION' state */ rowapi_deactivate(table_ptr, eptr); if (eptr->new_owner) { if (eptr->owner) AGFREE(eptr->owner); eptr->owner = AGSTRDUP(eptr->new_owner); } if (table_ptr->ClbkCopy && eptr->tmp) table_ptr->ClbkCopy(eptr); break; } ROWAPI_delete_clone(table_ptr, ctrl_index); return SNMP_ERR_NOERROR; }