src/protocols/novell/nmconn.c

changeset 9360
c40bc951573a
parent 9268
196cbf2cae4c
child 10660
3f4f0e368ecb
equal deleted inserted replaced
9359:89c40efa7f7b 9360:c40bc951573a
164 str = "0"; 164 str = "0";
165 break; 165 break;
166 } 166 }
167 167
168 return str; 168 return str;
169 }
170
171 NMConn *
172 nm_create_conn(const char *addr, int port)
173 {
174 NMConn *conn = g_new0(NMConn, 1);
175 conn->addr = g_strdup(addr);
176 conn->port = port;
177 return conn;
178 }
179
180 void nm_release_conn(NMConn *conn)
181 {
182 if (conn) {
183 GSList *node;
184 for (node = conn->requests; node; node = node->next) {
185 if (node->data)
186 nm_release_request(node->data);
187 }
188 g_slist_free(conn->requests);
189 conn->requests = NULL;
190 if (conn->ssl_conn) {
191 g_free(conn->ssl_conn);
192 conn->ssl_conn = NULL;
193 }
194 g_free(conn->addr);
195 conn->addr = NULL;
196 g_free(conn);
197 }
169 } 198 }
170 199
171 int 200 int
172 nm_tcp_write(NMConn * conn, const void *buff, int len) 201 nm_tcp_write(NMConn * conn, const void *buff, int len)
173 { 202 {
374 403
375 return rc; 404 return rc;
376 } 405 }
377 406
378 NMERR_T 407 NMERR_T
379 nm_send_request(NMConn * conn, char *cmd, NMField * fields, NMRequest ** req) 408 nm_send_request(NMConn *conn, char *cmd, NMField *fields,
409 nm_response_cb cb, gpointer data, NMRequest **request)
380 { 410 {
381 NMERR_T rc = NM_OK; 411 NMERR_T rc = NM_OK;
382 char buffer[512]; 412 char buffer[512];
383 int bytes_to_send; 413 int bytes_to_send;
384 int ret; 414 int ret;
385 NMField *request = NULL; 415 NMField *request_fields = NULL;
386 char *str = NULL; 416 char *str = NULL;
387 417
388 if (conn == NULL || cmd == NULL) 418 if (conn == NULL || cmd == NULL)
389 return NMERR_BAD_PARM; 419 return NMERR_BAD_PARM;
390 420
415 } 445 }
416 446
417 /* Add the transaction id to the request fields */ 447 /* Add the transaction id to the request fields */
418 if (rc == NM_OK) { 448 if (rc == NM_OK) {
419 if (fields) 449 if (fields)
420 request = nm_copy_field_array(fields); 450 request_fields = nm_copy_field_array(fields);
421 451
422 str = g_strdup_printf("%d", ++(conn->trans_id)); 452 str = g_strdup_printf("%d", ++(conn->trans_id));
423 request = nm_field_add_pointer(request, NM_A_SZ_TRANSACTION_ID, 0, 453 request_fields = nm_field_add_pointer(request_fields, NM_A_SZ_TRANSACTION_ID, 0,
424 NMFIELD_METHOD_VALID, 0, 454 NMFIELD_METHOD_VALID, 0,
425 str, NMFIELD_TYPE_UTF8); 455 str, NMFIELD_TYPE_UTF8);
426 } 456 }
427 457
428 /* Send the request to the server */ 458 /* Send the request to the server */
429 if (rc == NM_OK) { 459 if (rc == NM_OK) {
430 rc = nm_write_fields(conn, request); 460 rc = nm_write_fields(conn, request_fields);
431 } 461 }
432 462
433 /* Write the CRLF to terminate the data */ 463 /* Write the CRLF to terminate the data */
434 if (rc == NM_OK) { 464 if (rc == NM_OK) {
435 ret = nm_tcp_write(conn, "\r\n", strlen("\r\n")); 465 ret = nm_tcp_write(conn, "\r\n", strlen("\r\n"));
436 if (ret < 0) { 466 if (ret < 0) {
437 rc = NMERR_TCP_WRITE; 467 rc = NMERR_TCP_WRITE;
438 } 468 }
439 } 469 }
440 470
441 /* Create a request struct and return it */ 471 /* Create a request struct, add it to our queue, and return it */
442 if (rc == NM_OK) { 472 if (rc == NM_OK) {
443 *req = nm_create_request(cmd, conn->trans_id, time(0)); 473 NMRequest *new_request = nm_create_request(cmd, conn->trans_id,
444 } 474 time(0), cb, NULL, data);
445 475 nm_conn_add_request_item(conn, new_request);
446 if (request != NULL) { 476
447 nm_free_fields(&request); 477 /* Set the out param if it was sent in, otherwise release the request */
448 } 478 if (request)
479 *request = new_request;
480 else
481 nm_release_request(new_request);
482 }
483
484 if (request_fields != NULL)
485 nm_free_fields(&request_fields);
449 486
450 return rc; 487 return rc;
451 } 488 }
452 489
453 NMERR_T 490 NMERR_T

mercurial