WIP.
[radsecproxy.git] / lib / packet.c
index e734452..68adf2b 100644 (file)
@@ -1,8 +1,11 @@
 #include <string.h>
+#include <assert.h>
 #include <freeradius/libradius.h>
 #include "libradsec.h"
 #include "libradsec-impl.h"
-
+#if defined DEBUG
+#include "debug.h"
+#endif
 
 int
 _packet_create (struct rs_connection *conn, struct rs_packet **pkt_out,
@@ -45,33 +48,45 @@ rs_packet_create_acc_request (struct rs_connection *conn,
 
   if (rs_attr_create (conn, &attr, "User-Name", user_name))
     return -1;
-  if (rs_packet_add_attr (pkt, attr))
-    return -1;
+  rs_packet_add_attr (pkt, attr);
 
   if (rs_attr_create (conn, &attr, "User-Password", user_name))
     return -1;
-  if (rs_packet_add_attr (pkt, attr))
-    return -1;
+  /* FIXME: need this too? rad_pwencode(user_pw, &pwlen, SECRET, reqauth) */
+  rs_packet_add_attr (pkt, attr);
 
   return RSE_OK;
 }
 
 int
-rs_packet_send (struct rs_conn *conn, const struct rs_packet *pkt,
+rs_packet_send (struct rs_connection *conn, const struct rs_packet *pkt,
                void *user_data)
 {
-  rad_encode (pkt->rpkt, NULL, pkt->conn->secret);
+  assert (pkt->rpkt);
+
+  if (!conn->active_peer)
+    {
+      int err = rs_conn_open (conn);
+      if (err)
+       return err;
+      }
+  rad_encode (pkt->rpkt, NULL, conn->active_peer->secret);
 #if defined (DEBUG)
-  fprintf (stderr, "%s: about to send this to %"
-  print_hex (pkt);
+  fprintf (stderr, "%s: about to send this to %s", __func__, "fixme");
+  rs_dump_packet (pkt);
 #endif
 
-  
-
   return RSE_NOSYS;
 }
 
-int rs_packet_receive(struct rs_conn *conn, struct rs_packet **pkt)
+int rs_packet_receive(struct rs_connection *conn, struct rs_packet **pkt)
 {
   return RSE_NOSYS;
 }
+
+void
+rs_packet_add_attr(struct rs_packet *pkt, struct rs_attr *attr)
+{
+  pairadd (&pkt->rpkt->vps, attr->vp);
+  attr->pkt = pkt;
+}