+/*
+ * List ALL OpenIDs in the database
+ */
+void cmd_oida(char *argbuf) {
+ struct cdbdata *cdboi;
+ long usernum;
+ struct ctdluser usbuf;
+
+ if (CtdlAccessCheck(ac_aide)) return;
+ cdb_rewind(CDB_OPENID);
+ cprintf("%d List of all OpenIDs in the database:\n", LISTING_FOLLOWS);
+
+ while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
+ if (cdboi->len > sizeof(long)) {
+ memcpy(&usernum, cdboi->ptr, sizeof(long));
+ if (CtdlGetUserByNumber(&usbuf, usernum) != 0) {
+ usbuf.fullname[0] = 0;
+ }
+ cprintf("%s|%ld|%s\n",
+ cdboi->ptr + sizeof(long),
+ usernum,
+ usbuf.fullname
+ );
+ }
+ cdb_free(cdboi);
+ }
+ cprintf("000\n");
+}
+
+
+/*
+ * Attempt to register (populate the vCard) the currently-logged-in user
+ * using the data from Simple Registration Extension, if present.
+ */
+void populate_vcard_from_sreg(HashList *sreg_keys) {
+
+ struct vCard *v;
+ int pop = 0; /* number of fields populated */
+ char *data = NULL;
+ char *postcode = NULL;
+ char *country = NULL;
+
+ if (!sreg_keys) return;
+ v = vcard_new();
+ if (!v) return;
+
+ if (GetHash(sreg_keys, "identity", 8, (void *) &data)) {
+ vcard_add_prop(v, "url;type=openid", data);
+ ++pop;
+ }
+
+ if (GetHash(sreg_keys, "sreg.email", 10, (void *) &data)) {
+ vcard_add_prop(v, "email;internet", data);
+ ++pop;
+ }
+
+ if (GetHash(sreg_keys, "sreg.nickname", 13, (void *) &data)) {
+ vcard_add_prop(v, "nickname", data);
+ ++pop;
+ }
+
+ if (GetHash(sreg_keys, "sreg.fullname", 13, (void *) &data)) {
+ char n[256];
+ vcard_add_prop(v, "fn", data);
+ vcard_fn_to_n(n, data, sizeof n);
+ vcard_add_prop(v, "n", n);
+ ++pop;
+ }
+
+ if (!GetHash(sreg_keys, "sreg.postcode", 13, (void *) &postcode)) {
+ postcode = NULL;
+ }
+
+ if (!GetHash(sreg_keys, "sreg.country", 12, (void *) &country)) {
+ country = NULL;
+ }
+
+ if (postcode || country) {
+ char adr[256];
+ snprintf(adr, sizeof adr, ";;;;;%s;%s",
+ (postcode ? postcode : ""),
+ (country ? country : "")
+ );
+ vcard_add_prop(v, "adr", adr);
+ ++pop;
+ }
+
+ if (GetHash(sreg_keys, "sreg.dob", 8, (void *) &data)) {
+ vcard_add_prop(v, "bday", data);
+ ++pop;
+ }
+
+ if (GetHash(sreg_keys, "sreg.gender", 11, (void *) &data)) {
+ vcard_add_prop(v, "x-funambol-gender", data);
+ ++pop;
+ }
+
+ /* Only save the vCard if there is some useful data in it */
+ if (pop > 0) {
+ char *ser;
+ ser = vcard_serialize(v);
+ if (ser) {
+ CtdlWriteObject(USERCONFIGROOM, "text/x-vcard",
+ ser, strlen(ser)+1, &CC->user, 0, 0, 0
+ );
+ free(ser);
+ }
+ }
+ vcard_free(v);
+}
+
+
+/*
+ * Create a new user account, manually specifying the name, after successfully
+ * verifying an OpenID (which will of course be attached to the account)
+ */
+void cmd_oidc(char *argbuf) {
+ ctdl_openid *oiddata = (ctdl_openid *) CC->openid_data;
+
+ if ( (!oiddata) || (!oiddata->verified) ) {
+ cprintf("%d You have not verified an OpenID yet.\n", ERROR);
+ return;
+ }
+
+ /* We can make the semantics of OIDC exactly the same as NEWU, simply
+ * by _calling_ cmd_newu() and letting it run. Very clever!
+ */
+ cmd_newu(argbuf);
+
+ /* Now, if this logged us in, we have to attach the OpenID */
+ if (CC->logged_in) {
+ attach_openid(&CC->user, oiddata->claimed_id);
+ if (oiddata->sreg_keys != NULL) {
+ populate_vcard_from_sreg(oiddata->sreg_keys);
+ }
+ }
+
+}
+