Can any body tell me is significance of NF_STOP in netfilter hook returns? - netfilter

Can any body tell me is significance of NF_STOP in netfilter hook returns i.e. when can a hook function return NF_STOP?

NF_STOP is similar to NF_STOLEN , only difference is function callback is called on return in case of NF_STOP.

Related

Does OCMockito reset invocation count after a verify() call?

Here is the pseudocode of my unit test:
int invocationCount
given(mock).willDo {
invocationCount++
return value
}
doSomeProcessing()
verify(mock)
doSomeMoreProcessing()
verifyCount(mock, 2)
At this point, invocationCount == 2, as expected. However, verifyCount fails, saying it was only called once. In addition, if I exclude the first verify call, the test passes as expected. It might be relevant to note that each verify call is capturing a new argument for assertion later.
My question is this: when the first verify() is called, is the mock's invocation count reset? If this is not the case, what could be happening?
Yes, verification only counts the matches since the last verification.
Further discussion can be found here: https://github.com/jonreid/OCMockito/issues/116

How the return type of intercept() is used by struts?

I am not able to understand the concept behind the return type of intercept().Is it any time related to the return type of actionInvocationInstance.invoke().Need guidance.Thanks in advance.
It's a String, and should be the name of a result.
It may be the result from invoke, or an interceptor's result that "intercepts" the action invocation, e.g., the workflow interceptor returns "input" on a validation error.
It isn't related, but the ActionInvocation::invoke() can return a result code which is suitable to return by the interceptor's intercept method. It's up to you to decide which result code to return by the interceptor, but the result code type is a String defined as a return type by the method Interceptor::intercept(). Note, that a result code corresponds to the result name in the action config, and a result with such name should be available to the configuration at runtime.

Does Backbone have a finally-Callback?

I am currently creating a Backbone.js and jquery Mobile web application and I have some calls to Backbone.model.fetch().
I have the proper success and error-callbacks, but there is some code that I want to execute no matter if the fetch was successfull or not.
Currently, I'm simply copying the common code. But I asked myself if there is any callback that is executed no matter what happens.
Like the try{} catch{} finally{} from C#.
Is there anything like that?
fetch() returns a 'Deferred Object'
see: http://api.jquery.com/category/deferred-object/
it's not really like try{} catch{}, but you can use .always() method to bind a callback which will be executed after the request is done (no matter if it was successful or not)
like so.
var doSomething = function () {
//will run after fetch() request is finished
};
collection.fetch().always(doSomething);
similarly, instead of passing success or error callbacks to fetch()'s options, in general it is encouraged to chain .done(), .fail(), or .then() methods to deferred methods(fetch, save...etc)

OCMockito verify with any arguments

I'm trying to verify that a function on a mock object is NOT called at all with ANY parameters.
The function on the object I'm mocking is...
- (void)registerUserWithUsername:(NSString*)username password:(NSString*)password;
I'd like to verify that the function is NOT called if the username is blank.
i.e.
[mockService registerUserWithUsername:#"" password:#"Password"];
[verify(mockService, never()) registerWithUsername:....... password:.......];
I'm just not sure what to put in the ...... bits?
To specify that it's never called with any parameters, use the anything() matcher:
[verify(mockService, never()) registerWithUsername:(id)anything() password:(id)anything()];

Executing my 3 calls one after the other in my activate function

I work on a project with durandal/breeze. I have the following code in my activate function:
var activate = function (routeData) {
initLookups();
var idTran = parseInt(routeData.idTran);
var idItin = parseInt(routeData.idItin);
if (idItin == -1)
idItin = datacontext.createItineraryDetailTransport(idTran);
datacontext.getTransportById(idTran, transport);
datacontext.getItineraryById(idItin, itinerary);
}
As you can see in the above code, I have 3 calls to the datacontext:
datacontext.createItineraryDetailTransport >> eventually... if (idItin == -1)
datacontext.getTransportById
datacontext.getItineraryById
The problem right now is that each call is not waiting for the previous one to complete before executing.
My question: how to proceed to be sure one call is finished before executing the next one? Please note that the first call is inside a condition... I'm thinking of using 'promises' but don't know.
Thanks.
The tricky part to what you're trying to do is conditionally chain three calls together.
You can simply chain multiple calls together using the then() method. However in your case, you need an initial promise to chain when the first condition isn't met.
The $.when() method is the trick here, because you can either chain an promise returned by Breeze, or you can chain a "dummy" promise, which is what $.when() gives you. If the first parameter passed to $.when is not a promise, then it returns a promise that is immediately resolved.
If I understand your question correctly, you should be able to write your code something like this:
var activate = function (routeData) {
initLookups();
var idTran = parseInt(routeData.idTran);
var idItin = parseInt(routeData.idItin);
var idtDeferred = $.when();
if (idItin == -1)
idtDeferred = datacontext.createItineraryDetailTransport(idTran);
idtDeferred
.then(datacontext.getTransportById(idTran, transport))
.then(datacontext.getItineraryById(idItin, itinerary));
}
Your code example looks like datacontext.createItineraryDetailTransport is supposed to set the idItin var, but I'm assuming that it returns a promise like typical breeze queries.
Certain parts of your example are unclear to me.
Is initLookups asynchronous? If so, do you have to wait for it to complete before performing the other asynchronous steps?
How can createItineraryDetailTransport be asynchronous when it returns the integer, idItin?
What the heck does createItineraryDetailTransport actually do? My guess is that idItin == -1 when you don't have an ItineraryDetailTransport entity yet and therefore don't have the key you need to call getItineraryById. If so, you have to restructure the signature of createItineraryDetailTransport.
Why does getItineraryById have to wait for getTransportById when they seemingly have nothing in common?
What are transport and itinerary? I'm guessing they are accidentally omitted variables that will be set with the results of the async calls within those datacontext methods.
Where is your error handling? What should happen if one of the async calls fails?
These issues must be sorted out before someone can give you a really good answer.
Joseph Gabriel seems to me to be mostly on the right track although I might have written it a little differently
...
var transport, itinerary;
var promise = (idItin == -1) ?
datacontext.createItineraryDetailTransport(aCallBackThatSets_idItin) :
Q.resolve(); // creates a resolved promise
promise = promise
.then(datacontext.getTransportById(idTran, transport)
.then(datacontext.getItineraryById(idItin, itinerary))
.fail(yourErrorHandler);
return promise; // don't forget to return the promise!
The most important step missing from Joseph Gabriel's suggestion ... and the reason you couldn't make his suggestion work ... is that it neglected to return the promise.
You must return a promise if you want Durandal to wait before activating the view.

Resources