-struct associate_handle *process_associate_response(char *claimed_id, char *associate_response)
-{
- struct associate_handle *h = NULL;
- char *ptr = associate_response;
- char thisline[256];
- char thiskey[256];
- char thisdata[256];
-
- h = (struct associate_handle *) malloc(sizeof(struct associate_handle));
- safestrncpy(h->claimed_id, claimed_id, sizeof h->claimed_id);
-
- do {
- ptr = memreadline(ptr, thisline, sizeof thisline);
- extract_token(thiskey, thisline, 0, ':', sizeof thiskey);
- extract_token(thisdata, thisline, 1, ':', sizeof thisdata);
-
- if (!strcasecmp(thiskey, "assoc_type")) {
- safestrncpy(h->assoc_type, thisdata, sizeof h->assoc_type);
- }
- else if (!strcasecmp(thiskey, "expires_in")) {
- h->expiration_time = time(NULL) + atol(thisdata);
- }
- else if (!strcasecmp(thiskey, "assoc_handle")) {
- safestrncpy(h->assoc_handle, thisdata, sizeof h->assoc_handle);
+void cmd_oids(char *argbuf) {
+ const char *Pos = NULL;
+ StrBuf *ArgBuf = NULL;
+ StrBuf *ReplyBuf = NULL;
+ StrBuf *return_to = NULL;
+ StrBuf *trust_root = NULL;
+ StrBuf *openid_delegate = NULL;
+ StrBuf *RedirectUrl = NULL;
+ struct CitContext *CCC = CC; /* CachedCitContext - performance boost */
+ ctdl_openid *oiddata;
+
+ Free_ctdl_openid ((ctdl_openid**)&CCC->openid_data);
+
+ CCC->openid_data = oiddata = malloc(sizeof(ctdl_openid));
+ if (oiddata == NULL) {
+ cprintf("%d malloc failed\n", ERROR + INTERNAL_ERROR);
+ return;
+ }
+ memset(oiddata, 0, sizeof(ctdl_openid));
+ CCC->openid_data = (void *) oiddata;
+
+ ArgBuf = NewStrBufPlain(argbuf, -1);
+
+ oiddata->verified = 0;
+ oiddata->claimed_id = NewStrBufPlain(NULL, StrLength(ArgBuf));
+ trust_root = NewStrBufPlain(NULL, StrLength(ArgBuf));
+ return_to = NewStrBufPlain(NULL, StrLength(ArgBuf));
+
+ StrBufExtract_NextToken(oiddata->claimed_id, ArgBuf, &Pos, '|');
+ StrBufExtract_NextToken(return_to, ArgBuf, &Pos, '|');
+ StrBufExtract_NextToken(trust_root, ArgBuf, &Pos, '|');
+
+ syslog(LOG_DEBUG, "User-Supplied Identifier is: %s", ChrPtr(oiddata->claimed_id));
+
+
+ /********** OpenID 2.0 section 7.3 - Discovery **********/
+
+ /* First we're supposed to attempt XRI based resolution.
+ * No one is using this, no one is asking for it, no one wants it.
+ * So we're not even going to bother attempting this mode.
+ */
+
+ /* Second we attempt YADIS.
+ * Google uses this so we'd better do our best to implement it.
+ */
+ int yadis_succeeded = perform_yadis_discovery(oiddata->claimed_id);
+
+ /* Third we attempt HTML-based discovery. Here we go! */
+ if ( (yadis_succeeded == 0)
+ && (fetch_http(oiddata->claimed_id, &ReplyBuf) > 0)
+ && (StrLength(ReplyBuf) > 0)
+ ) {
+ openid_delegate = NewStrBuf();
+ oiddata->server = NewStrBuf();
+ extract_link(oiddata->server, HKEY("openid.server"), ReplyBuf);
+ extract_link(openid_delegate, HKEY("openid.delegate"), ReplyBuf);
+
+ if (StrLength(oiddata->server) == 0) {
+ cprintf("%d There is no OpenID identity provider at this URL.\n", ERROR);
+ FreeStrBuf(&ArgBuf);
+ FreeStrBuf(&ReplyBuf);
+ FreeStrBuf(&return_to);
+ FreeStrBuf(&trust_root);
+ FreeStrBuf(&openid_delegate);
+ FreeStrBuf(&RedirectUrl);
+ return;