source: zwrite.c @ 93ee554

barnowl_perlaimdebianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 93ee554 was 93ee554, checked in by Alejandro R. Sedeño <asedeno@mit.edu>, 17 years ago
Merged revisions 734-776 via svnmerge from file:///afs/sipb.mit.edu/project/barnowl/src/svn/trunk ........ r738 | nelhage | 2007-07-07 17:42:45 -0400 (Sat, 07 Jul 2007) | 3 lines Make the built-in regression tests output TAP and add a perl wrapper to call it. ........ r739 | nelhage | 2007-07-07 17:43:22 -0400 (Sat, 07 Jul 2007) | 2 lines Forgot these in the last commit; Make all the tests output TAP ........ r740 | nelhage | 2007-07-07 19:46:16 -0400 (Sat, 07 Jul 2007) | 2 lines Clean up an unused var warning. ........ r741 | nelhage | 2007-07-08 15:37:43 -0400 (Sun, 08 Jul 2007) | 2 lines Adding a -s switch to change the location of the config dir (~/.owl) ........ r742 | nelhage | 2007-07-08 15:39:57 -0400 (Sun, 08 Jul 2007) | 2 lines I don't understand why this didn't commit last time. I blame psvn. ........ r743 | nelhage | 2007-07-11 22:37:16 -0400 (Wed, 11 Jul 2007) | 3 lines Don't allow you to go off the end of an empty message list. [fixes: #9] ........ r744 | nelhage | 2007-07-30 18:47:39 -0400 (Mon, 30 Jul 2007) | 2 lines Fix sending to -c message -i personal ........ r745 | chmrr | 2007-07-30 20:21:18 -0400 (Mon, 30 Jul 2007) | 3 lines r20981@zoq-fot-pik: chmrr | 2007-07-30 20:20:44 -0400 * message length 0 means no fields ........ r746 | nelhage | 2007-07-30 20:25:59 -0400 (Mon, 30 Jul 2007) | 4 lines * zero-len message means no fields * Actually use owl_zephyr_get_zsig to get the zsig, which handles 0- and 1- field zephyrs correctly. ........ r747 | nelhage | 2007-07-30 20:29:36 -0400 (Mon, 30 Jul 2007) | 2 lines Making that last patch actually compile. Bad me. ........ r748 | nelhage | 2007-08-01 01:42:53 -0400 (Wed, 01 Aug 2007) | 3 lines owl_message_get_text needs to make sure there's text to return before returning it. fixes: #15 ........ r749 | nelhage | 2007-08-01 01:52:08 -0400 (Wed, 01 Aug 2007) | 5 lines zephyr smartnarrow now uses the ``personal'' filter to decide whether to narrow to user or not, and the zephyr-user filter now checks for `filter personal' instead of <message,personal,*>. closes #2 ........ r750 | nelhage | 2007-08-01 02:27:30 -0400 (Wed, 01 Aug 2007) | 5 lines Changing the default personal filter to <message,personal,*> for zephyr. refs 2 ........ r751 | nelhage | 2007-08-01 22:58:31 -0400 (Wed, 01 Aug 2007) | 2 lines Display opcodes with the default style ........ r752 | nelhage | 2007-08-08 18:01:51 -0400 (Wed, 08 Aug 2007) | 2 lines Applying ctl's variable shuffling patch for better ANSI C-ness. closes #18 ........ r753 | nelhage | 2007-08-11 01:04:07 -0400 (Sat, 11 Aug 2007) | 3 lines Implement :punt and :unpunt to punt arbitrary filters, rather than just z-triplets. closes #6 ........ r754 | nelhage | 2007-08-11 01:18:37 -0400 (Sat, 11 Aug 2007) | 2 lines Show non-personal pings like stock owl does. closes #12 ........ r756 | asedeno | 2007-08-17 12:48:37 -0400 (Fri, 17 Aug 2007) | 8 lines Apply patch from: http://rt.cpan.org/Public/Bug/Display.html?id=17484 Fixing problems with jabber servers keeping the same stream id when negotiating TLS. Thanks to ghudson for tracking this down. ........ r757 | nelhage | 2007-08-17 17:26:44 -0400 (Fri, 17 Aug 2007) | 4 lines When we're narrowing to an instance, properly include un-instances. This fixes narrowing to any instance that starts with ``un-'' ........ r758 | nelhage | 2007-08-27 19:17:20 -0400 (Mon, 27 Aug 2007) | 2 lines Don't read before the start of the string for an instance ........ r759 | nelhage | 2007-09-07 00:13:45 -0400 (Fri, 07 Sep 2007) | 3 lines Adding an explicit -f - to the tar commands for FreeBSD compatibility (reported by ecprice) ........ r760 | ecprice | 2007-09-08 17:33:34 -0400 (Sat, 08 Sep 2007) | 3 lines Fixes for FreeBSD. ........ r761 | nelhage | 2007-09-10 20:00:45 -0400 (Mon, 10 Sep 2007) | 3 lines Use "" instead of `undef' as a default for messages with no reply command to hopefully squelch perl warnings. ........ r762 | nelhage | 2007-09-12 21:37:41 -0400 (Wed, 12 Sep 2007) | 2 lines Do ~-expansion in :loadsubs. closes #26 ........ r763 | nelhage | 2007-09-12 21:54:51 -0400 (Wed, 12 Sep 2007) | 2 lines Validate JIDs passed to jmuc join. closes #25 ........ r764 | nelhage | 2007-09-12 22:46:17 -0400 (Wed, 12 Sep 2007) | 2 lines Show full JIDs for users in non-anonymous JIDs in :jmuc presence. closes #24 ........ r766 | nelhage | 2007-10-02 00:38:49 -0400 (Tue, 02 Oct 2007) | 3 lines Don't crash if we hit `i' on iso-8859-*. This is not the right solution, but at least it doesn't SEGV. ........ r767 | asedeno | 2007-10-10 15:21:13 -0400 (Wed, 10 Oct 2007) | 1 line Fixing a typo pointed out by kchen. ........ r768 | matt | 2007-10-14 17:16:35 -0400 (Sun, 14 Oct 2007) | 1 line added -m flag to aimwrite ........ r769 | austein | 2007-10-14 18:16:44 -0400 (Sun, 14 Oct 2007) | 1 line aimwrite -m displays according to displayoutgoing ........ r770 | asedeno | 2007-12-06 14:38:05 -0500 (Thu, 06 Dec 2007) | 3 lines Making usleep call more reasonable. Responsiveness seems okay on linerva, no-knife, and darkmatter, and reported good on zephyr. ........ r771 | nelhage | 2007-12-10 21:34:46 -0500 (Mon, 10 Dec 2007) | 2 lines Add zip as build-depends ........ r772 | nelhage | 2007-12-10 21:36:25 -0500 (Mon, 10 Dec 2007) | 2 lines We're not ktools ........ r773 | nelhage | 2007-12-23 11:32:02 -0500 (Sun, 23 Dec 2007) | 2 lines bind END in popless windows. closes #41 ........ r774 | chmrr | 2007-12-23 15:16:26 -0500 (Sun, 23 Dec 2007) | 3 lines r1805@utwig: chmrr | 2007-12-23 15:15:33 -0500 * Allow C-r on outgoing messages (useful for CCs) ........ r775 | chmrr | 2007-12-23 15:16:29 -0500 (Sun, 23 Dec 2007) | 3 lines r1806@utwig: chmrr | 2007-12-23 15:15:50 -0500 * Identify ourselves as barnowl in a couple more places ........
  • Property mode set to 100644
