Fix some updating issues related to cwcs

This commit is contained in:
Andreas Öman 2008-05-17 07:47:38 +00:00
parent 1080cff57f
commit e9fb4dcd22
7 changed files with 23 additions and 61 deletions

View file

@ -123,10 +123,9 @@ ajax_cwclist(http_connection_t *hc, http_reply_t *hr,
"Username",
"Enabled",
"Status",
"Crypto",
"",
NULL},
(int[]){3, 2, 1, 6, 6, 1});
(int[]){3, 2, 1, 12, 1});
TAILQ_FOREACH(cwc, &cwcs, cwc_link) {
snprintf(id, sizeof(id), "cwc_%d", cwc->cwc_id);
@ -142,12 +141,11 @@ ajax_cwclist(http_connection_t *hc, http_reply_t *hr,
"<input %stype=\"checkbox\" class=\"nicebox\" "
"onChange=\"new Ajax.Request('/ajax/cwcchange', "
"{parameters: {checked: this.checked, id: %d}})\">",
1 ? "checked " : "", cwc->cwc_id);
cwc->cwc_tcp_session.tcp_enabled
? "checked " : "", cwc->cwc_id);
ajax_table_cell(&ta, "status", cwc_status_to_text(cwc));
ajax_table_cell(&ta, "crypto", cwc_crypto_to_text(cwc));
ajax_table_cell(&ta, NULL,
"<a href=\"javascript:void(0)\" "
"onClick=\"dellistentry('/ajax/cwcdel', '%d', '%s')\">"
@ -243,7 +241,7 @@ ajax_cwcchange(http_connection_t *hc, http_reply_t *hr,
if((txt = http_arg_get(&hc->hc_req_args, "checked")) == NULL)
return HTTP_STATUS_BAD_REQUEST;
// cwc_set_state(cwc, atoi(txt));
cwc_set_enable(cwc, !strcmp(txt, "true"));
http_output(hc, hr, "text/javascript; charset=UTF8", NULL, 0);
return 0;
}

View file

@ -498,14 +498,3 @@ ajax_mailbox_cwc_status_change(struct cwc *cwc)
ajax_mailbox_update_div("cwc", "status", id, cwc_status_to_text(cwc));
}
void
ajax_mailbox_cwc_crypto_change(struct cwc *cwc)
{
char id[20];
snprintf(id, sizeof(id), "cwc_%d", cwc->cwc_id);
ajax_mailbox_update_div("cwc", "crypto", id, cwc_crypto_to_text(cwc));
}

View file

@ -45,6 +45,4 @@ void ajax_mailbox_transport_status_change(struct th_transport *t);
struct cwc;
void ajax_mailbox_cwc_status_change(struct cwc *cwc);
void ajax_mailbox_cwc_crypto_change(struct cwc *cwc);
#endif /* AJAXUI_MAILBOX_H_ */

51
cwc.c
View file

@ -386,8 +386,6 @@ cwc_dispatch_card_data_reply(cwc_t *cwc, uint8_t msgtype,
cwc->cwc_caid = (msg[4] << 8) | msg[5];
n = psi_caid2name(cwc->cwc_caid) ?: "Unknown";
notify_cwc_crypto_change(cwc);
syslog(LOG_INFO, "cwc: %s: Connected as user 0x%02x "
"to a %s-card [0x%04x : %02x.%02x.%02x.%02x.%02x.%02x.%02x.%02x] "
"with %d providers",
@ -814,7 +812,7 @@ cwc_save(void)
cwc->cwc_confedkey[0xb],
cwc->cwc_confedkey[0xc],
cwc->cwc_confedkey[0xd]);
fprintf(fp, "\tenabled = %d\n", 1);
fprintf(fp, "\tenabled = %d\n", cwc->cwc_tcp_session.tcp_enabled);
fprintf(fp, "}\n");
@ -894,9 +892,7 @@ cwc_add(const char *hostname, const char *porttxt, const char *username,
return "Enabled not set";
cwc = tcp_create_client(hostname, port, sizeof(cwc_t),
"cwc", cwc_tcp_callback);
// cwc->cwc_enabled = atoi(enabled);
"cwc", cwc_tcp_callback, atoi(enabled));
cwc->cwc_username = strdup(username);
if(salt) {
@ -948,23 +944,15 @@ cwc_delete(cwc_t *cwc)
cwc_save();
}
#if 0
/**
*
*/
void
cwc_set_enable(cwc_t *cwc, int enabled)
{
if(cwc->enabled == enabled)
return;
cwc->enabled = enabled;
tcp_client_set_state(&cwc->cwc_tcp_session, enabled);
tcp_enable_disable(&cwc->cwc_tcp_session, enabled);
cwc_save();
}
#endif
/**
@ -1011,25 +999,24 @@ static struct strtab cwcstatustab[] = {
const char *
cwc_status_to_text(struct cwc *cwc)
{
static char buf[100];
char buf2[30];
const char *n;
if(cwc->cwc_state == CWC_STATE_IDLE)
return cwc->cwc_errtxt ?: "Not connected";
if(cwc->cwc_state == CWC_STATE_RUNNING) {
n = psi_caid2name(cwc->cwc_caid);
if(n == NULL) {
snprintf(buf2, sizeof(buf2), "0x%x", cwc->cwc_caid);
n = buf2;
}
snprintf(buf, sizeof(buf), "Connected to a %s card", n);
return buf;
}
return val2str(cwc->cwc_state, cwcstatustab) ?: "Invalid status";
}
const char *
cwc_crypto_to_text(struct cwc *cwc)
{
const char *n;
static char buf[40];
if(cwc->cwc_state != CWC_STATE_RUNNING)
return "Unknown";
n = psi_caid2name(cwc->cwc_caid);
if(n != NULL)
return n;
snprintf(buf, sizeof(buf), "0x%x", cwc->cwc_caid);
return buf;
}

2
cwc.h
View file

@ -85,6 +85,4 @@ void cwc_delete(cwc_t *cwc);
void cwc_set_enable(cwc_t *cwc, int enabled);
const char *cwc_crypto_to_text(struct cwc *cwc);
#endif /* CWC_H_ */

View file

@ -92,9 +92,3 @@ notify_cwc_status_change(struct cwc *cwc)
{
ajax_mailbox_cwc_status_change(cwc);
}
void
notify_cwc_crypto_change(struct cwc *cwc)
{
ajax_mailbox_cwc_status_change(cwc);
}

View file

@ -43,6 +43,4 @@ void notify_transprot_status_change(struct th_transport *t);
struct cwc;
void notify_cwc_status_change(struct cwc *cwc);
void notify_cwc_crypto_change(struct cwc *cwc);
#endif /* NOTIFY_H_ */