]> andersk Git - moira.git/blobdiff - lib/mr_connect.c
make auth do the right thing for version 2 of the protocol
[moira.git] / lib / mr_connect.c
index 25ba36eac12fbe1cf11788df9234e0199b46156e..f701aac9ad965d361e4c4b215c7411a188aed16f 100644 (file)
@@ -21,82 +21,65 @@ static char *rcsid_sms_connect_c = "$Header$";
 
 int sms_connect()
 {
-       extern int errno;
+    extern int errno;
        
-       if (!sms_inited) sms_init();
-       
-       /* 
-        * should do a hesiod call to find the sms machine name & service
-        * number/name.
-        */
-       /* XXX gdb doesn't give real return codes. Can we trust errno?*/
-       errno = 0;
-       _sms_conn = start_server_connection(SMS_GDB_SERV, ""); 
-       if (_sms_conn == NULL) {
-               return errno;
-       }
-       return 0;
+    if (!sms_inited) sms_init();
+    if (_sms_conn) return SMS_ALREADY_CONNECTED;
+               
+    /* 
+     * XXX should do a hesiod call to find the sms machine name & service
+     * number/name.
+     */
+    errno = 0;
+    _sms_conn = start_server_connection(SMS_GDB_SERV, ""); 
+    if (_sms_conn == NULL)
+       return errno;
+    if (connection_status(_sms_conn) == CON_STOPPED) {
+       register status = connection_errno(_sms_conn);
+       if (!status) status = SMS_CANT_CONNECT;
+       sms_disconnect();
+       return status;
+    }
+    return 0;
 }
        
 int sms_disconnect()
 {
-       if (!_sms_conn) {
-               return SMS_NOT_CONNECTED;
-       }
-       /* Is this guaranteed NOT to fail?? I don't believe it, but.. */
-       _sms_conn = sever_connection(_sms_conn);
-       return 0;
+    CHECK_CONNECTED;
+    _sms_conn = sever_connection(_sms_conn);
+    return 0;
 }
 
 int sms_noop()
 {
-       int status;
-       struct sms_params *parms = NULL;
-       struct sms_params *reply = NULL;
-       
-
-       parms = (struct sms_params *) malloc(sizeof(*parms));
-       
-       parms->sms_procno = SMS_NOOP;
-       parms->sms_argc = 0;
+    int status;
+    sms_params param_st;
+    struct sms_params *params = NULL;
+    struct sms_params *reply = NULL;
 
-       if ((status = sms_do_call(parms, &reply)) || (status = reply->sms_status))
-               goto punt;
+    CHECK_CONNECTED;
+    params = &param_st;
+    params->sms_version_no = sending_version_no;
+    params->sms_procno = SMS_NOOP;
+    params->sms_argc = 0;
+    params->sms_argl = NULL;
+    params->sms_argv = NULL;
        
+    if ((status = sms_do_call(params, &reply)) == 0)
+       status = reply->sms_status;
        
-punt:
-       sms_destroy_reply(reply);
-ok:
-       free(parms);
-       return status;
-}
-
-int sms_shutdown(why)
-       char *why;
-{
-       int status;
-       sms_params *parms=NULL;
-       sms_params *reply=NULL;
+    sms_destroy_reply(reply);
 
-       parms = (sms_params *) malloc(sizeof(*parms));
-       
-       parms->sms_procno = SMS_SHUTDOWN;
-       parms->sms_argc = 1;
-       parms->sms_argv = (char **)malloc(sizeof(char *) * 2);
-       parms->sms_argv[0] = why;
-       parms->sms_argv[1] = NULL;
-
-       if ((status = sms_do_call(parms, &reply)) || (status = reply->sms_status))
-               goto punt;
-       
-       
-punt:
-       sms_destroy_reply(reply);
-ok:
-       if(parms) {
-               if(parms->sms_argv)
-                       free(parms->sms_argv);
-               free(parms);
-       }
-       return status;
+    return status;
 }
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-indent-level: 4
+ * c-continued-statement-offset: 4
+ * c-brace-offset: -4
+ * c-argdecl-indent: 4
+ * c-label-offset: -4
+ * End:
+ */
This page took 0.038648 seconds and 4 git commands to generate.