OAuth in iwhd preview patch
Jim Meyering
jim at meyering.net
Mon Oct 3 20:13:35 UTC 2011
Pete Zaitcev wrote:
> Guys:
>
> Below is what I have now for 2-legged OAuth in iwhd. It actually works,
> with oauthtest2 from liboauth.
>
> The patch is only a small piece, since it has no client, which we need
> to run the tests, has no documentation, and no user list. However, it
> retires most of the risk. We know that it can be done, this way.
> The biggest risk left is interoperability with Aeolus.
>
> BTW, the OAuth header looks like this:
>
> Authorization: OAuth realm="http://example.org/", oauth_consumer_key="chiaki",
> oauth_nonce="mitPzrhrCMHABJiYava_", oauth_signature_method="HMAC-SHA1",
> oauth_timestamp="1317182031", oauth_version="1.0",
> oauth_signature="Ya36%2FkXTG5YATRx%2BWAXK9NXzZCg%3D"
Thanks again.
BTW, have you thought about extending "make check" to test
all of this new code?
Here are some suggested changes.
The first chunk is just to save a little vertical space.
The point of using "sizeof *ret" rather than "sizeof(struct use)"
is maintainability. If ret ever happens to have a different type,
you won't have to remember (or risk a bug) to change the use in
that sizeof.
I added a comment for your auth_type_check function,
because it wasn't immediately obvious what it does.
While writing it, I realized that returning "false"
rather than NULL was probably best fixed.
Then I moved a few trailing "{" to beginning of line,
along with a stray "return".
diff --git a/rest.c b/rest.c
index fec602c..6d5a146 100644
--- a/rest.c
+++ b/rest.c
@@ -2108,18 +2108,16 @@ struct user {
static struct user *
user_lookup (const char *user)
{
- struct user *ret;
-
/*
* We do not have a real user table yet, so just compare with -U.
*/
if (username == NULL || strcmp(user, username) != 0)
return NULL;
- ret = malloc(sizeof(struct user));
+ struct user *ret = malloc(sizeof *ret);
if (!ret)
return NULL;
- memset(ret,0,sizeof(struct user));
+ memset(ret,0,sizeof *ret);
strcpy(ret->name, username);
strcpy(ret->pass, userpass);
return ret;
@@ -2158,6 +2156,10 @@ rebuild_url(bool is_ssl, struct MHD_Connection *conn, const char *path)
return ret;
}
+/* Ensure that VAL consists of optional spaces, followed by
+ the string, TYPE, followed by more optional spaces.
+ If so, return a pointer to the first non-space following
+ TYPE in VAL. Otherwise, return NULL. */
static const char *
auth_type_check (const char *val, const char *type)
{
@@ -2167,19 +2169,19 @@ auth_type_check (const char *val, const char *type)
p = val;
while (*p == ' ') {
if (*p == 0) {
- return false;
+ return NULL;
}
p++;
}
if (strncmp(p, type, tlen) != 0)
- return false;
+ return NULL;
p += tlen;
if (*p != ' ')
- return false;
+ return NULL;
p++;
while (*p == ' ') {
if (*p == 0) {
- return false;
+ return NULL;
}
p++;
}
@@ -2375,10 +2377,9 @@ auth_hdr_split (int *pargc, char ***pargv, const char *val)
/* Extract the value from key="val". */
static char *
-oauth_param_val(const char *arg) {
- char *val;
-
- val = strchr(arg, '=');
+oauth_param_val(const char *arg)
+{
+ char *val = strchr(arg, '=');
if (!val)
return NULL;
val++;
@@ -2389,11 +2390,13 @@ oauth_param_val(const char *arg) {
/* clone of oauth_param_exists with minimal changes */
static int
-oauth_param_find(char **argv, int argc, const char *key) {
+oauth_param_find(char **argv, int argc, const char *key)
+{
int i;
- size_t l= strlen(key);
+ size_t l = strlen(key);
for (i=0;i<argc;i++)
- if (strlen(argv[i])>l && !strncmp(argv[i],key,l) && argv[i][l] == '=') return i;
+ if (strlen(argv[i])>l && !strncmp(argv[i],key,l) && argv[i][l] == '=')
+ return i;
return -1;
}
More information about the iwhd-devel
mailing list