File size: 8.0 KB
Line 
1#include <string.h>
2#include <pwd.h>
3#include <sys/types.h>
4#include <unistd.h>
5#include "owl.h"
6
7static const char fileIdent[] = "$Id$";
8
9int owl_zwrite_create_from_line(owl_zwrite *z, char *line)
10{
11  int argc, badargs, myargc;
12  char **argv, **myargv;
13  char *zsigproc, *zsigowlvar, *zsigzvar, *ptr;
14  struct passwd *pw;
15
16  badargs=0;
17 
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;
25  z->cc=0;
26  z->noping=0;
27  owl_list_create(&(z->recips));
28
29  /* parse the command line for options */
30  argv=myargv=owl_parseline(line, &argc);
31  if (argc<0) {
32    owl_function_error("Unbalanced quotes in zwrite");
33    return(-1);
34  }
35  myargc=argc;
36  if (myargc && *(myargv[0])!='-') {
37    myargc--;
38    myargv++;
39  }
40  while (myargc) {
41    if (!strcmp(myargv[0], "-c")) {
42      if (myargc<2) {
43        badargs=1;
44        break;
45      }
46      z->class=owl_strdup(myargv[1]);
47      myargv+=2;
48      myargc-=2;
49    } else if (!strcmp(myargv[0], "-i")) {
50      if (myargc<2) {
51        badargs=1;
52        break;
53      }
54      z->inst=owl_strdup(myargv[1]);
55      myargv+=2;
56      myargc-=2;
57    } else if (!strcmp(myargv[0], "-r")) {
58      if (myargc<2) {
59        badargs=1;
60        break;
61      }
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      myargv+=2;
72      myargc-=2;
73    } else if (!strcmp(myargv[0], "-O")) {
74      if (myargc<2) {
75        badargs=1;
76        break;
77      }
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 or a class or an instance*/
87      if (owl_list_get_size(&(z->recips))<1 && (!z->class) && (!z->inst)) {
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=owl_realloc(z->message, strlen(z->message)+strlen(myargv[0])+5);
98        strcat(z->message, myargv[0]);
99        strcat(z->message, " ");
100        myargc--;
101        myargv++;
102      }
103      z->message[strlen(z->message)-1]='\0'; /* remove last space */
104      break;
105    } else if (!strcmp(myargv[0], "-C")) {
106      z->cc=1;
107      myargv++;
108      myargc--;
109    } else if (!strcmp(myargv[0], "-n")) {
110      z->noping=1;
111      myargv++;
112      myargc--;
113    } else {
114      /* anything unattached is a recipient */
115      owl_list_append_element(&(z->recips), owl_strdup(myargv[0]));
116      myargv++;
117      myargc--;
118    }
119  }
120
121  owl_parsefree(argv, argc);
122
123  if (badargs) {
124    return(-1);
125  }
126
127  if (z->class == NULL &&
128      z->inst == NULL &&
129      owl_list_get_size(&(z->recips))==0) {
130    owl_function_error("You must specify a recipient for zwrite");
131    return(-1);
132  }
133
134  /* now deal with defaults */
135  if (z->class==NULL) z->class=owl_strdup("message");
136  if (z->inst==NULL) z->inst=owl_strdup("personal");
137  if (z->realm==NULL) z->realm=owl_strdup("");
138  if (z->opcode==NULL) z->opcode=owl_strdup("");
139  /* z->message is allowed to stay NULL */
140 
141  /* get a zsig, if not given */
142  if (z->zsig==NULL) {
143    zsigproc = owl_global_get_zsigproc(&g);
144    zsigowlvar = owl_global_get_zsig(&g);
145    zsigzvar = owl_zephyr_get_variable("zwrite-signature");
146
147    if (zsigowlvar && *zsigowlvar) {
148      z->zsig=owl_strdup(zsigowlvar);
149    } else if (zsigproc && *zsigproc) {
150      FILE *file;
151      char buff[LINE], *openline;
152     
153      /* simple hack for now to nuke stderr */
154      openline=owl_malloc(strlen(zsigproc)+40);
155      strcpy(openline, zsigproc);
156#if !(OWL_STDERR_REDIR)
157      strcat(openline, " 2> /dev/null");
158#endif
159      file=popen(openline, "r");
160      owl_free(openline);
161      if (!file) {
162        if (zsigzvar && *zsigzvar) {
163          z->zsig=owl_strdup(zsigzvar);
164        }
165      } else {
166        z->zsig=owl_malloc(LINE*5);
167        strcpy(z->zsig, "");
168        while (fgets(buff, LINE, file)) { /* wrong sizing */
169          strcat(z->zsig, buff);
170        }
171        pclose(file);
172        if (z->zsig[strlen(z->zsig)-1]=='\n') {
173          z->zsig[strlen(z->zsig)-1]='\0';
174        }
175      }
176    } else if (zsigzvar) {
177      z->zsig=owl_strdup(zsigzvar);
178    } else if (((pw=getpwuid(getuid()))!=NULL) && (pw->pw_gecos)) {
179      z->zsig=owl_strdup(pw->pw_gecos);
180      ptr=strchr(z->zsig, ',');
181      if (ptr) {
182        ptr[0]='\0';
183      }
184    }
185  }
186
187  return(0);
188}
189
190void owl_zwrite_send_ping(owl_zwrite *z)
191{
192  int i, j;
193  char to[LINE];
194
195  if (z->noping) return;
196 
197  if (strcasecmp(z->class, "message") ||
198      strcasecmp(z->inst, "personal")) {
199    return;
200  }
201
202  /* if there are no recipients we won't send a ping, which
203     is what we want */
204  j=owl_list_get_size(&(z->recips));
205  for (i=0; i<j; i++) {
206    if (strcmp(z->realm, "")) {
207      sprintf(to, "%s@%s", (char *) owl_list_get_element(&(z->recips), i), z->realm);
208    } else {
209      strcpy(to, owl_list_get_element(&(z->recips), i));
210    }
211    send_ping(to);
212  }
213
214}
215
216void owl_zwrite_set_message(owl_zwrite *z, char *msg)
217{
218  int i, j;
219  char toline[LINE];
220
221  if (z->message) owl_free(z->message);
222
223  j=owl_list_get_size(&(z->recips));
224  if (j>0 && z->cc) {
225    strcpy(toline, "CC: ");
226    for (i=0; i<j; i++) {
227      if (strcmp(z->realm, "")) {
228        sprintf(toline, "%s%s@%s ", toline, (char *) owl_list_get_element(&(z->recips), i), z->realm);
229      } else {
230        sprintf(toline, "%s%s ", toline, (char *) owl_list_get_element(&(z->recips), i));
231      }
232    }
233    z->message=owl_sprintf("%s\n%s", toline, msg);
234  } else {
235    z->message=owl_strdup(msg);
236  }
237}
238
239char *owl_zwrite_get_message(owl_zwrite *z)
240{
241  if (z->message) return(z->message);
242  return("");
243}
244
245int owl_zwrite_is_message_set(owl_zwrite *z)
246{
247  if (z->message) return(1);
248  return(0);
249}
250
251int owl_zwrite_send_message(owl_zwrite *z)
252{
253  int i, j;
254  char to[LINE];
255
256  if (z->message==NULL) return(-1);
257
258  j=owl_list_get_size(&(z->recips));
259  if (j>0) {
260    for (i=0; i<j; i++) {
261      if (strcmp(z->realm, "")) {
262        sprintf(to, "%s@%s", (char *) owl_list_get_element(&(z->recips), i), z->realm);
263      } else {
264        strcpy(to, owl_list_get_element(&(z->recips), i));
265      }
266      send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, z->message);
267    }
268  } else {
269    sprintf(to, "@%s", z->realm);
270    send_zephyr(z->opcode, z->zsig, z->class, z->inst, to, z->message);
271  }
272  return(0);
273}
274
275int owl_zwrite_create_and_send_from_line(char *cmd, char *msg)
276{
277  owl_zwrite z;
278  int rv;
279  rv=owl_zwrite_create_from_line(&z, cmd);
280  if (rv) return(rv);
281  if (!owl_zwrite_is_message_set(&z)) {
282    owl_zwrite_set_message(&z, msg);
283  }
284  owl_zwrite_send_message(&z);
285  owl_zwrite_free(&z);
286  return(0);
287}
288
289char *owl_zwrite_get_class(owl_zwrite *z)
290{
291  return(z->class);
292}
293
294char *owl_zwrite_get_instance(owl_zwrite *z)
295{
296  return(z->inst);
297}
298
299char *owl_zwrite_get_opcode(owl_zwrite *z)
300{
301  return(z->opcode);
302}
303
304void owl_zwrite_set_opcode(owl_zwrite *z, char *opcode)
305{
306  if (z->opcode) owl_free(z->opcode);
307  z->opcode=owl_strdup(opcode);
308}
309
310char *owl_zwrite_get_realm(owl_zwrite *z)
311{
312  return(z->realm);
313}
314
315char *owl_zwrite_get_zsig(owl_zwrite *z)
316{
317  if (z->zsig) return(z->zsig);
318  return("");
319}
320
321void owl_zwrite_get_recipstr(owl_zwrite *z, char *buff)
322{
323  int i, j;
324
325  strcpy(buff, "");
326  j=owl_list_get_size(&(z->recips));
327  for (i=0; i<j; i++) {
328    strcat(buff, owl_list_get_element(&(z->recips), i));
329    strcat(buff, " ");
330  }
331  buff[strlen(buff)-1]='\0';
332}
333
334int owl_zwrite_get_numrecips(owl_zwrite *z)
335{
336  return(owl_list_get_size(&(z->recips)));
337}
338
339char *owl_zwrite_get_recip_n(owl_zwrite *z, int n)
340{
341  return(owl_list_get_element(&(z->recips), n));
342}
343
344int owl_zwrite_is_personal(owl_zwrite *z)
345{
346  /* return true if at least one of the recipients is personal */
347  int i, j;
348  char *foo;
349
350  j=owl_list_get_size(&(z->recips));
351  for (i=0; i<j; i++) {
352    foo=owl_list_get_element(&(z->recips), i);
353    if (foo[0]!='@') return(1);
354  }
355  return(0);
356}
357 
358void owl_zwrite_free(owl_zwrite *z)
359{
360  owl_list_free_all(&(z->recips), &owl_free);
361  if (z->class) owl_free(z->class);
362  if (z->inst) owl_free(z->inst);
363  if (z->opcode) owl_free(z->opcode);
364  if (z->realm) owl_free(z->realm);
365  if (z->message) owl_free(z->message);
366  if (z->zsig) owl_free(z->zsig);
367}
Note: See TracBrowser for help on using the repository browser.