Пример #1
0
static void event_text(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
	char *line, *str;

	g_return_if_fail(data != NULL);
	if (item == NULL) return;

	line = settings_get_bool("expand_escapes") ?
		expand_escapes(data, server, item) : g_strdup(data);

	/* check for automatic nick completion */
	if (completion_auto && IS_CHANNEL(item)) {
		str = auto_complete(CHANNEL(item), line);
		if (str != NULL) {
			g_free(line);
                        line = str;
		}
	}

	str = g_strdup_printf(IS_CHANNEL(item) ? "-channel %s %s" :
			      IS_QUERY(item) ? "-nick %s %s" : "%s %s",
			      item->name, line);

	signal_emit("command msg", 3, str, server, item);

	g_free(str);
	g_free(line);

	signal_stop();
}
Пример #2
0
int generate_event(char *buffer, size_t buffer_size, const char *host_name, char *service_name,
                   char *state, const char *output, char *long_output, char *tags,
                   long initial_failure_delay, long repeat_failure_delay,
                   long initial_recovery_delay, double event_time) {

    char *escaped_host_name    = expand_escapes(host_name);
    char *escaped_service_name = expand_escapes(service_name);
    char *escaped_state        = expand_escapes(state);
    char *escaped_output       = expand_escapes(output);
    char *escaped_long_output  = expand_escapes(long_output);

    int written = snprintf(buffer, buffer_size,
                            "{"
                                "\"entity\":\"%s\","                   // HOSTNAME
                                "\"check\":\"%s\","                    // SERVICENAME
                                "\"type\":\"service\","                // type
                                "\"state\":\"%s\","                    // HOSTSTATE
                                "\"summary\":\"%s\","                  // HOSTOUTPUT
                                "\"details\":\"%s\","                  // HOSTlongoutput
                                "\"tags\":[%s],"                       // tags
                                "\"initial_failure_delay\":%lu,"       // initial_failure_delay
                                "\"repeat_failure_delay\":%lu,"        // repeat_failure_delay
                                //"\"initial_recovery_delay\":%lu,"      // initial_recovery_delay
                                "\"time\":%.0f"                        // TIMET
                            "}",
                                escaped_host_name,
                                escaped_service_name,
                                escaped_state,
                                escaped_output,
                                escaped_long_output,
                                tags,
                                initial_failure_delay,
                                repeat_failure_delay,
                                //initial_recovery_delay,
                                event_time);

    sfree(escaped_host_name);
    sfree(escaped_service_name);
    sfree(escaped_state);
    sfree(escaped_output);
    sfree(escaped_long_output);

    return(written);
}
Пример #3
0
static void event_text(gchar *line, IRC_SERVER_REC *server, WI_IRC_REC *item)
{
    CHANNEL_REC *channel;
    GList *comp;
    gchar *str, *ptr;

    g_return_if_fail(line != NULL);

    if (!irc_item_check(item))
	    return;

    /* FIXME: this really should go to fe-common/core. */
    line = settings_get_bool("expand_escapes") ?
	    expand_escapes(line, server, item) : g_strdup(line);

    /* check for nick completion */
    if (!settings_get_bool("completion_auto") ||
	*settings_get_str("completion_char") == '\0')
    {
	ptr = NULL;
	comp = NULL;
    }
    else
    {
	ptr = strchr(line, *settings_get_str("completion_char"));
	if (ptr != NULL) *ptr++ = '\0';

	channel = irc_item_channel(item);

	comp = ptr == NULL || channel == NULL ||
	    nicklist_find(channel, line) != NULL ? NULL :
	    completion_channel_nicks(channel, line, NULL);
    }

    /* message to channel */
    if (ptr == NULL)
        str = g_strdup_printf("%s %s", item->name, line);
    else
    {
        str = g_strdup_printf("%s %s%s%s", item->name,
                              comp != NULL ? (gchar *) comp->data : line,
                              settings_get_str("completion_char"), ptr);
    }
    signal_emit("command msg", 3, str, server, item);

    g_free(str);
    g_free(line);

    if (comp != NULL)
    {
        g_list_foreach(comp, (GFunc) g_free, NULL);
        g_list_free(comp);
    }

    signal_stop();
}
Пример #4
0
static void event_text(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
	CHANNEL_REC *channel;
	GList *comp;
	char *line, *str, *ptr, comp_char;

	g_return_if_fail(data != NULL);
	if (item == NULL) return;

	line = settings_get_bool("expand_escapes") ?
		expand_escapes(data, server, item) : g_strdup(data);
	comp_char = *settings_get_str("completion_char");

	/* check for automatic nick completion */
        ptr = NULL;
	comp = NULL;
	channel = CHANNEL(item);

	if (channel != NULL && comp_char != '\0' &&
	    settings_get_bool("completion_auto")) {
		ptr = strchr(line, comp_char);
		if (ptr != NULL) {
			*ptr++ = '\0';
			if (nicklist_find(channel, line) == NULL) {
				comp = completion_channel_nicks(channel,
								line, NULL);
			}
		}
	}

	str = g_strdup_printf(ptr == NULL ? "%s %s" : "%s %s%c%s", item->name,
			      comp != NULL ? (char *) comp->data : line,
			      comp_char, ptr);
	signal_emit("command msg", 3, str, server, item);

	g_free(str);
	g_free(line);

	if (comp != NULL) {
		g_list_foreach(comp, (GFunc) g_free, NULL);
		g_list_free(comp);
	}

	signal_stop();
}
Пример #5
0
static void event_text(const char *data, SERVER_REC *server, WI_ITEM_REC *item)
{
	char *line, *str, *target;

	g_return_if_fail(data != NULL);

	if (item == NULL)
		return;

	if (*data == '\0') {
		/* empty line, forget it. */
                signal_stop();
		return;
	}

	line = settings_get_bool("expand_escapes") ?
		expand_escapes(data, server, item) : g_strdup(data);

	/* check for automatic nick completion */
	if (completion_auto && IS_CHANNEL(item)) {
		str = auto_complete(CHANNEL(item), line);
		if (str != NULL) {
			g_free(line);
                        line = str;
		}
	}

	/* the nick is quoted in case it contains '-' character. also
	   spaces should work too now :) The nick is also escaped in case
	   it contains '\' characters */
	target = escape_string(window_item_get_target(item));
	str = g_strdup_printf(IS_CHANNEL(item) ? "-channel \"%s\" %s" :
			      IS_QUERY(item) ? "-nick \"%s\" %s" : "%s %s",
			      target, line);
	g_free(target);

	signal_emit("command msg", 3, str, server, item);

	g_free(str);
	g_free(line);

	signal_stop();
}
Пример #6
0
yylex(){
int nstr; extern int yyprevious;
#ifdef __cplusplus
/* to avoid CC and lint complaining yyfussy not being used ...*/
static int __lex_hack = 0;
if (__lex_hack) goto yyfussy;
#endif
while((nstr = yylook()) >= 0)
yyfussy: switch(nstr){
case 0:
if(yywrap()) return(0); break;
case 1:

# line 30 "ncgen.l"
	/* comment */ ;
break;
case 2:

# line 32 "ncgen.l"
	{
			 if(yyleng > MAXTRST) {
				yyerror("string too long, truncated\n");
			        yytext[MAXTRST-1] = '\0';
			 }
			 expand_escapes(termstring,yytext,yyleng);
		 	 return (TERMSTRING);
		        }
break;
case 3:

# line 41 "ncgen.l"
{return (FLOAT_K);}
break;
case 4:

# line 42 "ncgen.l"
	{return (CHAR_K);}
break;
case 5:

# line 43 "ncgen.l"
	{return (BYTE_K);}
break;
case 6:

# line 44 "ncgen.l"
	{return (SHORT_K);}
break;
case 7:

# line 45 "ncgen.l"
{return (LONG_K);}
break;
case 8:

# line 46 "ncgen.l"
	{return (DOUBLE_K);}
break;
case 9:

# line 47 "ncgen.l"
{long_val = -1;
			 return (NC_UNLIMITED_K);}
break;
case 10:

# line 50 "ncgen.l"
{return (DIMENSIONS);}
break;
case 11:

# line 51 "ncgen.l"
{return (VARIABLES);}
break;
case 12:

# line 52 "ncgen.l"
	{return (DATA);}
break;
case 13:

# line 53 "ncgen.l"
{
		char *s = (char*)yytext+strlen("netcdf");
		char *t = (char*)yytext+yyleng-1;
		while (isspace(*s))
			s++;
		while (isspace(*t))
			t--;
		t++;
		netcdfname = (char *) emalloc(t-s+1);
		(void) strncpy(netcdfname, s, t-s);
		netcdfname[t-s] = '\0';
		return (NETCDF);
		}
break;
case 14:

# line 66 "ncgen.l"
{    /* missing value (pre-2.4 backward compatibility) */
		double_val = FILL_DOUBLE;  /* IEEE double infinity */
		return (DOUBLE_CONST);
		}
break;
case 15:

# line 70 "ncgen.l"
{ /* missing value (pre-2.4 backward compatibility) */
		float_val = FILL_FLOAT;  /* IEEE float infinity */
		return (FLOAT_CONST);
		}
break;
case 16:

# line 74 "ncgen.l"
{
                if (STREQ((char *)yytext, FILL_STRING))
		        return (FILLVALUE);
		if ((yylval = lookup(yytext)) == NULL) {
			yylval = install(yytext);
			}
		return (IDENT);
		}
break;
case 17:

# line 83 "ncgen.l"
	{
		lineno++ ;
		}
break;
case 18:

# line 86 "ncgen.l"
{
		if (sscanf((char*)yytext, "%le", &double_val) != 1) {
		    sprintf(errstr,"bad long or double constant: %s",(char*)yytext);
		    yyerror(errstr);
		}
                return (DOUBLE_CONST);
                }
break;
case 19:

# line 93 "ncgen.l"
{
		if (sscanf((char*)yytext, "%e", &float_val) != 1) {
		    sprintf(errstr,"bad float constant: %s",(char*)yytext);
		    yyerror(errstr);
		}
                return (FLOAT_CONST);
                }
break;
case 20:

# line 100 "ncgen.l"
{
		if (sscanf((char*)yytext, "%hd", &short_val) != 1) {
		    sprintf(errstr,"bad short constant: %s",(char*)yytext);
		    yyerror(errstr);
		}
		return (SHORT_CONST);
	        }
break;
case 21:

# line 107 "ncgen.l"
{
#ifdef cray	/* machines where longs have more precision than doubles. */
    		char *ptr;
		long_val = strtol((char*)yytext, &ptr, 0);
		if (ptr == (char*)yytext) {
		    sprintf(errstr,"bad long constant: %s",(char*)yytext);
		    yyerror(errstr);
		}
		return (LONG_CONST);
#else		/* machines where doubles have more precision than longs. */
		/*
		 * Because strtol and sscanf with "%ld" may silently give
		 * bad results from undetected overflow for strings like
		 * "30000000000", we scan as double first.
		 */
		double dd;
#ifdef VMS  /* work around bug in VMS strtol() */
		if (STREQ((char*)yytext, "-2147483648")) {
		    long_val = -2147483648;
		    return (LONG_CONST);
		}
#endif /* VMS */
		if (sscanf((char*)yytext, "%le", &dd) != 1) {
		    sprintf(errstr,"bad long constant: %s",(char*)yytext);
		    yyerror(errstr);
		}
		if (dd < LONG_MIN  ||  dd > LONG_MAX) {
		    double_val = dd;
		    return DOUBLE_CONST;
		} else {
		    long_val = dd;
		    return LONG_CONST;
		}
#endif /* cray */
	        }
break;
case 22:

# line 142 "ncgen.l"
{
		long dd;
#ifdef VMS  /* work around bug in VMS strtol() */
		if (STREQ((char*)yytext, "-2147483648")) {
		    long_val = -2147483648;
		    return (LONG_CONST);
		}
#endif /* VMS */
		if (sscanf((char*)yytext, "%li", &dd) != 1) {
		    sprintf(errstr,"bad long constant: %s",(char*)yytext);
		    yyerror(errstr);
		}
		long_val = dd;
		return LONG_CONST;
	        }
break;
case 23:

# line 157 "ncgen.l"
         {
	        (void) sscanf((char*)&yytext[1],"%c",&byte_val);
		return (BYTE_CONST);
                }
break;
case 24:

# line 161 "ncgen.l"
 {
		byte_val = strtol((char*)&yytext[2], (char **) 0, 8);
		return (BYTE_CONST);
                }
break;
case 25:

# line 165 "ncgen.l"
 {
		byte_val = strtol((char*)&yytext[3], (char **) 0, 16);
		return (BYTE_CONST);
                }
break;
case 26:

# line 169 "ncgen.l"
       {
	       switch ((char)yytext[2]) {
	          case 'a': byte_val = '\007'; break; /* not everyone under-
						       * stands '\a' yet */
     	          case 'b': byte_val = '\b'; break;
		  case 'f': byte_val = '\f'; break;
		  case 'n': byte_val = '\n'; break;
		  case 'r': byte_val = '\r'; break;
		  case 't': byte_val = '\t'; break;
		  case 'v': byte_val = '\v'; break;
		  case '\\': byte_val = '\\'; break;
		  case '?': byte_val = '\177'; break;
		  case '\'': byte_val = '\''; break;
		  default: byte_val = (char)yytext[2];
	           }
		return (BYTE_CONST);
                }
break;
case 27:

# line 187 "ncgen.l"
{/* whitespace */ ;
		}
break;
case 28:

# line 189 "ncgen.l"
	return (yytext[0]) ;
break;
case -1:
break;
default:
(void)fprintf(yyout,"bad switch yylook %d",nstr);
} return(0); }