diff options
author | Ermal Luçi <eri@pfsense.org> | 2010-01-26 23:59:43 +0000 |
---|---|---|
committer | Ermal Luçi <eri@pfsense.org> | 2010-01-26 23:59:43 +0000 |
commit | 9b16b83439add7c4898c8911e5a36a1ed1d3bdc2 (patch) | |
tree | 77a4f23c1936b15e962ee61ff2b6aabecd8aabd9 /etc/inc/itemid.inc | |
parent | 8f3f7729dca3cb734bc9d06a53953a07d6fca0c1 (diff) | |
download | pfsense-9b16b83439add7c4898c8911e5a36a1ed1d3bdc2.zip pfsense-9b16b83439add7c4898c8911e5a36a1ed1d3bdc2.tar.gz |
Ticket #136.
Fix associated nat rules.
Now both the filter rules and the nat ones contain a associated-rule-id tag which helps link the items together.
The API to use for this is in itemid.inc.
All the issues should be solved now.
Diffstat (limited to 'etc/inc/itemid.inc')
-rw-r--r-- | etc/inc/itemid.inc | 55 |
1 files changed, 21 insertions, 34 deletions
diff --git a/etc/inc/itemid.inc b/etc/inc/itemid.inc index f8904df..dde3762 100644 --- a/etc/inc/itemid.inc +++ b/etc/inc/itemid.inc @@ -45,10 +45,13 @@ function delete_id($id, &$array){ // Index to delete $delete_index = NULL; + if (!is_array($array)) + return false; + // Search for the item in the array foreach ($array as $key => $item){ // If this item is the one we want to delete - if(isset($item['id']) && $item['id']==$id ){ + if(isset($item['associated-rule-id']) && $item['associated-rule-id']==$id ){ $delete_index = $key; break; } @@ -66,54 +69,38 @@ function delete_id($id, &$array){ /****f* itemid/get_id * NAME - * get_id - Get an item with ['id'] = $id from $array by reference + * get_id - Get an item id with ['associated-rule-id'] = $id from $array * INPUTS - * $id - int: The ID to get + * $id - string: The ID to get * $array - array to get the item from * RESULT - * mixed - The item, NULL if not found + * mixed - The id, NULL if not found ******/ -function &get_id($id, &$array) { +function get_id($id, &$array) { // Use $foo = &get_id('id', array('id'=>'value')); - // Index to delete - $get_index = NULL; + + if (!is_array($array)) + return false; // Search for the item in the array foreach ($array as $key => $item){ // If this item is the one we want to delete - if(isset($item['id']) && $item['id']==$id ){ - $get_index = $key; - break; - } + if (isset($item['associated-rule-id']) && $item['associated-rule-id']==$id) + return $key; } - // If we found the item, unset it - if( $get_index!==NULL) - return $array[$get_index]; - else - return false; + return false; } -/****f* itemid/get_next_id +/****f* itemid/get_unique_id * NAME - * get_next_id - find the next available id from an item list - * INPUTS - * $array - array of items to get the id for + * get_unique_id - get a unique identifier * RESULT - * integer - the next available id + * string - unique id ******/ -function get_next_id($array){ - // Default value - $next_id = 1; - - // Search for IDs - foreach ($array as $item){ - // If this item has an ID, and it's higher or equal to the current "next ID", use that + 1 as the next ID - if(isset($item['id']) && $item['id']>=$next_id ){ - $next_id = $item['id'] + 1; - } - } - return $next_id; +function get_unique_id(){ + + return uniqid("nat_", true); } -?>
\ No newline at end of file +?> |