Changeset 556
- Timestamp:
- 04/02/06 03:15:57 (3 years ago)
- Location:
- trunk/src
- Files:
-
- 4 modified
-
config/policy.cpp (modified) (3 diffs)
-
config/policy.h (modified) (2 diffs)
-
gui/config/serverpage.cpp (modified) (3 diffs)
-
gui/config/serverpage.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/config/policy.cpp
r447 r556 52 52 } 53 53 54 /** Constructor. Creates a new Policy object from the string parts. */ 55 Policy::Policy(QString action, QString address, QString ports) 56 { 57 /* Set the defaults */ 58 _action = Accept; 59 _address = QHostAddress::Any; 60 _fromPort = _toPort = 0; 61 _mask = 0; 62 63 fromString(action + " " + address + ":" + ports); 64 } 65 54 66 /** Constructor. Creates a new Policy object depending on the specified 55 67 * special policy type. */ … … 59 71 _address = QHostAddress::Any; 60 72 _fromPort = _toPort = 0; 61 _mask = 0;62 }63 64 /** Constructor. Creates a new policy object based on the given rules. */65 Policy::Policy(Action action, QHostAddress addr,66 quint16 fromPort, quint16 toPort)67 {68 _action = action;69 _address = addr;70 _fromPort = fromPort;71 _toPort = toPort;72 73 _mask = 0; 73 74 } … … 134 135 Policy::toString() 135 136 { 136 QString policy; 137 138 /* Add the action to take for this policy */ 139 policy = (_action == Accept ? "accept " : "reject "); 140 141 /* Add the address (and mask, if specified) */ 142 if (_mask && !_address.isNull()) { 143 policy += _address.toString() + "/" + QString::number(_mask); 144 } else { 145 policy += (_address.isNull() ? "*" : _address.toString()); 146 } 147 148 /* Add the port or port range (if specified) */ 149 policy += ":" + (_fromPort ? QString::number(_fromPort) : "*"); 150 if (_fromPort && _toPort) { 151 policy += "-" + QString::number(_toPort); 152 } 153 return policy; 137 return action() + " " + address() + ":" + ports(); 154 138 } 155 139 140 /** Converts the given action to a string. */ 141 Policy::Action 142 Policy::toAction(QString action) 143 { 144 if (action.toLower() == "accept") { 145 return Accept; 146 } 147 return Reject; 148 } 149 150 /** Returns the action associated with this policy. */ 151 QString 152 Policy::action() 153 { 154 return (_action == Accept ? "accept" : "reject"); 155 } 156 157 /** Returns the address (and mask, if specified) for this policy. */ 158 QString 159 Policy::address() 160 { 161 if (_mask && !_address.isNull()) { 162 return _address.toString() + "/" + QString::number(_mask); 163 } 164 return (_address.isNull() ? "*" : _address.toString()); 165 } 166 167 /** Returns the port (or port range, if specified) for this policy. */ 168 QString 169 Policy::ports() 170 { 171 QString ports = (_fromPort ? QString::number(_fromPort) : "*"); 172 if (_fromPort && _toPort) { 173 ports += "-" + QString::number(_toPort); 174 } 175 return ports; 176 } 177 -
trunk/src/config/policy.h
r447 r556 50 50 /** Parses the given policy, represented as a string. */ 51 51 Policy(QString policy); 52 /** Parses the given portions of a policy string. */ 53 Policy(QString action, QString address, QString ports); 52 54 /** Creates a policy of the given special type. */ 53 55 Policy(SpecialPolicy policy); 54 /** Create a policy using the specified information. */55 Policy(Action action, QHostAddress addr,56 quint16 fromPort, quint16 toPort = 0);57 56 /** Creates a policy using the specified information. */ 58 57 Policy(Action action, QHostAddress addr, uchar mask, … … 66 65 /** Converts this policy to a format Tor understands. */ 67 66 QString toString(); 68 67 /** Converts a string action to an Action enum value. */ 68 static Action toAction(QString action); 69 69 70 /** Returns the action taken when this policy matches an address. */ 70 Action action() { return _action; } 71 /** Returns the host address for this policy. */ 72 QHostAddress address() { return _address; } 73 /** Returns the host address mask for this policy. */ 74 uchar mask() { return _mask; } 75 /** Returns the first port in a range. */ 76 quint16 fromPort() { return _fromPort; } 77 /** Returns the last port in a port range. */ 78 quint16 toPort() { return _toPort; } 71 QString action(); 72 /** Returns the host address (including mask, if set) for this policy. */ 73 QString address(); 74 /** Returns the port or port range for this policy. */ 75 QString ports(); 79 76 80 77 private: -
trunk/src/gui/config/serverpage.cpp
r555 r556 142 142 ServerPage::savePolicy(QTreeWidgetItem *item, ExitPolicy &exitPolicy) 143 143 { 144 /* Build policy string */145 QString policyString = item->text(COL_ACTION) + " ";146 policyString += item->text(COL_ADDRESS) + ":" + item->text(COL_PORT);147 148 144 /* Add policy to ServerSettings */ 149 exitPolicy.addPolicy(Policy(policyString)); 145 exitPolicy.addPolicy(Policy(item->text(COL_ACTION), 146 item->text(COL_ADDRESS), 147 item->text(COL_PORT))); 150 148 } 151 149 … … 163 161 164 162 /* Add the policy to the list */ 165 addPolicyItem(ui.cmboExitAction->currentText(), ui.lineExitAddress->text(), 166 ui.lineExitMask->text(), ui.lineExitFromPort->text(), 167 ui.lineExitToPort->text()); 163 addPolicyItem(Policy(Policy::toAction(ui.cmboExitAction->currentText()), 164 QHostAddress(ui.lineExitAddress->text()), 165 ui.lineExitMask->text().toUShort(), 166 ui.lineExitFromPort->text().toUShort(), 167 ui.lineExitToPort->text().toUShort())); 168 168 169 169 /* Clear input text boxes */ … … 178 178 ServerPage::addPolicyItem(Policy policy) 179 179 { 180 /* Convert to strings */181 QString action = (policy.action() == Policy::Accept ? "accept" : "reject");182 QHostAddress address = policy.address();183 QString addr = (address.isNull() ? "*" : address.toString());184 QString mask = (policy.mask() ? QString::number(policy.mask()) : "");185 int port = policy.fromPort();186 QString fromPort = (port ? QString::number(port) : "");187 port = policy.toPort();188 QString toPort = (port ? QString::number(port) : "");189 190 /* Add to list */191 addPolicyItem(action, addr, mask, fromPort, toPort);192 }193 194 /** Adds a new QTreeWidget item to the exit policy list */195 void196 ServerPage::addPolicyItem(QString action, QString address, QString mask,197 QString fromPort, QString toPort)198 {199 180 QTreeWidgetItem *newPolicy = new QTreeWidgetItem(); 200 201 newPolicy->setText(COL_ACTION, action); 202 newPolicy->setTextAlignment(COL_ACTION, Qt::AlignCenter); 203 204 if (!mask.isEmpty()) { 205 address += "/" + mask; 206 } 207 newPolicy->setText(COL_ADDRESS, address); 208 newPolicy->setTextAlignment(COL_ADDRESS, Qt::AlignCenter); 209 210 if (!fromPort.isEmpty()) { 211 if (!toPort.isEmpty() && fromPort != "*") { 212 fromPort += "-" + toPort; 213 } 214 } else { 215 fromPort = "*"; 216 } 217 218 newPolicy->setText(COL_PORT, fromPort); 219 newPolicy->setTextAlignment(COL_PORT, Qt::AlignCenter); 220 181 182 newPolicy->setText(COL_ACTION, policy.action()); 183 newPolicy->setText(COL_ADDRESS, policy.address()); 184 newPolicy->setText(COL_PORT, policy.ports()); 185 221 186 ui.lstExitPolicies->addTopLevelItem(newPolicy); 222 187 } -
trunk/src/gui/config/serverpage.h
r555 r556 71 71 int selectedIndex(); 72 72 /** Adds a new exit policy to the exit policy list */ 73 void addPolicyItem(QString action, QString address, QString mask,74 QString fromPort, QString toPort);75 73 void addPolicyItem(Policy policy); 76 74 /** Saves the policy specified in item to the exitPolicy */
