comparison libpurple/protocols/zephyr/ZLocations.c @ 18148:f160b6e84d0c

Use dynamicly allocated string manipulation here as well to avoid a MAXPATHLEN. This is untested, as I don't use Zephyr. This also leaks a string at libpurple uninit. If that's bad, I can add a callback to this file and call it from the prpl's unload callback. References #1635
author Richard Laager <rlaager@wiktel.com>
date Sun, 17 Jun 2007 03:00:15 +0000
parents 32c366eeeb99
children a8cc50c2279f
comparison
equal deleted inserted replaced
18147:5653692dcf79 18148:f160b6e84d0c
34 Code_t ZFlushMyLocations() 34 Code_t ZFlushMyLocations()
35 { 35 {
36 return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, "")); 36 return (Z_SendLocation(LOGIN_CLASS, LOGIN_USER_FLUSH, ZAUTH, ""));
37 } 37 }
38 38
39 static char host[MAXHOSTNAMELEN], mytty[MAXPATHLEN]; 39 static char host[MAXHOSTNAMELEN];
40 static char *mytty = NULL;
40 static int reenter = 0; 41 static int reenter = 0;
41 42
42 Code_t Z_SendLocation(class, opcode, auth, format) 43 Code_t Z_SendLocation(class, opcode, auth, format)
43 char *class; 44 char *class;
44 char *opcode; 45 char *opcode;
85 (void) strncpy(host, hent->h_name, sizeof(host)); 86 (void) strncpy(host, hent->h_name, sizeof(host));
86 host[sizeof(host) - 1] = '\0'; 87 host[sizeof(host) - 1] = '\0';
87 } 88 }
88 #ifndef X_DISPLAY_MISSING 89 #ifndef X_DISPLAY_MISSING
89 if ((display = getenv("DISPLAY")) && *display) { 90 if ((display = getenv("DISPLAY")) && *display) {
90 (void) strncpy(mytty, display, sizeof(mytty)); 91 mytty = g_strdup(display);
91 } else { 92 } else {
92 #endif 93 #endif
93 #ifdef WIN32 94 #ifdef WIN32
94 strncpy(mytty, "WinPurple", sizeof(mytty)); 95 mytty = g_strdup("WinPurple");
95 #else 96 #else
96 ttyp = ttyname(0); 97 ttyp = ttyname(0);
97 if (ttyp && *ttyp) { 98 if (ttyp && *ttyp) {
98 p = strchr(ttyp + 1, '/'); 99 p = strchr(ttyp + 1, '/');
99 strcpy(mytty, (p) ? p + 1 : ttyp); 100 mytty = g_strdup((p) ? p + 1 : ttyp);
100 } else { 101 } else {
101 strncpy(mytty, "unknown", sizeof(mytty)); 102 mytty = g_strdup("unknown");
102 } 103 }
103 #endif 104 #endif
104 mytty[sizeof(mytty)-1] = '\0';
105 #ifndef X_DISPLAY_MISSING 105 #ifndef X_DISPLAY_MISSING
106 } 106 }
107 #endif 107 #endif
108 reenter = 1; 108 reenter = 1;
109 } 109 }
112 bptr[0] = host; 112 bptr[0] = host;
113 bptr[1] = ctime(&ourtime); 113 bptr[1] = ctime(&ourtime);
114 bptr[1][strlen(bptr[1])-1] = '\0'; 114 bptr[1][strlen(bptr[1])-1] = '\0';
115 bptr[2] = mytty; 115 bptr[2] = mytty;
116 116
117
118 if ((retval = ZSendList(&notice, bptr, 3, auth)) != ZERR_NONE) 117 if ((retval = ZSendList(&notice, bptr, 3, auth)) != ZERR_NONE)
119 return (retval); 118 return (retval);
120 119
121 retval = Z_WaitForNotice (&retnotice, ZCompareUIDPred, &notice.z_uid, 120 retval = Z_WaitForNotice (&retnotice, ZCompareUIDPred, &notice.z_uid,
122 SRV_TIMEOUT); 121 SRV_TIMEOUT);