xymon

Check-in [7cb3c7331d]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:html-encode msgs/procs status messages git-svn-id: http://svn.code.sf.net/p/xymon/code/branches/4.3.19@7600 44351d6e-118b-4698-b696-ce33095ecaa4
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | origin/4.3.19
Files: files | file ages | folders
SHA3-256: 7cb3c7331ded741af279112612009853a8070755745ec4b2f4e0750dfd92d25b
User & Date: jccleaver@users.sf.net 2015-03-15 17:55:51
Context
2015-03-15
18:36
msgs/html pre-tag fixes, pt.2 git-svn-id: http://svn.code.sf.net/p/xymon/code/branches/4.3.19@7601 44351d6e-118b-4698-b696-ce33095ecaa4 check-in: 615c833eb0 user: jccleaver@users.sf.net tags: trunk, origin/4.3.19
17:55
html-encode msgs/procs status messages git-svn-id: http://svn.code.sf.net/p/xymon/code/branches/4.3.19@7600 44351d6e-118b-4698-b696-ce33095ecaa4 check-in: 7cb3c7331d user: jccleaver@users.sf.net tags: trunk, origin/4.3.19
2015-03-13
07:07
null ptr fix for non-GNU printf, thanks Jeremy Laidman git-svn-id: http://svn.code.sf.net/p/xymon/code/branches/4.3.19@7599 44351d6e-118b-4698-b696-ce33095ecaa4 check-in: cc3d3801ce user: jccleaver@users.sf.net tags: trunk, origin/4.3.19
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to lib/strfunc.c.

222
223
224
225
226
227
228


































