/[winpt]/trunk/Src/wptKeyCache.cpp
ViewVC logotype

Diff of /trunk/Src/wptKeyCache.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 147 by twoaday, Fri Jan 13 14:21:16 2006 UTC revision 167 by twoaday, Thu Jan 26 10:17:17 2006 UTC
# Line 121  parse_attr_list (FILE *fp, const BYTE *d Line 121  parse_attr_list (FILE *fp, const BYTE *d
121  }  }
122    
123    
124    /* Always use the $users temp folder. */
125    static FILE*
126    w32_tmpfile (char *tmp, DWORD tmplen)
127    {
128        char id[16];
129    
130        if (!GetTempPath (tmplen-17, tmp))
131            return NULL;
132        if (tmp[strlen (tmp)-1] != '\\')
133            strcat (tmp, "\\");
134        _snprintf (id, sizeof (id)-1, "%lu", GetTickCount ());
135        strcat (tmp, id);
136        return fopen (tmp, "w+b");
137    }
138    
139    
140  static int  static int
141  parse_attr_data (const char *keyid, attr_list_t *list)  parse_attr_data (const char *keyid, attr_list_t *list)
142  {  {
143      gpgme_error_t err;      gpgme_error_t err;
144      FILE *tmp;      FILE *tmp;
145      char *status;      char *status, tmpnam[MAX_PATH+1];
146      BYTE *data;      BYTE *data;
147      DWORD ndata;      DWORD ndata;
148    
# Line 134  parse_attr_data (const char *keyid, attr Line 150  parse_attr_data (const char *keyid, attr
150      if (err)      if (err)
151          return err;          return err;
152    
153      if (ndata > 0) {      if (ndata > 0 && (tmp = w32_tmpfile (tmpnam, MAX_PATH)) != NULL) {
         tmp = tmpfile ();  
154          fwrite (status, 1, strlen (status), tmp);          fwrite (status, 1, strlen (status), tmp);
155          fflush (tmp);          fflush (tmp);
156          rewind (tmp);          rewind (tmp);
157    
158          ndata = parse_attr_list (tmp, data, ndata, list);          ndata = parse_attr_list (tmp, data, ndata, list);
159          fclose (tmp);          fclose (tmp);
160            DeleteFile (tmpnam);
161      }      }
162      else      else
163          *list = NULL;          *list = NULL;
# Line 503  keycache_reload_photo (gpg_keycache_t ct Line 519  keycache_reload_photo (gpg_keycache_t ct
519    
520  /* Return the next key which was updated. Before it is  /* Return the next key which was updated. Before it is
521     returned the update flag is cleared.     returned the update flag is cleared.
522       @r_status is 1 for a new key and 2 for an updated key.
523     Return value: 0 on success. */     Return value: 0 on success. */
524  gpgme_error_t  gpgme_error_t
525  gpg_keycache_next_updated_key (gpg_keycache_t ctx,  gpg_keycache_next_updated_key (gpg_keycache_t ctx,
526                                 struct keycache_s **r_obj)                                 struct keycache_s **r_obj,
527                                   int *r_status)
528  {  {
529      struct keycache_s *c;      struct keycache_s *c;
530    
531      for (c = ctx->item; c; c = c->next) {      for (c = ctx->item; c; c = c->next) {
532          if (c->flags == 1) {          if (c->flags != 0) {
533                *r_status = c->flags;
534              c->flags = 0;              c->flags = 0;
535              *r_obj = c;              *r_obj = c;
536              return 0;              return 0;
# Line 535  gpg_keycache_update_key (gpg_keycache_t Line 554  gpg_keycache_update_key (gpg_keycache_t
554      err = gpgme_new (&gctx);      err = gpgme_new (&gctx);
555      if (err)      if (err)
556          return err;          return err;
557        gpgme_set_keylist_mode  (gctx, GPGME_KEYLIST_MODE_SIGS);
558      err = gpgme_get_key (gctx, keyid, &key, is_sec);      err = gpgme_get_key (gctx, keyid, &key, is_sec);
559      gpgme_release (gctx);      gpgme_release (gctx);
560      if (err)      if (err)
# Line 544  gpg_keycache_update_key (gpg_keycache_t Line 564  gpg_keycache_update_key (gpg_keycache_t
564          log_debug ("keycache update: keyid=%s %p\r\n", keyid, pub);          log_debug ("keycache update: keyid=%s %p\r\n", keyid, pub);
565          gpgme_key_release (fndkey);          gpgme_key_release (fndkey);
566          c->key = key;          c->key = key;
567          c->flags = 1;          c->flags = KC_FLAG_UPD;
568          if (is_sec && pub != NULL &&          if (is_sec && pub != NULL &&
569              !gpg_keycache_find_key (pub, keyid, 0, &fndkey)) {              !gpg_keycache_find_key (pub, keyid, 0, &fndkey)) {
570              log_debug ("keycache update: set public part %p\r\n", fndkey);              log_debug ("keycache update: set public part %p\r\n", fndkey);
# Line 568  gpg_keycache_update_key (gpg_keycache_t Line 588  gpg_keycache_update_key (gpg_keycache_t
588              }              }
589          }          }
590          if (c)          if (c)
591              c->flags = 1;              c->flags = KC_FLAG_ADD;
592      }      }
593      return 0;      return 0;
594  }  }
# Line 746  keycache_next_key (gpg_keycache_t ctx, i Line 766  keycache_next_key (gpg_keycache_t ctx, i
766          *r_key = NULL;          *r_key = NULL;
767          return gpg_error (GPG_ERR_EOF);          return gpg_error (GPG_ERR_EOF);
768      }      }
769            if (ctx->tmp->flags != 0)
770            ctx->tmp->flags = 0; /* reset the 'updated' status. */
771        /* it might be possible there is no public key. */
772        if (flags && ctx->tmp->pubpart == NULL)
773            flags = 0;
774      *r_key = flags? ctx->tmp->pubpart->key : ctx->tmp->key;      *r_key = flags? ctx->tmp->pubpart->key : ctx->tmp->key;
775      *c = ctx->tmp = ctx->tmp->next;      *c = ctx->tmp = ctx->tmp->next;
776      ctx->pos++;      ctx->pos++;
# Line 767  gpg_keycache_next_key (gpg_keycache_t ct Line 791  gpg_keycache_next_key (gpg_keycache_t ct
791      err = keycache_next_key (ctx, flags, &c, r_key);      err = keycache_next_key (ctx, flags, &c, r_key);
792      return err;      return err;
793  }  }
794    
795    /* Search for a key with the pattern @pattern and mark
796       this key as the default signing key if found.
797       Return value: 0 on success. */
798    gpgme_error_t
799    gpg_keycache_set_default_key (gpg_keycache_t ctx,
800                                  const char *pattern)
801    {
802        gpgme_error_t err;
803        gpgme_key_t key;
804        struct keycache_s *itm;
805    
806        err = gpg_keycache_find_key2 (ctx, pattern, 0, &key, &itm);
807        if (err)
808            return err;
809    
810        if (itm)
811            itm->default_key = 1;
812        return 0;
813    }
814    
815    /* Return the default key from the cache. If no was
816       marked before, NULL is returned in @r_key.
817       Return value: 0 on success. */
818    gpgme_error_t
819    gpg_keycache_get_default_key (gpg_keycache_t ctx,
820                                  gpgme_key_t *r_key)
821    {
822        struct keycache_s *itm;
823    
824        *r_key = NULL;
825        for (itm = ctx->item; itm; itm = itm->next) {
826            if (itm->default_key) {
827                *r_key = itm->key;
828                break;
829            }
830        }
831        if (!*r_key)
832            return gpgme_error (GPG_ERR_NOT_FOUND);
833        return 0;
834    }
835    
836    
837    

Legend:
Removed from v.147  
changed lines
  Added in v.167

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26