- Timestamp:
- Jun 24, 2003, 11:12:09 PM (21 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 658dc2f
- Parents:
- 723c427
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
zwrite.c
r8262340 rce7db4d 7 7 static const char fileIdent[] = "$Id$"; 8 8 9 int owl_zwrite_create_and_send_from_line(char *cmd, char *msg) { 10 owl_zwrite z; 11 int rv; 12 rv = owl_zwrite_create_from_line(&z, cmd); 13 if (rv) return(rv); 14 owl_zwrite_send_message(&z, msg); 15 owl_zwrite_free(&z); 16 return(0); 17 } 18 19 int owl_zwrite_create_from_line(owl_zwrite *z, char *line) { 9 int owl_zwrite_create_from_line(owl_zwrite *z, char *line) 10 { 20 11 int argc, badargs, myargc; 21 12 char **argv, **myargv; … … 25 16 badargs=0; 26 17 27 /* set the defaults */ 28 strcpy(z->realm, ""); 29 strcpy(z->class, "message"); 30 strcpy(z->inst, "personal"); 31 strcpy(z->opcode, ""); 32 z->zsig=owl_strdup(""); 18 /* start with null entires */ 19 z->realm=NULL; 20 z->class=NULL; 21 z->inst=NULL; 22 z->opcode=NULL; 23 z->zsig=NULL; 24 z->message=NULL; 33 25 z->cc=0; 34 26 z->noping=0; … … 52 44 break; 53 45 } 54 strcpy(z->class,myargv[1]);46 z->class=owl_strdup(myargv[1]); 55 47 myargv+=2; 56 48 myargc-=2; … … 60 52 break; 61 53 } 62 strcpy(z->inst,myargv[1]);54 z->inst=owl_strdup(myargv[1]); 63 55 myargv+=2; 64 56 myargc-=2; … … 68 60 break; 69 61 } 70 strcpy(z->realm, myargv[1]); 62 z->realm=owl_strdup(myargv[1]); 63 myargv+=2; 64 myargc-=2; 65 } else if (!strcmp(myargv[0], "-s")) { 66 if (myargc<2) { 67 badargs=1; 68 break; 69 } 70 z->zsig=owl_strdup(myargv[1]); 71 71 myargv+=2; 72 72 myargc-=2; … … 76 76 break; 77 77 } 78 strcpy(z->opcode, myargv[1]); 79 myargv+=2; 80 myargc-=2; 78 z->opcode=owl_strdup(myargv[1]); 79 myargv+=2; 80 myargc-=2; 81 } else if (!strcmp(myargv[0], "-m")) { 82 if (myargc<2) { 83 badargs=1; 84 break; 85 } 86 /* we must already have users */ 87 if (owl_list_get_size(&(z->recips))<1) { 88 badargs=1; 89 break; 90 } 91 92 /* Once we have -m, gobble up everything else on the line */ 93 myargv++; 94 myargc--; 95 z->message=owl_strdup(""); 96 while (myargc) { 97 z->message=realloc(z->message, strlen(z->message)+strlen(myargv[0])+5); 98 strcat(z->message, " "); 99 strcat(z->message, myargv[0]); 100 myargc--; 101 myargv++; 102 } 103 break; 81 104 } else if (!strcmp(myargv[0], "-C")) { 82 105 z->cc=1; … … 101 124 } 102 125 126 /* now deal with defaults */ 127 if (z->class==NULL) z->class=owl_strdup("message"); 128 if (z->inst==NULL) z->inst=owl_strdup("personal"); 129 if (z->realm==NULL) z->realm=owl_strdup(""); 130 if (z->opcode==NULL) z->opcode=owl_strdup(""); 131 /* z->message is allowed to stay NULL */ 132 103 133 if (!strcasecmp(z->class, "message") && 104 134 !strcasecmp(z->inst, "personal") && 105 135 owl_list_get_size(&(z->recips))==0) { 106 /* do the makemsg somewhere else */107 136 owl_function_makemsg("You must specify a recipient"); 108 137 return(-1); 109 138 } 110 139 111 /* set a zsig */ 112 zsigproc = owl_global_get_zsigproc(&g); 113 zsigowlvar = owl_global_get_zsig(&g); 114 zsigzvar = ZGetVariable("zwrite-signature"); 115 116 if (zsigowlvar && *zsigowlvar) { 117 owl_free(z->zsig); 118 z->zsig=strdup(zsigowlvar); 119 } else if (zsigproc && *zsigproc) { 120 FILE *file; 121 char buff[LINE], *openline; 122 123 /* simple hack for now to nuke stderr */ 124 openline=owl_malloc(strlen(zsigproc)+40); 125 strcpy(openline, zsigproc); 126 strcat(openline, " 2> /dev/null"); 127 file=popen(openline, "r"); 128 owl_free(openline); 129 if (!file) { 130 if (zsigzvar && *zsigzvar) { 131 owl_free(z->zsig); 132 z->zsig=owl_strdup(zsigzvar); 133 } 134 } else { 135 owl_free(z->zsig); 136 z->zsig=owl_malloc(LINE); 137 strcpy(z->zsig, ""); 138 while (fgets(buff, LINE, file)) { /* wrong sizing */ 139 strcat(z->zsig, buff); 140 } 141 pclose(file); 142 if (z->zsig[strlen(z->zsig)-1]=='\n') { 143 z->zsig[strlen(z->zsig)-1]='\0'; 144 } 145 } 146 } else if (zsigzvar) { 147 owl_free(z->zsig); 148 z->zsig=owl_strdup(zsigzvar); 149 } else if (((pw=getpwuid(getuid()))!=NULL) && (pw->pw_gecos)) { 150 owl_free(z->zsig); 151 z->zsig=strdup(pw->pw_gecos); 152 ptr=strchr(z->zsig, ','); 153 if (ptr) { 154 ptr[0]='\0'; 155 } 156 } 157 158 return(0); 159 } 160 161 void owl_zwrite_send_ping(owl_zwrite *z) { 140 /* get a zsig, if not given */ 141 if (z->zsig==NULL) { 142 zsigproc = owl_global_get_zsigproc(&g); 143 zsigowlvar = owl_global_get_zsig(&g); 144 zsigzvar = ZGetVariable("zwrite-signature"); 145 146 if (zsigowlvar && *zsigowlvar) { 147 z->zsig=owl_strdup(zsigowlvar); 148 } else if (zsigproc && *zsigproc) { 149 FILE *file; 150 char buff[LINE], *openline; 151 152 /* simple hack for now to nuke stderr */ 153 openline=owl_malloc(strlen(zsigproc)+40); 154 strcpy(openline, zsigproc); 155 strcat(openline, " 2> /dev/null"); 156 file=popen(openline, "r"); 157 owl_free(openline); 158 if (!file) { 159 if (zsigzvar && *zsigzvar) { 160 z->zsig=owl_strdup(zsigzvar); 161 } 162 } else { 163 z->zsig=owl_malloc(LINE*5); 164 strcpy(z->zsig, ""); 165 while (fgets(buff, LINE, file)) { /* wrong sizing */ 166 strcat(z->zsig, buff); 167 } 168 pclose(file); 169 if (z->zsig[strlen(z->zsig)-1]=='\n') { 170 z->zsig[strlen(z->zsig)-1]='\0'; 171 } 172 } 173 } else if (zsigzvar) { 174 z->zsig=owl_strdup(zsigzvar); 175 } else if (((pw=getpwuid(getuid()))!=NULL) && (pw->pw_gecos)) { 176 z->zsig=strdup(pw->pw_gecos); 177 ptr=strchr(z->zsig, ','); 178 if (ptr) { 179 ptr[0]='\0'; 180 } 181 } 182 } 183 184 return(0); 185 } 186 187 void owl_zwrite_send_ping(owl_zwrite *z) 188 { 162 189 int i, j; 163 190 char to[LINE]; … … 184 211 } 185 212 186 void owl_zwrite_send_message(owl_zwrite *z, char *msg) { 213 void owl_zwrite_set_message(owl_zwrite *z, char *msg) 214 { 215 if (z->message) owl_free(z->message); 216 z->message=owl_strdup(msg); 217 } 218 219 char *owl_zwrite_get_message(owl_zwrite *z) 220 { 221 if (z->message) return(z->message); 222 return(""); 223 } 224 225 int owl_zwrite_is_message_set(owl_zwrite *z) 226 { 227 if (z->message) return(1); 228 return(0); 229 } 230 231 int owl_zwrite_send_message(owl_zwrite *z) 232 { 187 233 int i, j; 188 234 char to[LINE]; 235 236 if (z->message==NULL) return(-1); 189 237 190 238 j=owl_list_get_size(&(z->recips)); … … 202 250 } 203 251 } 204 tmpmsg=owl_malloc(strlen( msg)+strlen(toline)+30);205 sprintf(tmpmsg, "%s\n%s", toline, msg);252 tmpmsg=owl_malloc(strlen(z->message)+strlen(toline)+30); 253 sprintf(tmpmsg, "%s\n%s", toline, z->message); 206 254 } 207 255 … … 215 263 send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, tmpmsg); 216 264 } else { 217 send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, msg);265 send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, z->message); 218 266 } 219 267 } … … 223 271 } else { 224 272 sprintf(to, "@%s", z->realm); 225 send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, msg); 226 } 227 } 228 229 char *owl_zwrite_get_class(owl_zwrite *z) { 273 send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, z->message); 274 } 275 return(0); 276 } 277 278 int owl_zwrite_create_and_send_from_line(char *cmd, char *msg) 279 { 280 owl_zwrite z; 281 int rv; 282 rv=owl_zwrite_create_from_line(&z, cmd); 283 if (rv) return(rv); 284 if (!owl_zwrite_is_message_set(&z)) { 285 owl_zwrite_set_message(&z, msg); 286 } 287 owl_zwrite_send_message(&z); 288 owl_zwrite_free(&z); 289 return(0); 290 } 291 292 char *owl_zwrite_get_class(owl_zwrite *z) 293 { 230 294 return(z->class); 231 295 } 232 296 233 char *owl_zwrite_get_instance(owl_zwrite *z) { 297 char *owl_zwrite_get_instance(owl_zwrite *z) 298 { 234 299 return(z->inst); 235 300 } 236 301 237 char *owl_zwrite_get_opcode(owl_zwrite *z) { 302 char *owl_zwrite_get_opcode(owl_zwrite *z) 303 { 238 304 return(z->opcode); 239 305 } 240 306 241 char *owl_zwrite_get_realm(owl_zwrite *z) { 307 char *owl_zwrite_get_realm(owl_zwrite *z) 308 { 242 309 return(z->realm); 243 310 } 244 311 245 char *owl_zwrite_get_zsig(owl_zwrite *z) { 246 return(z->zsig); 247 } 248 249 void owl_zwrite_get_recipstr(owl_zwrite *z, char *buff) { 312 char *owl_zwrite_get_zsig(owl_zwrite *z) 313 { 314 if (z->zsig) return(z->zsig); 315 return(""); 316 } 317 318 void owl_zwrite_get_recipstr(owl_zwrite *z, char *buff) 319 { 250 320 int i, j; 251 321 … … 259 329 } 260 330 261 int owl_zwrite_get_numrecips(owl_zwrite *z) { 331 int owl_zwrite_get_numrecips(owl_zwrite *z) 332 { 262 333 return(owl_list_get_size(&(z->recips))); 263 334 } 264 335 265 char *owl_zwrite_get_recip_n(owl_zwrite *z, int n) { 336 char *owl_zwrite_get_recip_n(owl_zwrite *z, int n) 337 { 266 338 return(owl_list_get_element(&(z->recips), n)); 267 339 } 268 340 269 int owl_zwrite_is_personal(owl_zwrite *z) { 341 int owl_zwrite_is_personal(owl_zwrite *z) 342 { 270 343 /* return true if at least one of the recipients is personal */ 271 344 int i, j; … … 280 353 } 281 354 282 void owl_zwrite_free(owl_zwrite *z) { 355 void owl_zwrite_free(owl_zwrite *z) 356 { 283 357 owl_list_free_all(&(z->recips), &owl_free); 284 owl_free(z->zsig); 285 } 358 if (z->class) owl_free(z->class); 359 if (z->inst) owl_free(z->inst); 360 if (z->opcode) owl_free(z->opcode); 361 if (z->realm) owl_free(z->realm); 362 if (z->message) owl_free(z->message); 363 if (z->zsig) owl_free(z->zsig); 364 }
Note: See TracChangeset
for help on using the changeset viewer.