229
230
231
232
233
234
235
		switch (c) {
		  case '"': addtobuffer(result, """); break;
		  case '&': addtobuffer(result, "&"); break;
		  case '<': addtobuffer(result, "&lt;"); break;
		  case '>': addtobuffer(result, "&gt;"); break;
		  case ' ': addtobuffer(result, "&nbsp;"); break;
		  default: break;


































		}
		inp = (c == '\0') ? NULL : endp+1;
	} while (inp);

	return STRBUF(result);
}








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
		switch (c) {
		  case '"': addtobuffer(result, "&quot;"); break;
		  case '&': addtobuffer(result, "&amp;"); break;
		  case '<': addtobuffer(result, "&lt;"); break;
		  case '>': addtobuffer(result, "&gt;"); break;
		  case ' ': addtobuffer(result, "&nbsp;"); break;
		  default: break;
		}
		inp = (c == '\0') ? NULL : endp+1;
	} while (inp);

	return STRBUF(result);
}

char *prehtmlquoted(char *s)
{
	/*
	 * This routine converts a string which may contain html to a string
	 * safe to include in a PRE block. It's similar to above, but escapes
	 * only the minmum characters for efficiency.
	 */

	static strbuffer_t *result = NULL;
	char *inp, *endp;
	char c;

	if (!s) return NULL;

	if (!result) result = newstrbuffer(4096);
	clearstrbuffer(result);

	inp = s;
	do {
		endp = inp + strcspn(inp, "&<>");
		c = *endp;
		if (endp > inp) addtobufferraw(result, inp, endp-inp);
		switch (c) {
		  case '&': addtobuffer(result, "&amp;"); break;
		  case '<': addtobuffer(result, "&lt;"); break;
		  case '>': addtobuffer(result, "&gt;"); break;	// this is not, strictly speaking, needed, but unbalanced encoding might confuse automated readers
		  default: break;
		}
		inp = (c == '\0') ? NULL : endp+1;
	} while (inp);

	return STRBUF(result);
}

Changes to lib/strfunc.h.

22
23
24
25
26
27
28

29
30
31
32
extern char *grabstrbuffer(strbuffer_t *buf);
extern strbuffer_t *dupstrbuffer(char *src);
extern void strbufferchop(strbuffer_t *buf, int count);
extern void strbufferrecalc(strbuffer_t *buf);
extern void strbuffergrow(strbuffer_t *buf, int bytes);
extern void strbufferuse(strbuffer_t *buf, int bytes);
extern char *htmlquoted(char *s);

extern strbuffer_t *replacetext(char *original, char *oldtext, char *newtext);

#endif








>




22
23
24
25
26
27
28
29
30
31
32
33
extern char *grabstrbuffer(strbuffer_t *buf);
extern strbuffer_t *dupstrbuffer(char *src);
extern void strbufferchop(strbuffer_t *buf, int count);
extern void strbufferrecalc(strbuffer_t *buf);
extern void strbuffergrow(strbuffer_t *buf, int bytes);
extern void strbufferuse(strbuffer_t *buf, int bytes);
extern char *htmlquoted(char *s);
extern char *prehtmlquoted(char *s);
extern strbuffer_t *replacetext(char *original, char *oldtext, char *newtext);

#endif

Changes to xymond/xymond_client.c.

1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
....
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
	/* And add the info about what's wrong */
	if (STRBUFLEN(monmsg)) {
		addtostrstatus(monmsg);
		addtostatus("\n");
	}

	/* And the full ps output for those who want it */
	if (pslistinprocs) {
		/*
		 * NB: Process listings may contain HTML special characters.
		 *     We must encode these for HTML, cf.
		 *     http://www.w3.org/TR/html4/charset.html#h-5.3.2
		 */
		char *inp, *tagpos;

		inp = psstr;
		do {
			tagpos = inp + strcspn(inp, "<>&\"");
			switch (*tagpos) {
			  case '<':
				*tagpos = '\0'; addtostatus(inp); addtostatus("&lt;"); *tagpos = '<';
				inp = tagpos + 1;
				break;
			  case '>':
				*tagpos = '\0'; addtostatus(inp); addtostatus("&gt;"); *tagpos = '>';
				inp = tagpos + 1;
				break;
			  case '&':
				*tagpos = '\0'; addtostatus(inp); addtostatus("&amp;"); *tagpos = '&';
				inp = tagpos + 1;
				break;
			  case '\"':
				*tagpos = '\0'; addtostatus(inp); addtostatus("&quot;"); *tagpos = '\"';
				inp = tagpos + 1;
				break;
			  default:
				/* We're done */
				addtostatus(inp); inp = NULL;
				break;
			}
		} while (inp && *inp);
	}

	if (fromline && !localmode) addtostatus(fromline);
	finish_status();

	freestrbuffer(monmsg);

	if (anycountdata) combo_add(countdata);
................................................................................
		}
		else {
			sprintf(msgline, "\nFull log %s\n", 
				swalk->sname+5);
		}
		addtostatus(msgline);
		addtobuffer(yellowdata, "<pre>\n");
		addtostatus(swalk->sdata);
		addtobuffer(yellowdata, "</pre>\n");
		do { swalk=swalk->next; } while (swalk && strncmp(swalk->sname, "msgs:", 5));
	}

	if (fromline && !localmode) addtostatus(fromline);

	finish_status();







|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|







1146
1147
1148
1149
1150
1151
1152
1153


































1154
1155
1156
1157
1158
1159
1160
....
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
	/* And add the info about what's wrong */
	if (STRBUFLEN(monmsg)) {
		addtostrstatus(monmsg);
		addtostatus("\n");
	}

	/* And the full ps output for those who want it */
	if (pslistinprocs) addtostatus(prehtmlquoted(psstr));



































	if (fromline && !localmode) addtostatus(fromline);
	finish_status();

	freestrbuffer(monmsg);

	if (anycountdata) combo_add(countdata);
................................................................................
		}
		else {
			sprintf(msgline, "\nFull log %s\n", 
				swalk->sname+5);
		}
		addtostatus(msgline);
		addtobuffer(yellowdata, "<pre>\n");
		addtostatus(prehtmlquoted(swalk->sdata));
		addtobuffer(yellowdata, "</pre>\n");
		do { swalk=swalk->next; } while (swalk && strncmp(swalk->sname, "msgs:", 5));
	}

	if (fromline && !localmode) addtostatus(fromline);

	finish_status();