phalcon/cphalcon — pull request #1347 by sjinks (2013-10-08 05:21:20+00:00)
Title: Phalcon\Security::computeHmac() plus many bug fixes

The initial idea of this PR was to introduce Phalcon\Security\computeHmac() function which computes [HMAC](http://en.wikipedia.org/wiki/Hash-based_message_authentication_code) of the given message — it can be used to verify both the data integrity and the authentication of a message. One of its possible applications is to verify that the cookies were not tampered with.

Bug fixes included into this PR:
* Issue #1340
* Issue #1343
* Issue #1345

To properly fix #1340 (and similar bugs in the rest of the code) I have made these changes:
* `PHALCON_SEPARATE_PARAM()` now always separates its parameter — regardless of its refcount;
* introduced `phalcon_fetch_parameters_ex()` function and `fetch_params_ex()` macro — these ones return `zval**` instead of `zval*`. However, this allows to use `SEPARATE_ZVAL()` on the returned arguments without worrying about memory leaks;
* introduced convenience macros for type conversion — `PHALCON_ENSURE_IS_xxx()`. These ones take `zval**` as their argument, separate it if it is not a reference and perform type conversion. These macros are friendly to memory frames; they can work with method arguments but only if the arguments were fetched with `fetch_params_ex()`.