Changeset 1233:f6b3c9c47813 in roaraudio
- Timestamp:
- 02/25/09 18:46:14 (15 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
include/libroar/pinentry.h
r1232 r1233 41 41 42 42 struct roar_pinentry { 43 int open ;43 int opened; 44 44 pid_t pid; 45 45 int in; 46 46 int out; 47 FILE * fin; 47 48 }; 48 49 -
libroar/pinentry.c
r1232 r1233 35 35 #include "libroar.h" 36 36 37 int 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 52 int roar_pinentry_simple_open(struct roar_pinentry * pe) { 53 return roar_pinentry_open(pe, 0, NULL, NULL, NULL); 54 } 55 56 int 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 72 int 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 99 int roar_pinentry_recv (struct roar_pinentry * pe, char * line, char * opts) { 100 return -1; 101 } 102 103 int 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 113 int roar_pinentry_set_desc (struct roar_pinentry * pe, char * desc) { 114 return roar_pinentry_set(pe, "DESC", desc); 115 } 116 117 int 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 37 135 //ll
Note: See TracChangeset
for help on using the changeset viewer.