Ejemplo n.º 1
0
/*
 * Send an event, suggesting a given severity level and origin string.
 * The severity must be given but the origin may be NULL, in which case
 * the default supplied by _setorigin() will be used.
 * The event details are represented by a code and string, which may be
 * 0 for the code, NULL or "" for the string.
 * The event will be raised at the specifed severity, unless the log text
 * matches a regular expression entered in _setoverride(), in which case
 * the overriding severity will be used.
 * Data is output in the following order, which may be formatted with
 * a suitable printf format string [see printf(3)]:-
 *
 *    1. s 22 `DEC' style date and time
 *    2. s 28 Unix style date and time
 *    3. s  9 Short, adaptive date and time 
 *    4. d    Seconds since the `epoch' (Jan 1 1970)
 *    5. s  7 Severity string
 *    6. c  1 Severity character in lower case
 *    7. c  1 Severity character in upper case
 *    8. s    Short process name (stripped of file path)
 *    9. s    Full process name (may include file path)
 *   10. d    Process ID
 *   11. d    Thread ID (where applicable: not linux)
 *   12. s    File in which log was raised
 *   13. s    Function in which log was raised
 *   14. d    Line number of initial error function
 *   15. s    Origin sent by application
 *   16. d    Log code sent by application
 *   17. s    Log text sent by application
 *
 * if any spaces are required in the process name or origin, they should
 * be quoted "thus". logtext may include spaces without being quoted, 
 * but no newlines as the field terminates at the end of its line.
 * This version does not flush the route, but holds the text pending
 * in the route_ class. Use _contsend() to continue the same log and
 * _endsend() to finalize the message and send it.
 * Note that is another log is sent for the same route with this message
 * pending, the text will be jumbled with the other log.
 * Returns 1 success or 0 for failure.
 */
