Example #1
0
static void format(char *buf, const char *fmt)
{
    time_t t;
    struct tm tm;
    char *p, prefix[1024];
	
    p = prefix;

    if (markers) {
        time(&t);
        if (use_localtime)
            tm = gw_localtime(t);
        else
            tm = gw_gmtime(t);

        sprintf(p, "%04d-%02d-%02d %02d:%02d:%02d ",
                tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
                tm.tm_hour, tm.tm_min, tm.tm_sec);
    } else {
        *p = '\0';
    }

    if (strlen(prefix) + strlen(fmt) > FORMAT_SIZE / 2) {
        sprintf(buf, "%s <OUTPUT message too long>\n", prefix);
        return;
    }
    sprintf(buf, "%s%s\n", prefix, fmt);
}
Example #2
0
File: log.c Project: frese/mbuni
static void format(char *buf, int level, const char *place, int e,
		   const char *fmt, int with_timestamp)
{
    static char *tab[] = {
	"DEBUG: ",
	"INFO: ",
	"WARNING: ",
	"ERROR: ",
	"PANIC: ",
	"LOG: "
    };
    static int tab_size = sizeof(tab) / sizeof(tab[0]);
    time_t t;
    struct tm tm;
    char *p, prefix[1024];
    long tid, pid;
    
    p = prefix;

    if (with_timestamp) {
        time(&t);
#if LOG_TIMESTAMP_LOCALTIME
        tm = gw_localtime(t);
#else
        tm = gw_gmtime(t);
#endif
        sprintf(p, "%04d-%02d-%02d %02d:%02d:%02d ",
        tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
        tm.tm_hour, tm.tm_min, tm.tm_sec);
    
        p = strchr(p, '\0');
    }

    gwthread_self_ids(&tid, &pid);
    sprintf(p, "[%ld] [%ld] ", pid, tid);
    
    p = strchr(p, '\0');
    if (level < 0 || level >= tab_size)
	sprintf(p, "UNKNOWN: ");
    else
	sprintf(p, "%s", tab[level]);

    p = strchr(p, '\0');
    if (place != NULL && *place != '\0')
	sprintf(p, "%s: ", place);
    
    if (strlen(prefix) + strlen(fmt) > FORMAT_SIZE / 2) {
	sprintf(buf, "%s <OUTPUT message too long>\n", prefix);
	return;
    }
    
    if (e == 0)
	sprintf(buf, "%s%s\n", prefix, fmt);
    else
	sprintf(buf, "%s%s\n%sSystem error %d: %s\n",
		prefix, fmt, prefix, e, strerror(e));
}
Example #3
0
static void status_cb(const Octstr *filename, void *d)
{
    struct status *data = d;
    struct tm tm;
    char id[UUID_STR_LEN + 1];
    Octstr *msg_s;
    Msg *msg;

    msg_s = octstr_read_file(octstr_get_cstr(filename));
    msg = store_msg_unpack(msg_s);
    octstr_destroy(msg_s);
    if (msg == NULL)
        return;

    /* transform the time value */
#if LOG_TIMESTAMP_LOCALTIME
    tm = gw_localtime(msg->sms.time);
#else
    tm = gw_gmtime(msg->sms.time);
#endif
    if (msg->sms.udhdata)
        octstr_binary_to_hex(msg->sms.udhdata, 1);
    if (msg->sms.msgdata &&
        (msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2 ||
        (msg->sms.coding == DC_UNDEF && msg->sms.udhdata)))
        octstr_binary_to_hex(msg->sms.msgdata, 1);

    uuid_unparse(msg->sms.id, id);

    octstr_format_append(data->status, data->format,
        id,
        (msg->sms.sms_type == mo ? "MO" :
        msg->sms.sms_type == mt_push ? "MT-PUSH" :
        msg->sms.sms_type == mt_reply ? "MT-REPLY" :
        msg->sms.sms_type == report_mo ? "DLR-MO" :
        msg->sms.sms_type == report_mt ? "DLR-MT" : ""),
        tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
        tm.tm_hour, tm.tm_min, tm.tm_sec,
        (msg->sms.sender ? octstr_get_cstr(msg->sms.sender) : ""),
        (msg->sms.receiver ? octstr_get_cstr(msg->sms.receiver) : ""),
        (msg->sms.smsc_id ? octstr_get_cstr(msg->sms.smsc_id) : ""),
        (msg->sms.boxc_id ? octstr_get_cstr(msg->sms.boxc_id) : ""),
        (msg->sms.udhdata ? octstr_get_cstr(msg->sms.udhdata) : ""),
        (msg->sms.msgdata ? octstr_get_cstr(msg->sms.msgdata) : ""));

    msg_destroy(msg);
}
Example #4
0
static void status_cb(Msg *msg, void *d)
{
    struct status *data = d;
    struct tm tm;
    char id[UUID_STR_LEN + 1];

    if (msg == NULL)
        return;

    /* transform the time value */
#if LOG_TIMESTAMP_LOCALTIME
    tm = gw_localtime(msg->sms.time);
#else
    tm = gw_gmtime(msg->sms.time);
#endif

    uuid_unparse(msg->sms.id, id);

    octstr_format_append(data->status, data->format,
        id,
        (msg->sms.sms_type == mo ? "MO" :
        msg->sms.sms_type == mt_push ? "MT-PUSH" :
        msg->sms.sms_type == mt_reply ? "MT-REPLY" :
        msg->sms.sms_type == report_mo ? "DLR-MO" :
        msg->sms.sms_type == report_mt ? "DLR-MT" : ""),
        tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
        tm.tm_hour, tm.tm_min, tm.tm_sec,
        (msg->sms.sender ? octstr_get_cstr(msg->sms.sender) : ""),
        (msg->sms.receiver ? octstr_get_cstr(msg->sms.receiver) : ""),
        (msg->sms.smsc_id ? octstr_get_cstr(msg->sms.smsc_id) : ""),
        (msg->sms.boxc_id ? octstr_get_cstr(msg->sms.boxc_id) : ""),
        msg->sms.mclass, msg->sms.coding, msg->sms.mwi, msg->sms.compress,
        msg->sms.dlr_mask,
        (msg->sms.udhdata ? msg->sms.udhdata : octstr_imm("")),
        (msg->sms.msgdata ? msg->sms.msgdata : octstr_imm("")));
}
Example #5
0
static Octstr *store_file_status(int status_type)
{
    char *frmt;
    Octstr *ret, *key;
    unsigned long l;
    struct tm tm;
    Msg *msg;
    List *keys;
    char id[UUID_STR_LEN + 1];

    ret = octstr_create("");

    /* set the type based header */
    if (status_type == BBSTATUS_HTML) {
        octstr_append_cstr(ret, "<table border=1>\n"
            "<tr><td>SMS ID</td><td>Type</td><td>Time</td><td>Sender</td><td>Receiver</td>"
            "<td>SMSC ID</td><td>BOX ID</td><td>UDH</td><td>Message</td>"
            "</tr>\n");
    } else if (status_type == BBSTATUS_TEXT) {
        octstr_append_cstr(ret, "[SMS ID] [Type] [Time] [Sender] [Receiver] [SMSC ID] [BOX ID] [UDH] [Message]\n");
    }
   
    /* if there is no store-file, then don't loop in sms_store */
    if (filename == NULL)
        goto finish;

    keys = dict_keys(sms_dict);

    for (l = 0; l < gwlist_len(keys); l++) {
        key = gwlist_get(keys, l);
        msg = dict_get(sms_dict, key);
        if (msg == NULL)
            continue;

        if (msg_type(msg) == sms) {

            if (status_type == BBSTATUS_HTML) {
                frmt = "<tr><td>%s</td><td>%s</td>"
                       "<td>%04d-%02d-%02d %02d:%02d:%02d</td>"
                       "<td>%s</td><td>%s</td><td>%s</td>"
                       "<td>%s</td><td>%s</td><td>%s</td></tr>\n";
            } else if (status_type == BBSTATUS_XML) {
                frmt = "<message>\n\t<id>%s</id>\n\t<type>%s</type>\n\t"
                       "<time>%04d-%02d-%02d %02d:%02d:%02d</time>\n\t"
                       "<sender>%s</sender>\n\t"
                       "<receiver>%s</receiver>\n\t<smsc-id>%s</smsc-id>\n\t"
                       "<box-id>%s</box-id>\n\t"
                       "<udh-data>%s</udh-data>\n\t<msg-data>%s</msg-data>\n\t"
                       "</message>\n";
            } else {
                frmt = "[%s] [%s] [%04d-%02d-%02d %02d:%02d:%02d] [%s] [%s] [%s] [%s] [%s] [%s]\n";
            }

            /* transform the time value */
#if LOG_TIMESTAMP_LOCALTIME
            tm = gw_localtime(msg->sms.time);
#else
            tm = gw_gmtime(msg->sms.time);
#endif
            if (msg->sms.udhdata)
                octstr_binary_to_hex(msg->sms.udhdata, 1);
            if (msg->sms.msgdata &&
                (msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2 ||
                (msg->sms.coding == DC_UNDEF && msg->sms.udhdata)))
                octstr_binary_to_hex(msg->sms.msgdata, 1);

            uuid_unparse(msg->sms.id, id);

            octstr_format_append(ret, frmt, id,
                (msg->sms.sms_type == mo ? "MO" :
                 msg->sms.sms_type == mt_push ? "MT-PUSH" :
                 msg->sms.sms_type == mt_reply ? "MT-REPLY" :
                 msg->sms.sms_type == report_mo ? "DLR-MO" :
                 msg->sms.sms_type == report_mt ? "DLR-MT" : ""),
                 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
                 tm.tm_hour, tm.tm_min, tm.tm_sec,
                (msg->sms.sender ? octstr_get_cstr(msg->sms.sender) : ""),
                (msg->sms.receiver ? octstr_get_cstr(msg->sms.receiver) : ""),
                (msg->sms.smsc_id ? octstr_get_cstr(msg->sms.smsc_id) : ""),
                (msg->sms.boxc_id ? octstr_get_cstr(msg->sms.boxc_id) : ""),
                (msg->sms.udhdata ? octstr_get_cstr(msg->sms.udhdata) : ""),
                (msg->sms.msgdata ? octstr_get_cstr(msg->sms.msgdata) : ""));

            if (msg->sms.udhdata)
                octstr_hex_to_binary(msg->sms.udhdata);
            if (msg->sms.msgdata &&
                (msg->sms.coding == DC_8BIT || msg->sms.coding == DC_UCS2 ||
                (msg->sms.coding == DC_UNDEF && msg->sms.udhdata)))
                octstr_hex_to_binary(msg->sms.msgdata);
        }
    }
    gwlist_destroy(keys, octstr_destroy_item);

finish:
    /* set the type based footer */
    if (status_type == BBSTATUS_HTML) {
        octstr_append_cstr(ret,"</table>");
    }

    return ret;
}
Example #6
0
File: log.c Project: frese/mbuni
static void PRINTFLIKE(2,0) output(FILE *f, char *buf, va_list args) 
{
	int i = (int)fileno(f);
	
	// Find the log-file
	for (i = 0; i < num_logfiles; ++i)
        if (logfiles[i].file == f)
			break;
			
	gw_assert(i < num_logfiles); // Make sure we found the log file!
			
	if (rotate_logfile != NEVER && fileno(logfiles[i].file) != stderr) {
		int do_rotate = NEVER;
		time_t t;
		struct tm tm;

        time(&t);
#if LOG_TIMESTAMP_LOCALTIME
		tm = gw_localtime(t);
#else
        tm = gw_gmtime(t);
#endif
		if (init_rotate_tm) {
			rotate_tm = tm;
			init_rotate_tm = 0;
		}

		do_rotate |= ((rotate_logfile == DAILY  ));
		do_rotate |= ((rotate_logfile == WEEKLY ) && (tm.tm_wday == 1));
		do_rotate |= ((rotate_logfile == MONTHLY) && (tm.tm_mday == 1));
		do_rotate &= (rotate_tm.tm_mday != tm.tm_mday);

		if (do_rotate) {
			char log_start[16];
			char new_filename[FILENAME_MAX + 1];
			int year, mon, mday;

			rotate_tm = tm;
			year = tm.tm_year+1900; mon = tm.tm_mon+1; mday = tm.tm_mday-1;
			if (mday < 1) {
				mon--;
				if (mon < 1) {
					mon = 12;
					year--;
				}
				mday = 31;
				if (mon < 8 && ((mon & 0x01) == 0)) mday = 30;
				if (mon > 7 && ((mon & 0x01) == 1)) mday = 30;
				if (mon == 2)
					mday = (year % 4) ? 28 : 29;     // Works until 12/31/2099 ;-)
			}

			fclose(logfiles[i].file);
			sprintf(new_filename, "%s.%04d-%02d-%02d",
				logfiles[i].filename, year, mon, mday);
			if (rename(logfiles[i].filename, new_filename) == -1)
				warning(0, "Log rotate (%s) failed, continuing in current logfile",
					logfiles[i].filename);
			logfiles[i].file = fopen(logfiles[i].filename, "a");
		}
    }
	
    vfprintf(f, buf, args);
    fflush(f);
}