Date: 10/09/98
- Next message: agarcia <email protected>: "[PHP-DEV] Bug #838: Parser error in nested if"
- Previous message: Thies C. Arntzen: "Re: [PHP-DEV] Speed improvements for GetImageSize? & IPTC Reader"
- Next in thread: ssb: "[PHP-DEV] CVS update: php3/functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Friday October 9, 1998 @ 3:56
Author: steinm
Update of /repository/php3/functions
In directory asf:/u2/tmp/cvs-serv28945/functions
Modified Files:
hg_comm.c hw.c
Log Message:
Better error reporting when opening a connection to Hyperwave fails
Index: php3/functions/hg_comm.c
diff -c php3/functions/hg_comm.c:1.8 php3/functions/hg_comm.c:1.9
*** php3/functions/hg_comm.c:1.8 Sat Oct 3 15:10:13 1998
--- php3/functions/hg_comm.c Fri Oct 9 03:56:09 1998
***************
*** 23,29 ****
+----------------------------------------------------------------------+
*/
! /* $Id: hg_comm.c,v 1.8 1998/10/03 19:10:13 shane Exp $ */
/* #define HW_DEBUG */
--- 23,29 ----
+----------------------------------------------------------------------+
*/
! /* $Id: hg_comm.c,v 1.9 1998/10/09 07:56:09 steinm Exp $ */
/* #define HW_DEBUG */
***************
*** 923,929 ****
struct sockaddr_in server_addr;
struct hostent *hp;
if ( (hp = gethostbyname(server_name)) == NULL ) {
- /* php3_error(E_WARNING, "gethostbyname failed for %s", server_name); */
return(-1);
}
--- 923,928 ----
***************
*** 936,943 ****
bcopy(hp->h_addr, (char *) &server_addr.sin_addr, hp->h_length);
if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) {
! /* php3_error(E_WARNING, "socket"); */
! return(-1);
}
#if defined(SUN) || (WIN32|WINNT)
--- 935,941 ----
bcopy(hp->h_addr, (char *) &server_addr.sin_addr, hp->h_length);
if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) {
! return(-2);
}
#if defined(SUN) || (WIN32|WINNT)
***************
*** 947,964 ****
#endif SUN
if (connect(sockfd, (struct sockaddr *) &server_addr, sizeof(server_addr)) < 0) {
- /* php3_error(E_WARNING, "connect"); */
close(sockfd);
! return(-1);
}
#if !(WIN32|WINNT)
if ( (sock_flags = fcntl(sockfd, F_GETFL, 0)) == -1 )
- /* php3_error(E_WARNING, "open_hg_connection: F_GETFL"); */
#endif
if ( set_nonblocking(sockfd) == -1 ) {
! return(-1);
}
return(sockfd);
--- 945,960 ----
#endif SUN
if (connect(sockfd, (struct sockaddr *) &server_addr, sizeof(server_addr)) < 0) {
close(sockfd);
! return(-3);
}
#if !(WIN32|WINNT)
if ( (sock_flags = fcntl(sockfd, F_GETFL, 0)) == -1 )
#endif
if ( set_nonblocking(sockfd) == -1 ) {
! return(-4);
}
return(sockfd);
***************
*** 980,1010 ****
*do_swap = 0;
buf = 'T';
if ( hg_write(sockfd, &buf, 1) == -1 ) {
! /* php3_error(E_WARNING, "initialize_hg_connection: hg_write (1) returned -1\n"); */
! return(-1);
}
if ( hg_read_exact(sockfd, &buf, 1) == -1 ) {
! /* php3_error(E_WARNING, "initialize_hg_connection: hg_read (1) returned -1\n"); */
! return(-1);
}
if ( buf == 'F' ) {
! /* php3_error(E_WARNING, "initialize_hg_connection: got >>F<< from server\n"); */
! return(-1);
}
if ( buf != 'T' ) {
! /* php3_error(E_WARNING, "initialize_hg_connection: neither >>F<< nor >>T<< from server\n"); */
! return(-1);
}
buf = c = ( *(char *)&i ) ? 'l' : 'B';
if ( hg_write(sockfd, &buf, 1) == -1 ) {
! /* php3_error(E_WARNING, "initialize_hg_connection: hg_write (2) returned -1\n"); */
! return(-1);
}
if ( hg_read_exact(sockfd, &buf, 1) == -1 ) {
! /* php3_error(E_WARNING, "initialize_hg_connection: hg_read (2) returned -1\n"); */
! return(-1);
}
if ( c != buf ) {
swap_on = 1;
--- 976,1000 ----
*do_swap = 0;
buf = 'T';
if ( hg_write(sockfd, &buf, 1) == -1 ) {
! return(-2);
}
if ( hg_read_exact(sockfd, &buf, 1) == -1 ) {
! return(-3);
}
if ( buf == 'F' ) {
! return(-4);
}
if ( buf != 'T' ) {
! return(-5);
}
buf = c = ( *(char *)&i ) ? 'l' : 'B';
if ( hg_write(sockfd, &buf, 1) == -1 ) {
! return(-6);
}
if ( hg_read_exact(sockfd, &buf, 1) == -1 ) {
! return(-7);
}
if ( c != buf ) {
swap_on = 1;
***************
*** 1015,1039 ****
}
if ( send_ready(sockfd) == -1) {
! /* php3_error(E_WARNING, "send ready msg returned -1"); */
! return(-1);
}
/* Receive return from Ready message */
if ( (ready_msg = recv_ready(sockfd)) == NULL ) {
! /* php3_error(E_WARNING, "initialize_hg_connection: recv_ready returned NULL\n"); */
! return(-1);
}
if ((ready_msg->version_msgid & F_VERSION) < VERSION)
! return -1;
*version = ready_msg->version_msgid;
*server_string = strdup(ready_msg->buf+4);
efree(ready_msg->buf);
efree(ready_msg);
! /* If we have a username and password then do the identification. */
! if((NULL != username) && (NULL != password)) {
length = HEADER_LENGTH + sizeof(int) + strlen(username) + 1 + strlen(password) + 1;
build_msg_header(&msg, length, msgid++, IDENTIFY_MESSAGE);
--- 1005,1027 ----
}
if ( send_ready(sockfd) == -1) {
! return(-8);
}
/* Receive return from Ready message */
if ( (ready_msg = recv_ready(sockfd)) == NULL ) {
! return(-9);
}
if ((ready_msg->version_msgid & F_VERSION) < VERSION)
! return(-8);
*version = ready_msg->version_msgid;
*server_string = strdup(ready_msg->buf+4);
efree(ready_msg->buf);
efree(ready_msg);
! /* If we have a username and password then do the identification. */
! if((NULL != username) && (NULL != password)) {
length = HEADER_LENGTH + sizeof(int) + strlen(username) + 1 + strlen(password) + 1;
build_msg_header(&msg, length, msgid++, IDENTIFY_MESSAGE);
***************
*** 1049,1064 ****
if ( send_hg_msg(sockfd, &msg, length) == -1 ) {
efree(msg.buf);
! return(-1);
}
efree(msg.buf);
}
! if((NULL != username) && (NULL != password)) {
/* Receive return form identify message */
retmsg = recv_hg_msg(sockfd);
if ( retmsg == NULL )
! return(-1);
*userdata = retmsg->buf;
efree(retmsg);
--- 1037,1052 ----
if ( send_hg_msg(sockfd, &msg, length) == -1 ) {
efree(msg.buf);
! return(-10);
}
efree(msg.buf);
}
! if((NULL != username) && (NULL != password)) {
/* Receive return form identify message */
retmsg = recv_hg_msg(sockfd);
if ( retmsg == NULL )
! return(-11);
*userdata = retmsg->buf;
efree(retmsg);
Index: php3/functions/hw.c
diff -c php3/functions/hw.c:1.13 php3/functions/hw.c:1.14
*** php3/functions/hw.c:1.13 Wed Oct 7 07:57:07 1998
--- php3/functions/hw.c Fri Oct 9 03:56:09 1998
***************
*** 23,29 ****
+----------------------------------------------------------------------+
*/
! /* $Id: hw.c,v 1.13 1998/10/07 11:57:07 steinm Exp $ */
#if COMPILE_DL
#include "dl/phpdl.h"
#endif
--- 23,29 ----
+----------------------------------------------------------------------+
*/
! /* $Id: hw.c,v 1.14 1998/10/09 07:56:09 steinm Exp $ */
#if COMPILE_DL
#include "dl/phpdl.h"
#endif
***************
*** 448,499 ****
/* Host: */
convert_to_string(argv[0]);
! if (argv[0]->value.str.val) {
! host = (char *) estrndup(argv[0]->value.str.val,argv[0]->value.str.len);
! } else {
! php3_error(E_WARNING, "No hostname given");
! if(host) efree(host);
! RETURN_FALSE;
! }
/* Port: */
convert_to_long(argv[1]);
! if (argv[1]->value.lval) {
! port = argv[1]->value.lval;
! } else {
! php3_error(E_WARNING, "No port number given");
! RETURN_FALSE;
! }
/* Username and Password */
if(argc > 2) {
/* Username */
convert_to_string(argv[2]);
! if (argv[2]->value.str.val) {
! username = (char *) estrndup(argv[2]->value.str.val,argv[2]->value.str.len);
! } else {
! php3_error(E_WARNING, "No username given");
! if(username) efree(username);
! RETURN_FALSE;
! }
!
/* Password */
convert_to_string(argv[3]);
! if (argv[3]->value.str.val) {
! password = (char *) estrndup(argv[3]->value.str.val,argv[3]->value.str.len);
! } else {
! php3_error(E_WARNING, "No password given");
! if(password) efree(password);
! RETURN_FALSE;
! }
}
/* Create identifier string for connection */
sprintf(buffer, "%d", port);
hashed_details_length = strlen(host)+strlen(buffer)+8;
if(NULL == (hashed_details = (char *) emalloc(hashed_details_length+1))) {
if(password) efree(password);
if(username) efree(username);
RETURN_FALSE;
}
sprintf(hashed_details,"hw_%s_%d",host,port);
--- 448,477 ----
/* Host: */
convert_to_string(argv[0]);
! host = (char *) estrndup(argv[0]->value.str.val,argv[0]->value.str.len);
/* Port: */
convert_to_long(argv[1]);
! port = argv[1]->value.lval;
/* Username and Password */
if(argc > 2) {
/* Username */
convert_to_string(argv[2]);
! username = (char *) estrndup(argv[2]->value.str.val,argv[2]->value.str.len);
/* Password */
convert_to_string(argv[3]);
! password = (char *) estrndup(argv[3]->value.str.val,argv[3]->value.str.len);
}
/* Create identifier string for connection */
sprintf(buffer, "%d", port);
hashed_details_length = strlen(host)+strlen(buffer)+8;
if(NULL == (hashed_details = (char *) emalloc(hashed_details_length+1))) {
+ if(host) efree(host);
if(password) efree(password);
if(username) efree(username);
+ php3_error(E_ERROR, "Could not get memory for connection details");
RETURN_FALSE;
}
sprintf(hashed_details,"hw_%s_%d",host,port);
***************
*** 506,512 ****
list_entry new_le;
if (php3_hw_module.max_links!=-1 && php3_hw_module.num_links>=php3_hw_module.max_links) {
! php3_error(E_WARNING,"Hyperwave: Too many open links (%d)",php3_hw_module.num_links);
if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
--- 484,490 ----
list_entry new_le;
if (php3_hw_module.max_links!=-1 && php3_hw_module.num_links>=php3_hw_module.max_links) {
! php3_error(E_ERROR,"Hyperwave: Too many open links (%d)",php3_hw_module.num_links);
if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
***************
*** 514,520 ****
RETURN_FALSE;
}
if (php3_hw_module.max_persistent!=-1 && php3_hw_module.num_persistent>=php3_hw_module.max_persistent) {
! /* php3_error(E_WARNING,"Hyperwave: Too many open persistent links (%d)",php3_hw_module.num_persistent); */
if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
--- 492,498 ----
RETURN_FALSE;
}
if (php3_hw_module.max_persistent!=-1 && php3_hw_module.num_persistent>=php3_hw_module.max_persistent) {
! php3_error(E_ERROR,"Hyperwave: Too many open persistent links (%d)",php3_hw_module.num_persistent);
if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
***************
*** 523,529 ****
}
if ( (sockfd = open_hg_connection(host, port)) < 0 ) {
! /* php3_error(E_WARNING, "open_hg_connection to %s (%d)returned -1", host, port); */
if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
--- 501,507 ----
}
if ( (sockfd = open_hg_connection(host, port)) < 0 ) {
! php3_error(E_ERROR, "Could not open connection to %s, Port: %d (retval=%d)", host, port, sockfd);
if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
***************
*** 532,537 ****
--- 510,516 ----
}
if(NULL == (ptr = malloc(sizeof(hw_connection)))) {
+ php3_error(E_ERROR, "Could not get memory for connection structure");
if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
***************
*** 540,546 ****
}
if(0 != (ptr->lasterror = initialize_hg_connection(sockfd, &do_swap, &version, &userdata, &server_string, username, password))) {
! /* php3_error(E_WARNING, "initalize hg connection returned -1"); */
if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
--- 519,525 ----
}
if(0 != (ptr->lasterror = initialize_hg_connection(sockfd, &do_swap, &version, &userdata, &server_string, username, password))) {
! php3_error(E_ERROR, "Could not initalize hyperwave connection");
if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
***************
*** 565,570 ****
--- 544,550 ----
new_le.type = php3_hw_module.le_psocketp;;
if (_php3_hash_update(plist,hashed_details,hashed_details_length+1,(void *) &new_le, sizeof(list_entry), NULL)==FAILURE) {
+ php3_error(E_ERROR, "Could not hash table with connection details");
if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
***************
*** 590,597 ****
list_entry *index_ptr,new_index_ptr;
/* first we check the hash for the hashed_details key. if it exists,
! * it should point us to the right offset where the actual pgsql link sits.
! * if it doesn't, open a new pgsql link, add it to the resource list,
* and add a pointer to it with hashed_details as the key.
*/
if (_php3_hash_find(list,hashed_details,hashed_details_length+1,(void **) &index_ptr)==SUCCESS) {
--- 570,577 ----
list_entry *index_ptr,new_index_ptr;
/* first we check the hash for the hashed_details key. if it exists,
! * it should point us to the right offset where the actual hyperwave link sits.
! * if it doesn't, open a new hyperwave link, add it to the resource list,
* and add a pointer to it with hashed_details as the key.
*/
if (_php3_hash_find(list,hashed_details,hashed_details_length+1,(void **) &index_ptr)==SUCCESS) {
***************
*** 609,615 ****
efree(hashed_details);
if(username) efree(username);
if(password) efree(password);
! if(host) efree(host);
return;
} else {
_php3_hash_del(list,hashed_details,hashed_details_length+1);
--- 589,595 ----
efree(hashed_details);
if(username) efree(username);
if(password) efree(password);
! if(host) efree(host);
return;
} else {
_php3_hash_del(list,hashed_details,hashed_details_length+1);
***************
*** 617,624 ****
}
if ( (sockfd = open_hg_connection(host, port)) < 0 ) {
! /* php3_error(E_WARNING, "open_hg_connection returned -1");*/
! if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
efree(hashed_details);
--- 597,604 ----
}
if ( (sockfd = open_hg_connection(host, port)) < 0 ) {
! php3_error(E_ERROR, "Could not open connection to %s, Port: %d (retval=%d", host, port, sockfd);
! if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
efree(hashed_details);
***************
*** 634,640 ****
}
if(0 != (ptr->lasterror = initialize_hg_connection(sockfd, &do_swap, &version, &userdata, &server_string, username, password))) {
! /* php3_error(E_WARNING, "initalize hg connection returned -1"); */
if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
--- 614,620 ----
}
if(0 != (ptr->lasterror = initialize_hg_connection(sockfd, &do_swap, &version, &userdata, &server_string, username, password))) {
! php3_error(E_ERROR, "Could not initalize hyperwave connection");
if(host) efree(host);
if(username) efree(username);
if(password) efree(password);
***************
*** 661,666 ****
--- 641,648 ----
new_index_ptr.ptr = (void *) return_value->value.lval;
new_index_ptr.type = le_index_ptr;
if (_php3_hash_update(list,hashed_details,hashed_details_length+1,(void *) &new_index_ptr, sizeof(list_entry), NULL)==FAILURE) {
+ php3_error(E_ERROR, "Could not update connection details in hash table");
+ if(host) efree(host);
efree(hashed_details);
RETURN_FALSE;
}
***************
*** 671,677 ****
if(host) efree(host);
php3_hw_module.default_link=return_value->value.lval;
! /* If there is no userdata because hw_connect was called without username
and password, we don't evaluate userdata.
*/
if(NULL == userdata)
--- 653,661 ----
if(host) efree(host);
php3_hw_module.default_link=return_value->value.lval;
! /* At this point we have a working connection. If userdata was given
! we are also indentified.
! If there is no userdata because hw_connect was called without username
and password, we don't evaluate userdata.
*/
if(NULL == userdata)
-- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe <email protected> For help: php-dev-help <email protected>
- Next message: agarcia <email protected>: "[PHP-DEV] Bug #838: Parser error in nested if"
- Previous message: Thies C. Arntzen: "Re: [PHP-DEV] Speed improvements for GetImageSize? & IPTC Reader"
- Next in thread: ssb: "[PHP-DEV] CVS update: php3/functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

