Convert uses of XKeycodeToKeysym (deprecated) to XkbKeycodeToKeysym
[oweals/cde.git] / cde / lib / DtSvc / DtEncap / spc-proto.c
index 33a3981d43b61fc6b6d7281603267cad6b8127f3..1d929b8ed51ecb1c523e3bd09dcd3c7eadf1917b 100644 (file)
@@ -16,7 +16,7 @@
  * details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with these librararies and programs; if not, write
+ * License along with these libraries and programs; if not, write
  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  * Floor, Boston, MA 02110-1301 USA
  */
@@ -41,6 +41,7 @@
 #include <stdarg.h>
 #include <sys/utsname.h>
 #include <limits.h>
+#include <stdint.h>
 
 #define X_INCLUDE_PWD_H
 #define XOS_USE_XT_LOCKING
@@ -189,7 +190,7 @@ SPC_Connection_Ptr SPC_Alloc_Connection(void)
   _DtSvcProcessLock();
   conn=(SPC_Connection_Ptr) XeMalloc(sizeof(SPC_Connection));
   /* Zero the connection */
-  memset(conn, NULL, sizeof(SPC_Connection));
+  memset(conn, 0, sizeof(SPC_Connection));
   conn->queued_remote_data = Xe_make_queue(FALSE);
   conn->termination_id = (-1);
   /* Init the socket id to "-1" because "0" is a valid file descriptor. */
@@ -439,7 +440,7 @@ protocol_request_ptr SPC_Read_Protocol(SPC_Connection_Ptr connection)
   if(!connection->connected)
     return(SPC_ERROR);
   
