| 394 | | static void |
|---|
| 395 | | foreach_callback_soapx(GMimeObject *part, gpointer user_data) |
|---|
| 396 | | { |
|---|
| 397 | | const char* content_id = NULL; |
|---|
| 398 | | GMimeDataWrapper *content; |
|---|
| 399 | | const char *filename; |
|---|
| 400 | | GMimeStream *stream; |
|---|
| 401 | | int fd2; |
|---|
| 402 | | |
|---|
| 403 | | content_id = g_mime_part_get_content_id((GMimePart *)part); |
|---|
| 404 | | |
|---|
| 405 | | /* The first mime part has no content id. That is where the SOAP message is. */ |
|---|
| 406 | | if (content_id != NULL) { |
|---|
| 407 | | return; |
|---|
| 408 | | } |
|---|
| 409 | | |
|---|
| 410 | | if ((fd2 = open (soap_file_path, O_CREAT | O_WRONLY | O_TRUNC, 0666)) == -1) { |
|---|
| 411 | | fprintf(stdout, "ERRROR creating output file"); |
|---|
| 412 | | return; |
|---|
| 413 | | } |
|---|
| 414 | | |
|---|
| 415 | | /* writing the content to the soap file path */ |
|---|
| 416 | | stream = g_mime_stream_fs_new (fd2); |
|---|
| 417 | | content = g_mime_part_get_content_object ((GMimePart*)part); |
|---|
| 418 | | g_mime_data_wrapper_write_to_stream (content, stream); |
|---|
| 419 | | g_mime_stream_flush (stream); |
|---|
| 420 | | |
|---|
| 421 | | g_object_unref (content); |
|---|
| 422 | | g_object_unref (stream); |
|---|
| 423 | | |
|---|
| 424 | | close(fd2); |
|---|
| 425 | | |
|---|
| 426 | | soap_message_read_done = 1; |
|---|
| 427 | | |
|---|
| 428 | | } |
|---|
| 429 | | |
|---|
| 456 | | fprintf(stdout, "Writing this mess: %s", text); |
|---|
| | 424 | if (debug == 1) |
|---|
| | 425 | fprintf(stdout, "Writing this mess: %s", text); |
|---|
| | 426 | |
|---|
| | 427 | FILE* output_file = NULL; |
|---|
| | 428 | // char* file_name = "/tmp/final_output_soap_file"; |
|---|
| | 429 | if ((output_file = fopen(final_output_file_name, "w")) == NULL) |
|---|
| | 430 | fprintf(stderr, "Cannot open %s to write soap message.\n", final_output_file_name); |
|---|
| | 431 | |
|---|
| | 432 | fprintf(output_file, "%s", text); |
|---|
| | 433 | |
|---|
| | 434 | fclose(output_file); |
|---|
| | 435 | |
|---|
| | 436 | g_free (text); |
|---|
| | 437 | g_mime_object_unref (GMIME_OBJECT (message)); |
|---|
| | 438 | |
|---|
| | 439 | xmlFree(signed_soap_mem); |
|---|
| | 440 | return 0; |
|---|
| | 441 | |
|---|
| | 442 | } |
|---|
| | 443 | |
|---|
| | 444 | int replace_soap_header_y(const char* original_multipart_mime_file, const char* signed_soap_file_name, const char* final_output_file_name){ |
|---|
| | 445 | GMimeMessage* message; |
|---|
| | 446 | int fd; |
|---|
| | 447 | |
|---|
| | 448 | if ((fd = open (multipart_mime_file, O_RDONLY)) == -1) { |
|---|
| | 449 | fprintf (stderr, "Cannot open message `%s': %s to write soap message.\n", multipart_mime_file, strerror (errno)); |
|---|
| | 450 | // return -1; |
|---|
| | 451 | } |
|---|
| | 452 | |
|---|
| | 453 | message = parse_message(fd); |
|---|
| | 454 | close(fd); |
|---|
| | 455 | |
|---|
| | 456 | GMimeObject* part = NULL; |
|---|
| | 457 | part = g_mime_message_get_mime_part(message); |
|---|
| | 458 | GMimeMultipart* multipart = (GMimeMultipart*) part; |
|---|
| | 459 | |
|---|
| | 460 | GMimePart* soap = (GMimePart*) g_mime_multipart_get_part(multipart, 0); |
|---|
| | 461 | |
|---|
| | 462 | FILE * pFile; |
|---|
| | 463 | long lSize; |
|---|
| | 464 | char * buffer; |
|---|
| | 465 | size_t result; |
|---|
| | 466 | |
|---|
| | 467 | pFile = fopen ( signed_soap_file_name , "rb" ); |
|---|
| | 468 | if (pFile==NULL) {fputs ("File error",stderr); return (-1);} |
|---|
| | 469 | |
|---|
| | 470 | // obtain file size: |
|---|
| | 471 | fseek (pFile , 0 , SEEK_END); |
|---|
| | 472 | lSize = ftell (pFile); |
|---|
| | 473 | rewind (pFile); |
|---|
| | 474 | |
|---|
| | 475 | // allocate memory to contain the whole file: |
|---|
| | 476 | buffer = (char*) malloc (sizeof(char)*lSize); |
|---|
| | 477 | if (buffer == NULL) {fputs ("Memory error",stderr); return (-2);} |
|---|
| | 478 | |
|---|
| | 479 | // copy the file into the buffer: |
|---|
| | 480 | result = fread (buffer,1,lSize,pFile); |
|---|
| | 481 | if (result != lSize) {fputs ("Reading error",stderr); return (-3);} |
|---|
| | 482 | |
|---|
| | 483 | /* the whole file is now loaded in the memory buffer. */ |
|---|
| | 484 | |
|---|
| | 485 | fprintf(stdout, "Before strlen: replace soap header_y"); |
|---|
| | 486 | g_mime_part_set_content(soap, buffer, strlen(buffer)); |
|---|
| | 487 | |
|---|
| | 488 | char* text; |
|---|
| | 489 | text = g_mime_message_to_string (message); |
|---|
| | 490 | |
|---|
| | 491 | if (debug == 1) |
|---|
| | 492 | fprintf(stdout, "Writing this message: %s", text); |
|---|
| 468 | | xmlFree(signed_soap_mem); |
|---|
| 469 | | return 0; |
|---|
| 470 | | |
|---|
| 471 | | } |
|---|
| 472 | | |
|---|
| 473 | | int replace_soap_header_y(const char* original_multipart_mime_file, const char* signed_soap_file_name, const char* final_output_file_name){ |
|---|
| 474 | | GMimeMessage* message; |
|---|
| 475 | | int fd; |
|---|
| 476 | | |
|---|
| 477 | | if ((fd = open (multipart_mime_file, O_RDONLY)) == -1) { |
|---|
| 478 | | fprintf (stderr, "Cannot open message `%s': %s to write soap message.\n", multipart_mime_file, strerror (errno)); |
|---|
| 479 | | // return -1; |
|---|
| 480 | | } |
|---|
| 481 | | |
|---|
| 482 | | message = parse_message(fd); |
|---|
| 483 | | close(fd); |
|---|
| 484 | | |
|---|
| 485 | | GMimeObject* part = NULL; |
|---|
| 486 | | part = g_mime_message_get_mime_part(message); |
|---|
| 487 | | GMimeMultipart* multipart = (GMimeMultipart*) part; |
|---|
| 488 | | |
|---|
| 489 | | GMimePart* soap = (GMimePart*) g_mime_multipart_get_part(multipart, 0); |
|---|
| 490 | | |
|---|
| 491 | | fprintf(stdout, "HHHHHHHHHHHHHHHELO\n"); |
|---|
| 492 | | fprintf(stdout, "HHHHHHHHHHHHHHHELO\n"); |
|---|
| 493 | | fprintf(stdout, "HHHHHHHHHHHHHHHELO\n"); |
|---|
| 494 | | |
|---|
| 495 | | FILE * pFile; |
|---|
| 496 | | long lSize; |
|---|
| 497 | | char * buffer; |
|---|
| 498 | | size_t result; |
|---|
| 499 | | |
|---|
| 500 | | pFile = fopen ( signed_soap_file_name , "rb" ); |
|---|
| 501 | | if (pFile==NULL) {fputs ("File error",stderr); return (-1);} |
|---|
| 502 | | |
|---|
| 503 | | // obtain file size: |
|---|
| 504 | | fseek (pFile , 0 , SEEK_END); |
|---|
| 505 | | lSize = ftell (pFile); |
|---|
| 506 | | rewind (pFile); |
|---|
| 507 | | |
|---|
| 508 | | // allocate memory to contain the whole file: |
|---|
| 509 | | buffer = (char*) malloc (sizeof(char)*lSize); |
|---|
| 510 | | if (buffer == NULL) {fputs ("Memory error",stderr); return (-2);} |
|---|
| 511 | | |
|---|
| 512 | | // copy the file into the buffer: |
|---|
| 513 | | result = fread (buffer,1,lSize,pFile); |
|---|
| 514 | | if (result != lSize) {fputs ("Reading error",stderr); return (-3);} |
|---|
| 515 | | |
|---|
| 516 | | /* the whole file is now loaded in the memory buffer. */ |
|---|
| 517 | | |
|---|
| 518 | | |
|---|
| 519 | | fprintf(stdout, "HHHHHHHHHHHHHHHELO\n"); |
|---|
| 520 | | fprintf(stdout, "Before strlen: replace soap header_y"); |
|---|
| 521 | | g_mime_part_set_content(soap, buffer, strlen(buffer)); |
|---|
| 522 | | |
|---|
| 523 | | char* text; |
|---|
| 524 | | text = g_mime_message_to_string (message); |
|---|
| 525 | | |
|---|
| 526 | | fprintf(stdout, "Writing this mess: %s", text); |
|---|
| 527 | | |
|---|
| 528 | | FILE* output_file = NULL; |
|---|
| 529 | | // char* file_name = "/tmp/final_output_soap_file"; |
|---|
| 530 | | if ((output_file = fopen(final_output_file_name, "w")) == NULL) |
|---|
| 531 | | fprintf(stderr, "Cannot open %s to write soap message.\n", final_output_file_name); |
|---|
| 532 | | fprintf(output_file, "%s", text); |
|---|
| 533 | | fclose(output_file); |
|---|
| 534 | | |
|---|
| 535 | | g_free (text); |
|---|
| 536 | | g_mime_object_unref (GMIME_OBJECT (message)); |
|---|
| 537 | | |
|---|