예제 #1
0
/*!
 * \brief Checa pode ser recebido.
 * \param[in] request Estrutura com as informacoes do arquivo requisitado.
 * \return 0 para sucesso e <0 para falha.
 */
int check_file_ready_to_receive(struct request_file * request)
{
  char file_name_part[PATH_MAX];
  char *last_slash = NULL;
  char abs_path[PATH_MAX];

  if (request->file_name == NULL)
    return ERROR;

  if (check_if_file_is_forbidden(request->file_name))
  {
    request->status = FORBIDDEN;
    goto on_error;
  }

  realpath(request->file_name, abs_path);
  if (strstr(abs_path, request->file_name))
  {
    last_slash = strrchr(abs_path,'/');
    memset(last_slash, 0, strlen(last_slash));
  }

  if (check_if_file_exists(abs_path))
  {
    request->status = FORBIDDEN;
    goto on_error;
  }

  if (check_if_is_directory(request->file_name) == SUCCESS)
  {
    request->status = BAD_REQUEST;
    goto on_error;
  }

  if (check_if_can_read_write_file(abs_path, W_OK))
  {
    request->status = UNAUTHORIZED;
    goto on_error;
  }
  snprintf(file_name_part, strlen(request->file_name) + strlen("~part") + 1,
           "%s~part", request->file_name);

  if (check_if_file_exists(file_name_part) == SUCCESS)
  {
    request->status = CONFLICT;
    goto on_error;
  }

  return SUCCESS;
on_error:
  set_std_response(request);
  return ERROR;
}
예제 #2
0
파일: q7.c 프로젝트: eokeeffe/C-code
int seek_record()
{
    FILE *FILE_HANDLE , *fopen();
    int record_to_search_for;

    FILE_HANDLE = fopen("student_records.dat","rb");//simply append to the binary file

    check_if_file_exists(FILE_HANDLE);

    printf("Please enter the record number to search for\r\n");
    record_to_search_for = get_int();

    if(record_to_search_for < 1 || record_to_search_for > 10)
    {
        fprintf(stderr,"Please enter a number between 0-10\r\n");
        fclose(FILE_HANDLE);
        seek_record();
    }

    fseek( FILE_HANDLE , ( record_to_search_for - 1)*sizeof(access),SEEK_SET);//seek the item at position N-1 , from the stream file handle
    // SEEK_SET means set the file pointer to the start of the file
    fread(&access, sizeof( access ) , 1 , FILE_HANDLE);

    fprintf(stdout,"Student Name:%s\r\nStudent Number:%d\r\nStudent Record:%d\r\n",access.student_name,access.student_number,access.record_number);

    fclose(FILE_HANDLE);

    exit(EXIT_SUCCESS);
}
예제 #3
0
/*!
 * \brief Checa se o arquivo existe e pode ser enviado.
 * \param[in] request Estrutura com as informacoes do arquivo requisitado.
 * \return 0 para sucesso e <0 para falha.
 */
int check_file_ready_to_send(struct request_file * request)
{
  if (request->file_name == NULL)
    return ERROR;
  if (check_if_file_exists(request->file_name))
  {
    request->status = NOT_FOUND;
    goto on_error;
  }
  if (check_if_is_directory(request->file_name) == SUCCESS)
  {
    request->status = BAD_REQUEST;
    goto on_error;
  }
  if (check_if_file_is_forbidden(request->file_name))
  {
    request->status = FORBIDDEN;
    goto on_error;
  }
  if (check_if_can_read_write_file(request->file_name, R_OK))
  {
    request->status = UNAUTHORIZED;
    goto on_error;
  }
  return SUCCESS;
on_error:
  set_std_response(request);
  return ERROR;
}
예제 #4
0
bool check_if_directory_exists(std::string dir_name)
{
	return dir_name.empty()==false && check_if_file_exists(dir_name);
/*	tinydir_dir dir;
	tinydir_open(&dir, dir_name.c_str());
	if(dir.has_next)
	{
		tinydir_close(&dir);
		return true;
	}
	tinydir_close(&dir);
	return false;*/
}
예제 #5
0
/**
 * @brief exist_required_files check if there are the required files
 *                              in the new selected folder.
 * @param dir : path of folder where search the files.
 * @return true if there are required files, false there not.
 */
