示例#1
0
string_directory::string_directory(const char * p_path)
{
	t_size ptr = scan_filename(p_path);
	if (ptr > 1) {
		if (is_path_separator(p_path[ptr-1]) && !is_path_separator(p_path[ptr-2])) --ptr;
	}
	m_data.set_string(p_path,ptr);
}
示例#2
0
void string_base::truncate_to_parent_path() {
	size_t at = scan_filename();
#ifdef _WIN32
	while(at > 0 && (*this)[at-1] == '\\') --at;
	if (at > 0 && (*this)[at-1] == ':' && (*this)[at] == '\\') ++at;
#else
	// Strip trailing /
	while(at > 0 && (*this)[at-1] == '/') --at;

	// Hit empty? Bring root / back to life
	if (at == 0 && (*this)[0] == '/') ++at;

	// Deal with proto://
	if (at > 0 && (*this)[at-1] == ':') {
		while((*this)[at] == '/') ++at;
	}
#endif
	this->truncate( at );
}
示例#3
0
int main(int argc, char**argv)
{
	GMainLoop *loop;
	DBusError error;
	int godaemon = 1;

/*
 * Signal the kernel that we're not timing critical
 */
#ifdef PR_SET_TIMERSLACK
	prctl(PR_SET_TIMERSLACK,1000*1000*1000, 0, 0, 0);
#endif

	read_config_file("/etc/kerneloops.conf");

	if (argc > 1 && strstr(argv[1], "--nodaemon"))
		godaemon = 0;
	if (argc > 1 && strstr(argv[1], "--debug")) {
		printf("Starting kerneloops in debug mode\n");
		godaemon = 0;
		testmode = 1;
		opted_in = 2;
	}

	if (!opted_in && !testmode) {
		fprintf(stderr, " [Inactive by user preference]");
		return EXIT_SUCCESS;
	}

	/*
	 * the curl docs say that we "should" call curl_global_init early,
	 * even though it'll be called later on via curl_easy_init().
	 * We ignore this advice, since 99.99% of the time this program
	 * will not use http at all, but the curl code does consume
	 * memory.
	 */

/*
	curl_global_init(CURL_GLOBAL_ALL);
*/

	if (godaemon && daemon(0, 0)) {
		printf("kerneloops failed to daemonize.. exiting \n");
		return EXIT_FAILURE;
	}
	sched_yield();

	loop = g_main_loop_new(NULL, FALSE);
	dbus_error_init(&error);
	bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
	if (bus) {
		dbus_connection_setup_with_g_main(bus, NULL);
		dbus_bus_add_match(bus, "type='signal',interface='org.kerneloops.submit.ping'", &error);
		dbus_bus_add_match(bus, "type='signal',interface='org.kerneloops.submit.permission'", &error);
		dbus_connection_add_filter(bus, got_message, NULL, NULL);
	}

	/* we scan dmesg before /var/log/messages; dmesg is a more accurate source normally */
	scan_dmesg(NULL);
	/* during boot... don't go too fast and slow the system down */
	if (!testmode)
		sleep(10);
	scan_filename(log_file, 1);

	if (argc > 2 && strstr(argv[1], "--file"))
		scan_filename(argv[2], 1);

	if (testmode && argc > 2) {
		int q;
		for (q = 2; q < argc; q++) {
			printf("Scanning %s\n", argv[q]);
			scan_filename(argv[q], 0);
		}
	}

	if (testmode) {
		g_main_loop_unref(loop);
		dbus_bus_remove_match(bus, "type='signal',interface='org.kerneloops.submit.ping'", &error);
		dbus_bus_remove_match(bus, "type='signal',interface='org.kerneloops.submit.permission'", &error);
		free(submit_url);
		return EXIT_SUCCESS;
	}

	/* now, start polling for oopses to occur */

	g_timeout_add_seconds(10, scan_dmesg, NULL);

	g_main_loop_run(loop);
	dbus_bus_remove_match(bus, "type='signal',interface='org.kerneloops.submit.ping'", &error);
	dbus_bus_remove_match(bus, "type='signal',interface='org.kerneloops.submit.permission'", &error);

	g_main_loop_unref(loop);
	free(submit_url);

	return EXIT_SUCCESS;
}
示例#4
0
int scan_xml_tracks_section(int action, char *info) {
    static int state;
    static int current_track_id;
    static int current_field;
    static int is_streaming;
    static MP3FILE mp3;
    static char *song_path=NULL;
    char real_path[PATH_MAX];
    MP3FILE *pmp3;
    int added_id;

    if(action == RXML_EVT_OPEN) {
        state = XML_TRACK_ST_INITIAL;
        memset((void*)&mp3,0,sizeof(MP3FILE));
        song_path = NULL;
        return 0;
    }

    /* walk through the states */
    switch(state) {
    case XML_TRACK_ST_INITIAL:
        /* expection only a <dict> */
        MAYBESETSTATE_TR(RXML_EVT_BEGIN,"dict",XML_TRACK_ST_MAIN_DICT);
        return XML_STATE_ERROR;
        break;

    case XML_TRACK_ST_MAIN_DICT:
        /* either get a <key>, or a </dict> */
        MAYBESETSTATE_TR(RXML_EVT_BEGIN,"key",XML_TRACK_ST_EXPECTING_TRACK_ID);
        if ((action == RXML_EVT_END) && (strcasecmp(info,"dict") == 0)) {
            return XML_STATE_PREAMBLE;
        }
        return XML_STATE_ERROR;
        break;

    case XML_TRACK_ST_EXPECTING_TRACK_ID:
        /* this is somewhat loose  - <key>id</key> */
        MAYBESETSTATE_TR(RXML_EVT_BEGIN,"key",XML_TRACK_ST_EXPECTING_TRACK_ID);
        MAYBESETSTATE_TR(RXML_EVT_END,"key",XML_TRACK_ST_EXPECTING_TRACK_DICT);
        if (action == RXML_EVT_TEXT) {
            current_track_id = atoi(info);
            DPRINTF(E_DBG,L_SCAN,"Scanning iTunes id #%d\n",current_track_id);
        } else {
            return XML_STATE_ERROR;
        }
        break;

    case XML_TRACK_ST_EXPECTING_TRACK_DICT:
        /* waiting for a dict */
        MAYBESETSTATE_TR(RXML_EVT_BEGIN,"dict",XML_TRACK_ST_TRACK_INFO);
        return XML_STATE_ERROR;
        break;

    case XML_TRACK_ST_TRACK_INFO:
        /* again, kind of loose */
        MAYBESETSTATE_TR(RXML_EVT_BEGIN,"key",XML_TRACK_ST_TRACK_INFO);
        MAYBESETSTATE_TR(RXML_EVT_END,"key",XML_TRACK_ST_TRACK_DATA);
        if(action == RXML_EVT_TEXT) {
            current_field=scan_xml_get_tagindex(info);
            if(current_field == SCAN_XML_T_DISABLED) {
                mp3.disabled = 1;
            } else if(current_field == SCAN_XML_T_COMPILATION) {
                mp3.compilation = 1;
            }
        } else if((action == RXML_EVT_END) && (strcmp(info,"dict")==0)) {
            state = XML_TRACK_ST_MAIN_DICT;
            /* but more importantly, we gotta process the track */
            is_streaming = 0;
            if((song_path) && strncasecmp(song_path,"http://",7) == 0)
                is_streaming = 1;

            if((!is_streaming)&&scan_xml_translate_path(song_path,real_path)) {
                /* FIXME: Error handling */
                pmp3=db_fetch_path(NULL,real_path,0);
                if(!pmp3) {
                    /* file doesn't exist... let's add it? */
                    scan_filename(real_path,SCAN_TEST_COMPDIR,NULL,NULL);
                    pmp3=db_fetch_path(NULL,real_path,0);
                }
                if(pmp3) {
                    /* Update the existing record with the
                     * updated stuff we got from the iTunes xml file
                     */
                    MAYBECOPYSTRING(title);
                    MAYBECOPYSTRING(artist);
                    MAYBECOPYSTRING(album);
                    MAYBECOPYSTRING(genre);
                    MAYBECOPYSTRING(comment);
                    MAYBECOPYSTRING(composer);
                    MAYBECOPY(song_length);
                    MAYBECOPY(track);
                    MAYBECOPY(total_tracks);
                    MAYBECOPY(year);
                    MAYBECOPY(bitrate);
                    MAYBECOPY(samplerate);
                    MAYBECOPY(play_count);
                    MAYBECOPY(rating);
                    MAYBECOPY(disc);
                    MAYBECOPY(total_discs);
                    MAYBECOPY(time_added);
                    MAYBECOPY(disabled);
                    MAYBECOPYSTRING(album_artist);

                    /* must add to the red-black tree */
                    scan_xml_add_lookup(current_track_id,pmp3->id);

                    make_composite_tags(pmp3);
                    db_add(NULL,pmp3,NULL);
                    db_dispose_item(pmp3);
                }
            } else if(is_streaming) {
                /* add/update a http:// url */
                pmp3=db_fetch_path(NULL,scan_xml_file,current_track_id);
                if(!pmp3) {
                    /* gotta add it! */
                    DPRINTF(E_DBG,L_SCAN,"Adding %s\n",song_path);
                    pmp3 = calloc(sizeof(MP3FILE),1);

                    if(!pmp3)
                        DPRINTF(E_FATAL,L_SCAN,
                                "malloc: scan_xml_tracks_section\n");
                } else {
                    DPRINTF(E_DBG,L_SCAN,"updating %s\n",song_path);
                }
                pmp3->url = strdup(song_path);
                pmp3->type = strdup("pls");
                pmp3->description = strdup("Playlist URL");
                pmp3->data_kind = 1;
                pmp3->item_kind = 2;

                pmp3->path = strdup(scan_xml_file);
                pmp3->index = current_track_id;

                MAYBECOPYSTRING(title);
                MAYBECOPYSTRING(artist);
                MAYBECOPYSTRING(album);
                MAYBECOPYSTRING(genre);
                MAYBECOPYSTRING(comment);
                MAYBECOPY(bitrate);
                MAYBECOPY(samplerate);
                MAYBECOPY(play_count);
                MAYBECOPY(rating);
                MAYBECOPY(time_added);
                MAYBECOPY(disabled);
                MAYBECOPYSTRING(album_artist);

                make_composite_tags(pmp3);
                if(db_add(NULL,pmp3,&added_id) == DB_E_SUCCESS) {
                    scan_xml_add_lookup(current_track_id,added_id);
                    DPRINTF(E_DBG,L_SCAN,"Added %s\n",song_path);
                } else {
                    DPRINTF(E_DBG,L_SCAN,"Error adding %s\n",song_path);
                }

                db_dispose_item(pmp3);
            }

            /* cleanup what's left */
            MAYBEFREE(mp3.title);
            MAYBEFREE(mp3.artist);
            MAYBEFREE(mp3.album);
            MAYBEFREE(mp3.genre);
            MAYBEFREE(mp3.comment);
            MAYBEFREE(mp3.album_artist);
            MAYBEFREE(song_path);

            memset((void*)&mp3,0,sizeof(MP3FILE));
        } else {
            return XML_STATE_ERROR;
        }
        break;

    case XML_TRACK_ST_TRACK_DATA:
        if(action == RXML_EVT_BEGIN) {
            break;
        } else if(action == RXML_EVT_TEXT) {
            if(current_field == SCAN_XML_T_NAME) {
                mp3.title = strdup(info);
            } else if(current_field == SCAN_XML_T_ARTIST) {
                mp3.artist = strdup(info);
            } else if(current_field == SCAN_XML_T_ALBUM) {
                mp3.album = strdup(info);
            } else if(current_field == SCAN_XML_T_GENRE) {
                mp3.genre = strdup(info);
            } else if(current_field == SCAN_XML_T_TOTALTIME) {
                mp3.song_length = atoi(info);
            } else if(current_field == SCAN_XML_T_TRACKNUMBER) {
                mp3.track = atoi(info);
            } else if(current_field == SCAN_XML_T_TRACKCOUNT) {
                mp3.total_tracks = atoi(info);
            } else if(current_field == SCAN_XML_T_YEAR) {
                mp3.year = atoi(info);
            } else if(current_field == SCAN_XML_T_BITRATE) {
                mp3.bitrate = atoi(info);
            } else if(current_field == SCAN_XML_T_SAMPLERATE) {
                mp3.samplerate = atoi(info);
            } else if(current_field == SCAN_XML_T_PLAYCOUNT) {
                mp3.play_count = atoi(info);
            } else if(current_field == SCAN_XML_T_RATING) {
                mp3.rating = atoi(info);
            } else if(current_field == SCAN_XML_T_DISCNO) {
                mp3.disc = atoi(info);
            } else if(current_field == SCAN_XML_T_DISCCOUNT) {
                mp3.total_discs = atoi(info);
            } else if(current_field == SCAN_XML_T_LOCATION) {
                song_path = scan_xml_urldecode(info,0);
                DPRINTF(E_DBG,L_SCAN,"scan_path: %s\n",song_path);
            } else if(current_field == SCAN_XML_T_DATE_ADDED) {
                mp3.time_added = scan_xml_datedecode(info);
            } else if(current_field == SCAN_XML_T_COMMENTS) {
                mp3.comment = strdup(info);
            } else if(current_field == SCAN_XML_T_COMPOSER) {
                mp3.composer = strdup(info);
            } else if(current_field == SCAN_XML_T_ALBUM_ARTIST) {
                mp3.album_artist = strdup(info);
            }
        } else if(action == RXML_EVT_END) {
            state = XML_TRACK_ST_TRACK_INFO;
        } else {
            return XML_STATE_ERROR;
        }
        break;
    default:
        return XML_STATE_ERROR;
    }

    return XML_STATE_TRACKS;
}