On 22/01/2008, Xuan Pan wrote:
> I use table iterator to implement those two tables. First I have a problem
> how to target the index in the nested linked list.


You don't need to - the iterator handles this for you.

> Take the following
> query as an example: startIp.2.1 = ...I am supposed to find the data in
> the second node of the parent list and first node in the nested list.


No. *You* don't worry about which index was requested.
The iterator helper handles this. You are supposed to provide
it with a list of which indexes are valid. This works as follows:

The iterator will call your 'get_first' routine.
You should return the two index values for the first range in the first pool,
together with a pointer to the data structure for this entry.

The iterator will then call your 'get_next' routine repeatedly.
Each time, you should return the two index values for the next range
in this pool (or the first range in the next pool), together with a
pointer to the data structure for this entry.

Keep doing this until you run out of entries.
The iterator decides which row is appropriate for this request, and
calls your handler routine. The lpIpRangeEntry entry corresponding
to this row (as supplied via the 'dataContext' parameter) is made
available to your handler, via the 'netsnmp_extract_iterator_context()' call.

See one of the existing iterator-based modules for an example.


> My thought is something like this. Because we don't know which node in the
> parent linked list we are querying. We have to check out the DHCP setting
> list one node by one node and therefore I have a loop in the
> getFirstIpRangeContext. The getNextIpRangeContext should be called
> repeatedly to query the nested linked list until the right index is found.
> If not, then move the entry in the DHCP setting list forward to the next
> node.


That's more or less what is happening - but *you* don't do it.
This is all the responsibility of the iterator helper.
Your responsibilities are purely as laid out above.



> This is just some dummy code:
>
> getFirstIpRangeContext(void ** loopContext,
> void **dataContext,
> netsnmp_variable_list * pIndex,
> netsnmp_iterator_info *pIterInfo)
> {


lpIpRangeEntry = IpDhcpHead->iprange;
snmp_set_var_value(pIndex, (u_char *)& lpDhcpHead->index, sizeof(int));
pIndex = pIndex->next_variable;
snmp_set_var_value(pIndex, (u_char *)& lpIpRangeEntry->index,
sizeof(int));

> *loopContext = lpIpRangeEntry;

*dataContext = lpIpRangeEntry;

return IpIpRangeEntry;
> }


> getNextIpRangeContext(void ** loopContext,
> void **dataContext,
> netsnmp_variable_list * pIndex,
> netsnmp_iterator_info *pIterInfo)
> {
> LPDHCPSETTING lpDhcpEntry;
> LPIPRANGEENTRY lpIpRangeEntry;
> lpIpRangeEntry = (LPIPRANGEENTRY)*loopContext;

lpDhcpEntry = IpIpRangeEntry->dhcp; // <=== new "parent" link

if ( IpIpRangeEntry->next ) {
IpIpRangeEntry = IpIpRangeEntry->next;
} else {
IpDhcpEntry = IpDhcpEntry->next;
if ( ! IpDhcpEntry ) { return NULL; }
IpIpRangeEntry = IpDhcpEntry->iprange;
}

> snmp_set_var_value(pIndex, (u_char *)& lpDhcpEntry->index, sizeof(int));
> pIndex = pIndex->next_variable;
> snmp_set_var_value(pIndex, (u_char *)& lpIpRangeEntry->index, sizeof(int));


*loopContext = lpIpRangeEntry;
*dataContext = lpIpRangeEntry;
> return pIndex;
> }




> My problem is, I don't know how I can break the loop in
> getFirstIpRangeContext when I've found the data with a target index.


No - your problem is that you're not using the iterator correctly!

> how does the iterator helper tell a target index is found.


It knows what index values were asked for.
You tell it what index values are valid.
The iterator handles the rest.

Dave

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/...net-snmp-users