static bool exist_required_files(const QString& dir)
{
    QString * arr_requrired_files = load_requried_files(dir);

    for (int i = 0; i < NUM_REQUIRED_FILE; i++)
        if(!check_if_file_exists(arr_requrired_files[i]))
        {
            qDebug()<<arr_requrired_files[i]<<" non esiste";
            return false;
        }

    return true;
}
예제 #6
0
파일: q7.c 프로젝트: eokeeffe/C-code
int read_from_binary_file()
{
    FILE *FILE_HANDLE , *fopen();

    FILE_HANDLE = fopen("student_records.dat","rb");//simply append to the binary file

    check_if_file_exists(FILE_HANDLE);

    fread(&access, sizeof( access ) , 1 , FILE_HANDLE); // the easiest reading of a struct in C

    fprintf(stdout,"Student Name:%s\r\nStudent Number:%d\r\nStudent Record:%d",access.student_name,access.student_number,access.record_number);

    fclose(FILE_HANDLE);

    return 1;
}
예제 #7
0
파일: q7.c 프로젝트: eokeeffe/C-code
int write_to_binary_file()
{
    FILE *FILE_HANDLE , *fopen();
    int counter;

    FILE_HANDLE = fopen("student_records.dat","wb+");//simply append to the binary file

    check_if_file_exists(FILE_HANDLE);

    for( counter =0;
            fwrite(&list[counter],sizeof( access) , 1 , FILE_HANDLE) && counter < struct_counter;//write the entire struct to the binary file
            counter++);

    fclose(FILE_HANDLE);

    return 1;
}
예제 #8
0
int handle_end_upload(const int socket_id, struct request_file **head)
{
  struct request_file *request = NULL;

  request = set_method_equals_get(socket_id, head);
  if (request == NULL)
    return ERROR;

  request->transferred_size = 0;
  memset(request->buffer, 0, BUFSIZE);

  if (check_if_file_exists(request->file_name) == SUCCESS)
    request->status = OK;
  else
    request->status = CREATED;

  rename_downloaded_file(request);

  set_std_response(request);
  return SUCCESS;
}
예제 #9
0
파일: q1.c 프로젝트: eokeeffe/C-code
int write_to_binary_file(int user_input)
{
	FILE *FILE_HANDLE , *fopen();
	
	FILE_HANDLE = fopen("binary_number_file.dat","ab+");//simply append to the binary file
	
	check_if_file_exists(FILE_HANDLE);
	
	fwrite(&user_input,sizeof(int),1,FILE_HANDLE);
	/* 
	   Explanation
	   the first arguement is the address of the information to write
	   the second arguement is the size of the object to write
	   the third is the number of items to write
	   the last is the stream that the object will be written to 
	*/
	
	fclose(FILE_HANDLE);
	
	get_user_number();
	
	return 1;
}
/*****
* Load initial settings from winfflow.ini
*****/
void
load_settings(void)
{
	GetExePath(hInst, inifile);

	strcat(inifile, "winfflow.ini");

	if(!check_if_file_exists(inifile))
	{
		char string[5];
		/* version information */
		WritePrivateProfileString("fflow", "scanner", VERSION, inifile);
		WritePrivateProfileString("fflow", "winfflow", WINFFLOW_VERSION,
			inifile);
		/* default settings */
		/* editor command */
		WritePrivateProfileString("Settings", "Editor",
			"POPPAD.EXE @FILE -l @LINE", inifile);
		/* save filelist on exit */
		WritePrivateProfileString("Settings","KeepFiles", "1", inifile);
		/* collapse consecutive calls to the same routine */
		WritePrivateProfileString("Settings", "CollapseMultiple", "1",
			inifile);
		/* allow dynamic updating of flowgraphs */
		WritePrivateProfileString("Settings", "DynamicUpdate", "1",
			inifile);
		/* don't hide unresolved calls */
		WritePrivateProfileString("Settings", "HideUnresolved", "0",
			inifile);
		/* cutoff depth for flowgraphs */
		WritePrivateProfileString("Settings", "CutOff", "0", inifile);
		itoa(MAXDEPTH, string, 10);
		/* maximum allowable recursion while generating flowgraph */
		WritePrivateProfileString("Settings", "MaxDepth", string,
			inifile);
	}
	/* default editor */
	GetPrivateProfileString("Settings", "Editor", "NOTEPAD.EXE @FILE",
		default_editor, MAXPATHLEN, inifile);

	collapse_consecutive = GetPrivateProfileInt("Settings",
		"CollapseMultiple", 1, inifile);
	hide_unresolved = GetPrivateProfileInt("Settings", "HideUnresolved",
		0, inifile);
	keep_files = GetPrivateProfileInt("Settings", "KeepFiles", 1, inifile);
	cutoff_depth = GetPrivateProfileInt("Settings", "CutOff", 0, inifile);
	dynamic_update = GetPrivateProfileInt("Settings", "DynamicUpdate", 1,
		inifile);
	maxdepth = GetPrivateProfileInt("Settings", "MaxDepth", MAXDEPTH,
		inifile);

	parse_editor_command(default_editor);

	/* Get initial directory */
	GetPrivateProfileString("Files", "CurrentDirectory", NULL, initial_dir,
		MAXPATHLEN, inifile);

	/* Set to current directory if not present */
	if(strlen(initial_dir) == 0)
		getcwd(initial_dir, MAXPATHLEN);

	/* cut off trailing slash */
	if(initial_dir[strlen(initial_dir) - 1] == '\\')
		initial_dir[strlen(initial_dir)-1] = '\0';
}
예제 #11
0
파일: server.c 프로젝트: txlife/cits3002-1
int main()
{
    struct sockaddr_in server;
    struct sockaddr_in dest;
    int socket_fd, client_fd,num;
    socklen_t size;
    SSL_CTX *ctx;
    /*******  START SSL ***************/
    /* http://mooon.blog.51cto.com/1246491/909932 */
    /* SSL Libraries Init */
    SSL_library_init();
    /* add all SSL algorithms */
    OpenSSL_add_all_algorithms();
    /* add all SSL ciphers */
    OpenSSL_add_all_ciphers();
    /* add all digests */
    OpenSSL_add_all_digests();
    /* load all SSL errors */
    SSL_load_error_strings();
    /* Build SSL_CTX  -> SSL Content Text 
     * SSLv2_server_method() or SSLv3_server_method() relative to SSL V2
     * and SSL V3
     */
    ctx = SSL_CTX_new(SSLv23_server_method());
    if(ctx == NULL){
        ERR_print_errors_fp(stdout);
        exit(EXIT_FAILURE);
    }
    /* Load the server certificate into the SSL_CTX structure */
    if(SSL_CTX_use_certificate_file(ctx,RSA_SERVER_CERT,SSL_FILETYPE_PEM) <= 0){
        ERR_print_errors_fp(stdout);
        exit(EXIT_FAILURE);
    } 
    /* Load the private-key corresponding to the server certificate */
    if(SSL_CTX_use_PrivateKey_file(ctx,RSA_SERVER_KEY,SSL_FILETYPE_PEM) <= 0){
        ERR_print_errors_fp(stdout);
        exit(EXIT_FAILURE);
    }
    /* Check if the server certificate and private-key matches */
    if(!SSL_CTX_check_private_key(ctx)){
        ERR_print_errors_fp(stdout);
        exit(EXIT_FAILURE);
    }

    /*********** END SSL ****************/

    int yes =1;

    /* Open a socket to listen */
    if ((socket_fd = socket(AF_INET, SOCK_STREAM, 0))== -1) {
        fprintf(stderr, "Socket failure!!\n");
        exit(EXIT_FAILURE);
    }

    if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1) {
        perror("setsockopt");
        exit(EXIT_FAILURE);
    }
    /* init memory for server and dest */
    memset(&server, 0, sizeof(server));
    memset(&dest,0,sizeof(dest));
    server.sin_family = AF_INET; //same to PF_INET
    server.sin_port = htons(PORT);
    server.sin_addr.s_addr = INADDR_ANY; 


    /* BIND SOCKET */
    if ((bind(socket_fd, (struct sockaddr *)&server, sizeof(struct sockaddr )))== -1)    { //sizeof(struct sockaddr) 
        fprintf(stderr, "Binding Failure\n");
        exit(EXIT_FAILURE);
    }

    /* START LISTENING */
    if ((listen(socket_fd, BACKLOG))== -1){
        fprintf(stderr, "Listening Failure\n");
        exit(EXIT_FAILURE);
    }
    while(1) {

        SSL *ssl;
        size = sizeof(struct sockaddr_in);

        /* Waiting for client to connect */
        if ((client_fd = accept(socket_fd, (struct sockaddr *)&dest, &size))==-1 ) {
            perror("accept");
            continue;
            //exit(EXIT_FAILURE);
        }
        else{
            printf("Server got connection from client %s, port %d, socket %d\n", inet_ntoa(dest.sin_addr),ntohs(dest.sin_port),client_fd);
        }
        /* /connection complete */

        /* create a new ssl based on ctx */
        ssl = SSL_new(ctx);
        /* add socket : client_fd to SSL */
        SSL_set_fd(ssl,client_fd);
        /* Build up SSL connection */
        if(SSL_accept(ssl) == -1){
            perror("accept");
            SSL_shutdown(ssl);
            SSL_free(ssl);
            close(client_fd);
            continue;
            //exit(EXIT_FAILURE);
        }


        /******* START PROCESSING DATA *************/

        /* read header - then do action based on header parsing */
        char header_buf[HEADER_SIZE];
        int len = HEADER_SIZE;
        if ((num = recv_all(ssl, (unsigned char *)header_buf, &len))== -1) {
            printf("Read header failed\n");
            perror("recv");
            SSL_shutdown(ssl);
            SSL_free(ssl);
            close(client_fd);
            continue;
            //exit(EXIT_FAILURE);
        }

        char *hr = NULL;
        hr = malloc(3);
        SSL_read(ssl, hr, sizeof(hr));
        if(strcmp("100",hr)){
            printf("Header receiving failed\n");
            SSL_write(ssl,"-1",strlen("-1"));
            /* Close SSL Connection */
            SSL_shutdown(ssl);
            /* Release SSL */
            SSL_free(ssl);
            //Close Connection Socket
            close(client_fd);
            continue;
        }
        else{
            printf("Header received successfully\n");
        }
        /* unpack header string */
        header h;
        if (unpack_header_string(header_buf, &h) == -1) {
            fprintf(stderr, "[SERVER] Could not unpack header information from client\n");
            h.action = FAIL_ERROR;
            //exit(EXIT_FAILURE);
        }

        if (h.action == FAIL_ERROR) {
            printf("Header action is FAIL ERROR\n");
            SSL_write(ssl,"-1",strlen("-1"));
            /* Close SSL Connection */
            SSL_shutdown(ssl);
            /* Release SSL */
            SSL_free(ssl);
            //Close Connection Socket
            close(client_fd);
            continue;
        }

        //inform client header unpacked successfully
        SSL_write(ssl,"100",strlen("100"));
        printf("Header unpacked successfully\n");

		// header part end
	    // if client requests to uplaod file
    	if (h.action == ADD_FILE) {
    		char *target = NULL;
            target = malloc(BLOCK_SIZE);
    		sprintf(target, "%s/%s", SERVER_FILE_DIR, h.file_name);
    		printf("[SERVER] Adding file %s\n", target);
    		receive_file(ssl, target, h.file_size);
            free(target);
    	} else if (h.action == FETCH_FILE) {
            char *target = NULL;
            target = malloc(BLOCK_SIZE);
            sprintf(target, "%s/%s", SERVER_FILE_DIR, h.file_name);
            printf("[SERVER] Fetching file %s\n", target);
            FILE *fp;
            if (!(fp = fopen(target, "r"))) {
                perror("fopen");
                /* Close SSL Connection */
                SSL_shutdown(ssl);
                /* Release SSL */
                SSL_free(ssl);
                //Close Connection Socket
                close(client_fd);
                continue;
                //exit(EXIT_FAILURE);
            }
            free(target);

            // get file's protection rating to compare to 
            // client's requested circumference 
            int protectionRating = getProtectionRating(h.file_name);

            header h_send;

            if (protectionRating >= h.circ) {    
                h_send.action = ADD_FILE;
            } else {
                h_send.action = FAIL_ERROR; // client will fail out
            }


            h_send.file_size = get_file_size(fp);
            h_send.file_name = h.file_name;
            h_send.certificate = " ";
            send_header(ssl, h_send);

            if (protectionRating >= h.circ) 
                send_file(ssl, fp);
            fclose(fp);
        }  else if (h.action == UPLOAD_CERT) {
            char target[MAXSIZE];
            sprintf(target, "%s/%s_crt.pem", SERVER_CERT_DIR, h.file_name);
            printf("Receiving cert and storing: %s\n", target);
            receive_file(ssl, target, h.file_size);
        }// if client requests to list files
	    else if (h.action == LIST_FILE) {
    		char **files;
    		size_t count;
    		unsigned int i;
    		count = file_list(SERVER_FILE_DIR, &files);
    		for (i = 0; i < count; i++) {
                char *send_str = NULL;
                send_str = malloc(MAXSIZE);
                int protectionRating = getProtectionRating(files[i]);
                if (protectionRating >= h.circ) {
                    sprintf(send_str, "Protected (c = %i): %s",protectionRating,files[i]);
                } else {
                    sprintf(send_str, "Unprotected (c = %i): %s",protectionRating,files[i]);
                }
                send_message(ssl, send_str);
                free(send_str);
    		}
    		printf("File list transmitting completed.\n");
    		close(client_fd);
    		printf("Client connection closed.\n");
	    }

        /* if client requires to vouch a file
         * https://gitorious.org/random_play/random_play/source/b9f19d4d9e8d4a9ba0ef55a6b0e2113d1c6a5587:openssl_sign.c
         */
        else if (h.action == VOUCH_FILE){
            // vouch for this file
            const char *clearTextFileName = h.file_name;
            int isCertFile = isNameCertFile(clearTextFileName);
            // vouch using this certificate
            char *certificate_file_name = h.certificate;
            char *cert_loc = NULL;
            cert_loc = malloc(MAXSIZE);
            sprintf(cert_loc, "%s/%s", SERVER_CERT_DIR, certificate_file_name);
            if (!check_if_file_exists(cert_loc)) {
                char *message = NULL;
                message = malloc(MAXSIZE);
                sprintf(message, "Unable to locate %s certificate on the server. Please upload using -a\n", cert_loc);
                SSL_write(ssl, message,strlen(message));
                free(message);
                /* Close SSL Connection */
                SSL_shutdown(ssl);
                /* Release SSL */
                SSL_free(ssl);
                //Close Connection Socket
                close(client_fd);
                continue;
                // should notify client here somehow
            }
            else{
                char *message = NULL;
                message = malloc(MAXSIZE);
                sprintf(message, "Located %s certificate on the server. \n", cert_loc);
                SSL_write(ssl, message,strlen(message));
                free(message);
            }
            free(cert_loc);
            char *target = NULL;
            target = malloc(MAXSIZE);

            if (isCertFile) {
                sprintf(target, "%s/%s", SERVER_CERT_DIR, h.file_name);
            } else {
                sprintf(target, "%s/%s", SERVER_FILE_DIR, h.file_name);
            }
            unsigned char *md5Value = NULL;
            md5Value = malloc(MD5_DIGEST_LENGTH);
            if(hashFile(md5Value, (const char *)target)!=0){
                printf("Couldn't open file");
                free(target);
                /* Close SSL Connection */
                SSL_shutdown(ssl);
                /* Release SSL */
                SSL_free(ssl);
                //Close Connection Socket
                close(client_fd);
                continue;
            }
            free(target);
            send_message(ssl, (char *)md5Value);

            unsigned char signature[MAXSIZE];
            SSL_read(ssl, signature, 128);
            char *sig_name = NULL;
            sig_name = malloc(MAXSIZE);

            // keep certificate signatures with certificates
            if (isCertFile) {
                sprintf(sig_name, "%s/%s_%s.sig", SERVER_CERT_DIR, clearTextFileName, certificate_file_name);
            } else {
                sprintf(sig_name, "%s/%s_%s.sig", SERVER_SIG_DIR, clearTextFileName, certificate_file_name);
            }

            if (writeSig(signature, sig_name) != 0) {
                fprintf(stderr, "Could not save signature file\n");
                free(sig_name);
                SSL_write(ssl,"-1",strlen("-1"));
                /* Close SSL Connection */
                SSL_shutdown(ssl);
                /* Release SSL */
                SSL_free(ssl);
                //Close Connection Socket
                close(client_fd);
                continue;
                //exit(EXIT_FAILURE);
            }
            else{
                printf("Sig loc: %s\n", sig_name);
                SSL_write(ssl,"100",strlen("100"));
            }
            free(sig_name);
        }

        else if (h.action == VERIFY_FILE){ // test verification of signature files
            char signatoryCertName[MAXSIZE];
            sprintf( signatoryCertName, "%s_crt.pem", h.certificate );
            const char *clearText = h.file_name;
            if(!verifySig(signatoryCertName,clearText)){
                printf("Verify failed\n");
            }
        } 
        else if (h.action == FIND_ISSUER){
            char certPath[MAXSIZE];
            sprintf( certPath, "%s", h.certificate );
        } 
        else if (h.action == TEST_RINGOFTRUST) {
            ringOfTrust(h.file_name);
        }

        /********** END DATA PROCESSING **************/
        free(h.certificate);
        free(h.file_name);
        /* Close SSL Connection */
        SSL_shutdown(ssl);
        /* Release SSL */
        SSL_free(ssl);
        //Close Connection Socket
        close(client_fd);
    } //Outer While

    /* Close listening socket */
    close(socket_fd);
    /* Release CTX */
    SSL_CTX_free(ctx);
    return 0;
} //End of main
//=====================================
// function calculates daylight factors
//=====================================
void getDaylightFactor( )
{
	float diffuse_dc[DAYLIGHT_COEFFICIENTS], overcast[DAYLIGHT_COEFFICIENTS], DZ[DAYLIGHT_COEFFICIENTS];
	int i,j,k;
	float ill_hor=101.5; /* outside horizontal irradiance under the CIE overcat sky at June 21st noon */
	char test_string[300]="";
	FILE *INPUT_FILE;

	//initialize arrays
	for (i = 0; i < DAYLIGHT_COEFFICIENTS; i++)
	{
		diffuse_dc[i]=0;
		overcast[i]=0;
	}


	//allocate menory for  daylight factor array
	daylight_factor=(float*) malloc (sizeof(float)*number_of_sensors);
	if (daylight_factor == NULL) error(SYSTEM, "out of memory in getDaylightFactor");
	for (i=0 ; i<number_of_sensors ; i++){
		daylight_factor[i]=0.0;
	}

	//initialize directiorns of diffuse daylight coefficients
	DZ[0] = DZ[1] = DZ[2] = DZ[3] = DZ[4] = DZ[5] = DZ[6] = DZ[7] = DZ[8] = DZ[9] = DZ[10] = DZ[11] = DZ[12] = DZ[13] = DZ[14] = DZ[15] = DZ[16] = DZ[17] = DZ[18] = DZ[19] = DZ[20] = DZ[21] = DZ[22] = DZ[23] = DZ[24] = DZ[25] = DZ[26] = DZ[27] = DZ[28] = DZ[29] = 0.104528f;
	DZ[30] = DZ[31] = DZ[32] = DZ[33] = DZ[34] = DZ[35] = DZ[36] = DZ[37] = DZ[38] = DZ[39] = DZ[40] = DZ[41] = DZ[42] = DZ[43] = DZ[44] = DZ[45] = DZ[46] = DZ[47] = DZ[48] = DZ[49] = DZ[50] = DZ[51] = DZ[52] = DZ[53] = DZ[54] = DZ[55] = DZ[56] = DZ[57] = DZ[58] = DZ[59] = 0.309017f;
	DZ[60] = DZ[61] = DZ[62] = DZ[63] = DZ[64] = DZ[65] = DZ[66] = DZ[67] = DZ[68] = DZ[69] = DZ[70] = DZ[71] = DZ[72] = DZ[73] = DZ[74] = DZ[75] = DZ[76] = DZ[77] = DZ[78] = DZ[79] = DZ[80] = DZ[81] = DZ[82] = DZ[83] = 0.500000f;
	DZ[84] = DZ[85] = DZ[86] = DZ[87] = DZ[88] = DZ[89] = DZ[90] = DZ[91] = DZ[92] = DZ[93] = DZ[94] = DZ[95] = DZ[96] = DZ[97] = DZ[98] = DZ[99] = DZ[100] = DZ[101] = DZ[102] = DZ[103] = DZ[104] = DZ[105] = DZ[106] = DZ[107] = 0.669131f;
	DZ[108] = DZ[109] = DZ[110] = DZ[111] = DZ[112] = DZ[113] = DZ[114] = DZ[115] = DZ[116] = DZ[117] = DZ[118] = DZ[119] = DZ[120] = DZ[121] = DZ[122] = DZ[123] = DZ[124] = DZ[125] = 0.809017f;
	DZ[126] = DZ[127] = DZ[128] = DZ[129] = DZ[130] = DZ[131] = DZ[132] = DZ[133] = DZ[134] = DZ[135] = DZ[136] = DZ[137] = 0.913545f;
	DZ[138] = DZ[139] = DZ[140] = DZ[141] = DZ[142] = DZ[143] = 0.978148f;
	DZ[144] = 1.0f;
	DZ[145] = -0.087156f;
	DZ[146] = -0.342f;
	DZ[147] = -1.0f;

	//calculate luminances of diffuse sky patches
	for (i = 0; i < DAYLIGHT_COEFFICIENTS; i++) {
		overcast[i] = (float)(CIE_SKY(DZ[i]) / ill_hor);
	}

	//open DC input files
	if(!check_if_file_exists(shading_dc_file[1]))
	{
		sprintf(errmsg, "%s does not exist", shading_dc_file[1]);
		error(WARNING, errmsg);
	}else{
		INPUT_FILE=open_input(shading_dc_file[1]);
		for (j=0 ; j<number_of_sensors ; j++){
				/* read in daylight coefficients */
				fscanf(INPUT_FILE,"%s ",test_string);
				while(test_string[0] == '#'){
					fscanf(INPUT_FILE,"%*[^\n]");
					fscanf(INPUT_FILE,"%*[\n\r]");
					fscanf(INPUT_FILE,"%s ",test_string);
				}
				diffuse_dc[0] = (float)atof(test_string);

				for (k = 1; k < DAYLIGHT_COEFFICIENTS; k++)
					fscanf(INPUT_FILE,"%f ",&diffuse_dc[k]);
				fscanf(INPUT_FILE,"%*[^\n]");
				fscanf(INPUT_FILE,"%*[\n\r]");

				/* calculate daylight factor */
				for (k = 0; k < DAYLIGHT_COEFFICIENTS; k++)
	        	{
	        		daylight_factor[j]+=diffuse_dc[k]*overcast[k];
	        	}
				//printf("\n\n");
	        	daylight_factor[j]*=100.0;
		}

		// close DC file
		fclose(INPUT_FILE);
	}


}