int elog_fstartsend(enum elog_severity severity,/* severity level */
		    char *file,			/* raised in file */
		    int line,			/* raised fron line number */
		    const char *function,	/* raised in function */
		    char *logtext		/* log a string */ )
{
     int r;
     time_t logtime;
     char timestr[50];
     struct tm timestruct;

     /* to stderr if uninitialised */
     if ( ! elog_isinit) {
	  fprintf(stderr, "%s: %s (%s:%d:%s)", elog_sevstring[severity], 
		  logtext, file, line, function);
	  return 1;
     }

     /* get time, reenterent style */
     logtime = time(NULL);
     localtime_r(&logtime, &timestruct);
     r = strftime(timestr, 50, "%c", &timestruct);

     /* severity in range? */
     if (severity >= ELOG_NSEVERITIES || severity < 0) {
	  elog_printf(ERROR, "elog_fstartsend(): severity %d out of "
		      "range (0..%d). original error is:-\n"
		      "location: %s:%s:%d\n"
		      "text:     %s\n",
		      severity, ELOG_NSEVERITIES-1, 
		      file, function, line, logtext);
	  return 0;
     }

     r = route_printf(elog_opendest[severity].route, 
		         (elog_opendest[severity].format ? 
			  elog_opendest[severity].format : ELOG_DEFFORMAT), 
		      util_decdatetime(logtime),/* DEC datetime */
		      timestr,			/* unix datetime */
		      util_shortadaptdatetime(logtime),	/* short datetime */
		      logtime,			/* epoch time */
		      elog_sevstring[severity], /* severity string */
		      elog_sevclower[severity], /* severity char low */
		      elog_sevcupper[severity], /* severity char up */
		      util_basename(elog_pname),/* short process name*/
		      elog_pname,		/* long process name*/
		      elog_pid,			/* process id */
		      0, 			/* thread id */
		      file,			/* file name */
		      function,			/* function */
		      line,			/* line number */
		      util_nonull(elog_origin),	/* origin string */
		      0,			/* code to log */
		      util_nonull(logtext));	/* text to log */

     if (r <= 0)
	  return 0;

     return 1;
}
Ejemplo n.º 2
0
char *get_poster_mode_item_unknown(DbItem *row_id,char **font_class,char **grid_class)
{
    HTML_LOG(2,"dbg: unclassified : set details as title");
    // Unclassified

    char *title;
    title = row_id->title;
    if (title != NULL) {
        title = STRDUP(title);
    } else {
        title = util_basename(row_id->file);
    }

    if (strlen(title) > 20) {
        strcpy(title+18,"..");
    }
    if (is_watched(row_id)) {
        *grid_class = "class=poster_watched_unknown";
    } else if (is_fresh(row_id)) {
        *grid_class = "class=poster_fresh_unknown";
    } else {
        *grid_class = "class=poster_unknown";
    }
    *font_class = watched_style_small(row_id);
    return title;
}
Ejemplo n.º 3
0
//Code to play a file. Only Gaya will understand this.
void gaya_auto_load(char *url_encoded_file) {

    char *file = url_decode(url_encoded_file);
    char *name = util_basename(file);

    printf("Content-Type: text/html\n\n");
    printf("<html><body onloadset=playme bgcolor=black text=white link=white >\n");
    //printf("<html><body >\n");

    printf("<br><a href=\"/oversight/oversight.cgi\">Oversight</a>\n");

    //char *back=get_self_link("","",name);
    //printf("<br>%s\n",back);
    //FREE(back);

    printf("<br><a href=\"/start.cgi\">Home</a>\n");

    printf("<hr><a href=\"file://%s\" %s onfocusload name=playme>Play %s</a>\n", // file://
            url_encoded_file,vod_attr(file),name);

    printf("</body></html>\n");

    FREE(file);
    FREE(name);
}
Ejemplo n.º 4
0
//
// Return 1 if path can be mounted.
// the share name is the folder after the NETWORK_SHARE sub folder.
// Then the nmt settings are inspected to get the full mount definition.
//
// First try to ping the host.
//
// If that doesnt work and using SMB/cifs then try to use nbtscan to
// resolve wins names.
//
// The current_mount_status is passed in case the share is alread present
// in /etc/mtab. If it is not - try to mount it, if it is, then check for timeouts.
static int nmt_mount_share(char *path,char *current_mount_status)
{
    int result = 0;

    char *link_prefix=NULL;
    char *share_name = util_basename(path);
    HTML_LOG(0,"mount path=[%s] share_name [%s] current status [%s]",path,share_name,current_mount_status);
    // eg "abc"

    char index = get_link_index("servname",share_name);
    if (index) {
        link_prefix="servlink";
    } else {
        index = get_link_index("netfs_name",share_name);
        if (index) {
            link_prefix="netfs_url";
        }
    }

    if (index) {
        char *key;
        ovs_asprintf(&key,"%s%c",link_prefix,index);

        char *serv_link = setting_val(key);
        // Look for corresponding variable servlinkN
		
		HTML_LOG(0,"DEMOTE mount %s [%s]",link_prefix,serv_link);
        FREE(key);

        char *link = get_pingable_link(serv_link);

        if (!link) {

            set_mount_status(path,MOUNT_STATUS_BAD);
        } else if (STRCMP(current_mount_status,MOUNT_STATUS_NOT_IN_MTAB) == 0) {

            char *user = get_link_user(serv_link);
            char *passwd = get_link_passwd(serv_link);
            NETFSProtocol proto = get_link_protocol(serv_link);

            char *cmd = get_mount_command(proto,link,path,user,passwd);

            FREE(user);
            FREE(passwd);

            if (cmd ) {
                long t = time(NULL);
                int mount_result = util_system(cmd);

                // Mount prints detailed error to stdout but just returns exit codes
                // 0(OK) , 1(Bad args?) OR  0xFF00 (Something else).
                // So we cant tell exactly why it failed without scraping
                // stdout.
                // Eg if mount display 'Device or resource Busy' it doesnt return EBUSY(16)
                //
                // Also trying to use native mount() function is hard work
                // (it does kernel space work but not other stuff - update /etc/mtab etc?)
                //
                // So I've taken a big liberty here and assumed that if the mount returns
                // immediately that it worked.
                // This obviously is risky of the mount failed due to bad parameters.
                switch(mount_result) {
                case 0:
                    result = 1;
                    break;
                case 0xFF00:
                    // some mount error occured. If it occured in less than 1 second
                    // just assume its a device busy and continue happily assuming it
                    // is already mounted.
                    if (time(NULL) - t <= 5) {
                        HTML_LOG(0,"mount [%s] failed quickly - assume all is ok",cmd);
                        result = 1;
                    } else {
                        HTML_LOG(0,"mount [%s] failed slowly - assume the worst ",cmd);
                        result = 0;
                    }
                    break;
                default:
                    HTML_LOG(0,"mount [%s] unknown error - assume the worst ",cmd);
                    //even though mount failed - add it to the list to avoid repeat attempts.
                    result = 0;
                }
                set_mount_status(path,(result ? MOUNT_STATUS_OK : MOUNT_STATUS_BAD));

                FREE(cmd);
            }

        } else if (STRCMP(current_mount_status,MOUNT_STATUS_IN_MTAB) == 0) {
            // Its pingable but now we check it is accessible.
TRACE;
            result = check_accessible(path,5);
        } else {
            // shouldnt get here
            assert(0);
        }
        FREE(link);
    }
    FREE(share_name);
    return result;
}