Changeset 1233:f6b3c9c47813 in roaraudio


Ignore:
Timestamp:
02/25/09 18:46:14 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

done a lot basic code

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • include/libroar/pinentry.h

    r1232 r1233  
    4141 
    4242struct roar_pinentry { 
    43  int open; 
     43 int opened; 
    4444 pid_t pid; 
    4545 int in; 
    4646 int out; 
     47 FILE * fin; 
    4748}; 
    4849 
  • libroar/pinentry.c

    r1232 r1233  
    3535#include "libroar.h" 
    3636 
     37int roar_pinentry_open (struct roar_pinentry * pe, int flags, char * display, char * tty, char * term) { 
     38 if ( pe == NULL ) 
     39  return -1; 
     40 
     41 memset(pe, 0, sizeof(struct roar_pinentry)); 
     42 pe->in  = -1; 
     43 pe->out = -1; 
     44 
     45#ifdef ROAR_HAVE_BIN_PINENTRY 
     46 return 0; 
     47#else 
     48 return -1; 
     49#endif 
     50} 
     51 
     52int roar_pinentry_simple_open(struct roar_pinentry * pe) { 
     53 return roar_pinentry_open(pe, 0, NULL, NULL, NULL); 
     54} 
     55 
     56int roar_pinentry_close(struct roar_pinentry * pe) { 
     57 if ( pe == NULL ) 
     58  return -1; 
     59 
     60 if ( pe->opened == 0 ) 
     61  return 0; 
     62 
     63 if ( pe->out != -1 ) 
     64  close(pe->out); 
     65 
     66 if ( pe->in  != -1 ) 
     67  close(pe->in); 
     68 
     69 return 0; 
     70} 
     71 
     72int roar_pinentry_send (struct roar_pinentry * pe, char * cmd,  char * args) { 
     73 size_t len; 
     74 
     75 if ( pe == NULL ) 
     76  return -1; 
     77 
     78 if ( cmd == NULL ) 
     79  return -1; 
     80 
     81 len = strlen(cmd); 
     82 
     83 if ( write(pe->out, cmd, len) != len ) 
     84  return -1; 
     85 
     86 if ( args != NULL ) { 
     87  len = strlen(args); 
     88 
     89  if ( write(pe->out, args, len) != len ) 
     90   return -1; 
     91 } 
     92 
     93 if ( write(pe->out, "\n", 1) != 1 ) 
     94  return -1; 
     95 
     96 return 0; 
     97} 
     98 
     99int roar_pinentry_recv (struct roar_pinentry * pe, char * line, char * opts) { 
     100 return -1; 
     101} 
     102 
     103int roar_pinentry_req  (struct roar_pinentry * pe, char * cmd,  char * args, char * line, char * opts) { 
     104 if ( pe == NULL ) 
     105  return -1; 
     106 
     107 if ( roar_pinentry_send(pe, cmd, args) != 0 ) 
     108  return -1; 
     109 
     110 return roar_pinentry_recv(pe, line, opts); 
     111} 
     112 
     113int roar_pinentry_set_desc (struct roar_pinentry * pe, char * desc) { 
     114 return roar_pinentry_set(pe, "DESC", desc); 
     115} 
     116 
     117int roar_pinentry_set      (struct roar_pinentry * pe, char * obj, char * text) { 
     118 char req[80] = "SET"; 
     119 
     120 if ( pe == NULL ) 
     121  return -1; 
     122 
     123 if ( obj == NULL ) 
     124  return -1; 
     125 
     126 if ( strlen(obj) > (80-1 /* \0 */ + 3 /* "SET" */ + 1 /* " " */) ) 
     127  return -1; 
     128 
     129 strncat(req, obj, 80-5); 
     130 strncat(req, " ", 2); 
     131 
     132 return roar_pinentry_req(pe, req, text, NULL, NULL); 
     133} 
     134 
    37135//ll 
Note: See TracChangeset for help on using the changeset viewer.