-  if((prot=SPC_New_Protocol_Ptr(NULL, NULL, NULL))==SPC_ERROR) {
+  if((prot=SPC_New_Protocol_Ptr(NULL, 0, 0))==SPC_ERROR) {
     SPC_Close_Connection(connection);
     return(SPC_ERROR);
   }
@@ -586,8 +587,8 @@ void SPC_Flush_Queued_Data(SPC_Channel_Ptr channel)
   XeQueue tmpqueue;
   protocol_request_ptr prot;
   
-  if(tmpqueue=channel->queued_remote_data) {
-    while(prot=(protocol_request_ptr)Xe_pop_queue(tmpqueue))
+  if((tmpqueue=channel->queued_remote_data)) {
+    while((prot=(protocol_request_ptr)Xe_pop_queue(tmpqueue)))
       SPC_Free_Protocol_Ptr(prot);
   }
 
@@ -652,7 +653,7 @@ int print_protocol_request(XeString name, protocol_request_ptr proto)
   dptr->data[dptr->offset+dptr->len]=0;
   
   fprintf(SPC_Print_Protocol,
-         "%s channel: %x, request: %d, length: %d, seq: %d data: %s\n",
+         "%s channel: %p, request: %d, length: %d, seq: %d data: %s\n",
          name, proto->channel, proto->request_type, dptr->len, proto->seqno,
          dptr->data+dptr->offset);
 
@@ -691,7 +692,7 @@ int SPC_Write_Protocol_Request (SPC_Connection_Ptr connection,
   /* We are overloading the "channel" field.  We put the cid rather  */
   /* than the actual channel pointer in when we pass it to the other */
   /* side of the connection.                                        */
-  prot_request->channel=(SPC_Channel_Ptr)(channel ? channel->cid : 0);
+  prot_request->channel=(SPC_Channel_Ptr) (intptr_t) (channel ? channel->cid : 0);
   
   switch (request) {
 
@@ -767,8 +768,10 @@ int SPC_Write_Protocol_Request (SPC_Connection_Ptr connection,
     envp=va_arg(ap, XeString *);
     va_end(ap);
     pdata->len=WRITE_APPLICATION_SPAWN(pdata, path, dir, argv, envp);
-    if(pdata->len == SPC_ERROR)
+    if(pdata->len == SPC_ERROR) {
+      SPC_Free_Protocol_Ptr(prot_request);
       return(SPC_ERROR);
+    }
     prot_name=(XeString)"  <-- APPLICATION_SPAWN";
     break;
     }
@@ -928,6 +931,7 @@ int SPC_Write_Protocol_Request (SPC_Connection_Ptr connection,
     if(connection->protocol_version < 3) {
       SPC_Error(SPC_Protocol_Version_Error,
                3, channel->connection->protocol_version);
+      SPC_Free_Protocol_Ptr(prot_request);
       return(SPC_ERROR);
     }
   
@@ -939,6 +943,7 @@ int SPC_Write_Protocol_Request (SPC_Connection_Ptr connection,
     if(connection->protocol_version < 3) {
       SPC_Error(SPC_Protocol_Version_Error,
                3, channel->connection->protocol_version);
+      SPC_Free_Protocol_Ptr(prot_request);
       return(SPC_ERROR);
     }
   
@@ -957,6 +962,7 @@ int SPC_Write_Protocol_Request (SPC_Connection_Ptr connection,
       buffer = SPC_Decode_Termios(termios_ptr);
       pdata->len=WRITE_TERMIOS(pdata, connector, side, buffer);
       prot_name=(XeString)"  <-- CHANNEL_TERMIOS";
+      free(buffer);
       break;
     }
 
@@ -964,6 +970,7 @@ int SPC_Write_Protocol_Request (SPC_Connection_Ptr connection,
     if(connection->protocol_version < 3) {
       SPC_Error(SPC_Protocol_Version_Error,
                3, channel->connection->protocol_version);
+      SPC_Free_Protocol_Ptr(prot_request);
       return(SPC_ERROR);
     }
 
@@ -1159,12 +1166,12 @@ int SPC_Send_Multi_Packet(SPC_Connection_Ptr connection,
     
     if(this_str == NULL)
       this_str = NULL_STR;
-    if(*this_str == NULL)
+    if(*this_str == '\0')
       this_str = EMPTY_STR;
     
     tmp_len=strlen(this_str)+1;         /* Room for NULL char */
     if((bytes_left-tmp_len) < 1) {
-      *buf=NULL;
+      *buf='\0';
       prot->dataptr->len=numbytes+1;
       SPC_Write_Single_Prot_Request(connection, name, prot);
       SPC_Free_Protocol_Ptr(prot);
@@ -1193,7 +1200,7 @@ int SPC_Send_Multi_Packet(SPC_Connection_Ptr connection,
   }
   
   if(numbytes) {
-    *buf=NULL;
+    *buf='\0';
     prot->dataptr->len=numbytes+1;
     SPC_Write_Single_Prot_Request(connection, (XeString)"  <-- ENVIRON_RESET", prot);
     SPC_Free_Protocol_Ptr(prot);
@@ -1228,8 +1235,10 @@ char **SPC_Get_Multi_Packet(SPC_Connection_Ptr connection,
       if(localprot)
        SPC_Free_Protocol_Ptr(localprot);
       prot=SPC_Filter_Connection(connection, NULL, request, TRUE);
-      if(prot==SPC_ERROR)
-       return(SPC_ERROR);
+      if(prot==SPC_ERROR) {
+        free(out);
+        return(SPC_ERROR);
+      }
       print_protocol_request(name, prot);
       localprot=prot;
       bufptr=PDRP(prot->dataptr);
@@ -1342,7 +1351,7 @@ XeString *sscan_counted_string(XeString buf,
     len=strlen(bufptr)+1;  /* len is string SIZE (with room for NULL) */
     *tmpidx=(XeString)XeMalloc(len);
     strncpy(*tmpidx, bufptr, len);
-    (*tmpidx)[len-1]=NULL;
+    (*tmpidx)[len-1]='\0';
     bufptr+= len;
   }
   *tmpidx=NULL;
@@ -1441,6 +1450,8 @@ sscan_application_data(XeString buf,
   *envp=sscan_counted_string(bufptr, &bufptr);
   if(*envp==SPC_ERROR)
     return(SPC_ERROR);
+    
+  return(TRUE);
 }
 
 /*----------------------------------------------------------------------+*/
@@ -1656,7 +1667,7 @@ int SPC_Query_Logfile(SPC_Channel_Ptr channel)
   
   READ_LOGFILE_REPLY(prot->dataptr, &channel->logfile, &junk1, &junk2);
   if (junk1) XeFree(junk1);
-  if (junk1) XeFree(junk2);
+  if (junk2) XeFree(junk2);
                     
   SPC_Free_Protocol_Ptr(prot);
   return (TRUE);
@@ -1810,6 +1821,7 @@ SPC_Validate_User(XeString hostname,
     tt_free (path);
     XeFree(connection_hostname);
     if (logfile) XeFree(logfile);
+    close(open_status);
     return(SPC_ERROR);
   }