/*
file_get_ext( const char *filename )
@filename - nazwa pliku lub pe�na nazwa pliku ( +�cie�ka )
- pobiera rozszerzenie z podanej nazwy pliku
- zwraca char *z rozszerzeniem */
char* file_get_ext( const char *filename ) {
	char* file_ext = strrchr( file_get_name( filename ), '.' );

	if( !file_ext ) {
		return "";
	}
	return file_ext;
}
Exemple #2
0
void CMainWindow::onEvent (CImageManager::IObserver::EVT evt, void *param) {
    xl::ui::CCtrlSlider *pSlider = (xl::ui::CCtrlSlider *)m_slider.get();
    assert(pSlider != NULL);
    assert(m_navbar != NULL);
    switch (evt) {
    case CImageManager::EVT_FILELIST_READY:
        m_navbar->setStyle(_T("disable:false"));
        m_toolbar->setStyle(_T("disable:false"));
        m_navbtn[0]->setStyle(_T("disable:false"));
        m_navbtn[1]->setStyle(_T("disable:false"));
        m_naview->setStyle(_T("disable:false"));
        // gestory
        m_ctrlMain->enableGesture(true);
        m_ctrlMain->setStyle(_T("background:none"));
        m_ctrlMain->getGestureCtrl()->setStyle(_T("padding:4 0; color:#ff0000; font-size:16;"));// font-weight:bold;"));
        break;
    case CImageManager::EVT_INDEX_CHANGED:
    {
        assert(param != NULL);
        int _min = 0, _max = m_cachedImages.size() - 1, _curr = *(int *)param;
        assert(_curr == (int)m_currIndex);
        TCHAR buf[128];
        _stprintf_s(buf, 128, _T("slider: %d %d %d; disable:false;"), _min, _max, _curr);
        pSlider->setStyle(buf);

        xl::tstring title = MAIN_TITLE;
        _stprintf_s(buf, 128, _T(" (%d/%d)"), _curr + 1, _max + 1);
        // title += _T(" - ") + m_cachedImages[_curr]->getFileName();
        title += _T(" - ") + file_get_name(m_cachedImages[_curr]->getFileName());
        title += buf;
        SetWindowText(title);
    }
    break;
    case CImageManager::EVT_IMAGE_LOADED:
        break;
    case CImageManager::EVT_THUMBNAIL_LOADED:
        break;
    case CImageManager::EVT_I_AM_DEAD:
        break;
    default:
        assert(false);
        break;
    }
}
static trg_files_tree_node *trg_file_parser_node_insert(trg_files_tree_node
                                                        * top,
                                                        trg_files_tree_node
                                                        * last,
                                                        JsonObject * file,
                                                        gint index,
                                                        JsonArray *
                                                        enabled,
                                                        JsonArray *
                                                        priorities)
{
    gchar **path = g_strsplit(file_get_name(file), "/", -1);
    trg_files_tree_node *lastIter = last;
    GList *parentList = NULL;
    gchar *path_el;
    GList *li;
    int i;

    /* Build up a list of pointers to each parent trg_files_tree_node
     * reversing the order as it iterates over its parent.
     */
    if (lastIter)
        while ((lastIter = lastIter->parent))
            parentList = g_list_prepend(parentList, lastIter);

    li = parentList;
    lastIter = top;

    /* Iterate over the path list which contains each file/directory
     * component of the path in order.
     */
    for (i = 0; (path_el = path[i]); i++) {
        gboolean isFile = !path[i + 1];
        trg_files_tree_node *target_node = NULL;

        /* No point checking for files. If there is a last parents iterator
         * check it for a shortcut. I'm assuming that these come in order of
         * directory at least to give performance a boost.
         */
        if (li && !isFile) {
            trg_files_tree_node *lastPathNode =
                (trg_files_tree_node *) li->data;

            if (!g_strcmp0(lastPathNode->name, path[i])) {
                target_node = lastPathNode;
                li = g_list_next(li);
            } else {
                /* No need to check any further. */
                li = NULL;
            }
        }

        if (!target_node && lastIter && lastIter->childrenHash && !isFile)
          target_node = g_hash_table_lookup(lastIter->childrenHash, path_el);

        /* Node needs creating */

        if (!target_node) {
            target_node = g_new0(trg_files_tree_node, 1);
            target_node->name = g_strdup(path[i]);
            target_node->parent = lastIter;
            trg_files_tree_node_add_child(lastIter, target_node);
        }

        lastIter = target_node;

        /* Files have more properties set here than for files.
         * Directories are updated from here too, by trg_files_tree_update_ancestors
         * working up the parents.
         */
        if (isFile) {
            target_node->length = file_get_length(file);
            target_node->bytesCompleted = file_get_bytes_completed(file);
            target_node->index = index;
            target_node->enabled =
                (gint) json_array_get_int_element(enabled, index);
            target_node->priority =
                (gint) json_array_get_int_element(priorities, index);

            trg_files_tree_update_ancestors(target_node);
        } else {
            target_node->index = -1;
        }
    }

    g_list_free(parentList);
    g_strfreev(path);

    return lastIter;
}
/*
REQUEST_process( HTTP_SESSION *http_session )
@http_session - wska�nik do pod��czonego klienta
- po udanej weryfikacji danych przechodzi do pr�by przes�ania ��danego zasobu */
void REQUEST_process( HTTP_SESSION *http_session ) {
	char *local_file_path;		/* Lokalna �cie�ka do ��danego pliku */
	char *file_ext;				/* Rozszerzenie ��danego pliku */
	char *add_hdr;				/* Opcjonalne nag��wki */
	char *ht_access_pwd;		/* Has�o do ��danego zasobu z funkcji file_params*/
	int len_loc; /* D�ugo�� ��danej �cie�ki */
	int file_params_val = 0;	/* Przechowuje wynik dzia�ania funkcji file_params */

	len_loc = strlen( http_session->http_info.http_local_path );
	/* Przygotowanie pami�ci na nazw� ��danego pliku */
	local_file_path = malloc( MAX_PATH_LENGTH_CHAR+1 );
	mem_allocated( local_file_path, 34 );

	/* Po��czenie �cie�ki z ��dania z pe�n� �cie�k� w systemie*/
	if( len_loc > 1 ) {
		/* Stworzenie lokalnej �cie�ki dost�pu do zasobu */
		strncpy( local_file_path, app_path, MAX_PATH_LENGTH );
		strncat( local_file_path, http_session->http_info.http_local_path, MAX_PATH_LENGTH );
	} else {
		/* Jeste�my w g��wnym katalogu */
		strncpy( local_file_path, app_path, MAX_PATH_LENGTH );
	}

	/* Zamiana znaku "/" z request na "\" - tylko Win32*/
	strrepchar( local_file_path, '/', C_SLASH );

	/* Usuni�cie podw�jnych znak�w slash */
	strdelbslash( local_file_path );

	/* Je�eli podano sam� nazw� katalogu to automatycznie dodajemy plik indeksu - tu juz po weryfikacji, czy zasob jest skryptem CGI */
	if( strncmp( file_get_name( local_file_path ), "", 1 ) == 0 ) {
		strncat( local_file_path, REQUEST_get_index( local_file_path ), MAX_PATH_LENGTH );
	}

	if( ht_access_count > 0 ) {
		/* Alokacja pami�ci */
		ht_access_pwd = malloc( STD_BUFF_SIZE_CHAR );
		mem_allocated( ht_access_pwd, 35 );
	}

	/*Sprawdzamy, czy ��dany plik istnieje... */
	file_params_val = file_params( http_session, local_file_path, (ht_access_count > 0 ? ht_access_pwd : NULL ) );
	if( file_params_val == 0 ) { /* Plik nie istnieje */
		file_ext = malloc( MICRO_BUFF_SIZE_CHAR );
		strncpy( file_ext, file_get_ext( local_file_path ), MICRO_BUFF_SIZE );
		/*...brak rozszerzenia = nie podano konkretnego pliku w URL... */
		if( strncmp( file_ext, "", MICRO_BUFF_SIZE ) == 0 ) {
			/*...sprawdzamy, czy ostatni znak to "/"... */
			if( local_file_path[ strlen( local_file_path )-1 ] != C_SLASH ) {
				/*...mimo wszystko sprawdzamy, czy �cie�ka jest prawid�owa. Tak = b��d 302. Nie = b��d 400. */
				if( directory_exists( local_file_path ) ) {
					/* Stworzenie dodatkowej informacji do nag��wna wysy�anego przez RESPONSE_error z prawid�ow� �cie�k� */
					add_hdr = malloc( MAX_PATH_LENGTH_CHAR );
					sprintf( add_hdr, "%s%s/\r\n", HEADER_LOCATION, http_session->http_info.http_local_path );
					RESPONSE_error( http_session, HTTP_302_FOUND, HTTP_ERR_302_MSG, add_hdr );
					free( add_hdr );
					add_hdr = NULL;
				} else {
					RESPONSE_error( http_session, HTTP_400_BAD_REQUEST, HTTP_ERR_400_MSG, NULL );
				}
			} else {
				/*...plik nie istnieje, a index.html brak... */
				RESPONSE_error( http_session, HTTP_404_NOT_FOUND, HTTP_ERR_404_MSG, NULL );
			}
		} else {
			RESPONSE_error( http_session, HTTP_404_NOT_FOUND, HTTP_ERR_404_MSG, NULL );
		}

		/* Zwolnienie pami�ci dla rozszerzenia ��danego pliku */
		free( file_ext );
		file_ext = NULL;
	} else {
		/* Plik istnieje, ale jakie ma w�a�ciwo�ci ? */
		if( file_params_val == 1 ) {
			/* Plik istnieje i jest do odczytu */
			/* Je�eli jest to skrypt CGI, to zostaje wykonany */
			/* Zwyk�e ��danie zasobu */
			/*Zapytanie zweryfikowane - wysy�ka zawarto�ci zasobu */
			if( http_session->http_info.method_name != POST ) {
				RESPONSE_file( http_session, local_file_path ); /* Zapytanie HEAD jest weryfikowane w funkcji RESPONSE_header */
			}
		} else if( file_params_val == 2 ) {/* Plik istnieje, ale dost�p jest zabroniony */
			RESPONSE_error( http_session, HTTP_403_FORBIDDEN, HTTP_ERR_403_MSG, NULL );
		} else if( file_params_val == 3 ) {/* Plik istnieje, ale wymaga autoryzacji */
			if( http_session->http_info.authorization ) {
				if( strncmp( ht_access_pwd, http_session->http_info.authorization, STD_BUFF_SIZE ) == 0 ) {
					/* Zwyk�e ��danie zasobu */
					/*Zapytanie zweryfikowane - wysy�ka zawarto�ci zasobu */
					if( http_session->http_info.method_name != POST ) {
						RESPONSE_file( http_session, local_file_path ); /* Zapytanie HEAD jest weryfikowane w funkcji RESPONSE_header */
					} else {
						RESPONSE_error( http_session, HTTP_401_AUTHORIZATION_REQUIRED, HTTP_ERR_401_MSG, HEADER_AUTHENTICATION );
					}
				} else {
					RESPONSE_error( http_session, HTTP_401_AUTHORIZATION_REQUIRED, HTTP_ERR_401_MSG, HEADER_AUTHENTICATION );
				}
			} else {
				RESPONSE_error( http_session, HTTP_401_AUTHORIZATION_REQUIRED, HTTP_ERR_401_MSG, HEADER_AUTHENTICATION );
			}
		}
	}

	if( ht_access_count > 0) {
		/* Zwolnienie pami�ci dla has�a zasobu */
		if( ht_access_pwd ) {
			free( ht_access_pwd );
			ht_access_pwd = NULL;
		}
	}

	/* Zwolnienie pami�ci dla nazwy ��danego pliku */
	free( local_file_path );
	local_file_path = NULL;

	 /* Zwalniamy pami�� */
	SESSION_release( http_session );
}