void unlock_ga_bysessionid(sessionid_t sessionid) { unsigned int i; int j, number; syslog_session(sessionid, DBG_DEBUG, "Unlocking GAs by session-id"); for (i = 0; i < num_buses; i++) { number = get_number_ga(i); for (j = 1; j <= number; j++) { if (ga[i].gastate[j].locked_by == sessionid) { unlockGA(i, j, sessionid); } } } }
/* * Command mode network thread routine */ int doCmdClient(session_node_t * sn) { /*TODO: Optimize memory usage; these buffers occupy 6 kB stack * memory. */ char line[MAXSRCPLINELEN]; char reply[MAXSRCPLINELEN]; char cbus[MAXSRCPLINELEN]; char command[MAXSRCPLINELEN]; char devicegroup[MAXSRCPLINELEN]; char parameter[MAXSRCPLINELEN]; bus_t bus; long int rc, nelem; struct timeval akt_time; ssize_t result; syslog_session(sn->session, DBG_INFO, "Command mode starting."); while (true) { pthread_testcancel(); memset(line, 0, sizeof(line)); result = socket_readline(sn->socket, line, sizeof(line) - 1); /* client terminated connection */ if (0 == result) { shutdown(sn->socket, SHUT_RDWR); break; } /* read errror */ if (-1 == result) { syslog_session(sn->session, DBG_ERROR, "Socket read failed: %s (errno = %d)\n", strerror(errno), errno); break; } /*remove terminating line break */ size_t linelen = strlen(line); if (linelen > 1 && (line[linelen - 1] == '\n')) line[linelen - 1] = '\0'; memset(command, 0, sizeof(command)); memset(cbus, 0, sizeof(cbus)); memset(devicegroup, 0, sizeof(devicegroup)); memset(parameter, 0, sizeof(parameter)); memset(reply, 0, sizeof(reply)); nelem = sscanf(line, "%s %s %s %1000c", command, cbus, devicegroup, parameter); bus = atoi(cbus); reply[0] = 0x00; if (nelem >= 3) { if (bus <= num_buses) { rc = SRCP_UNKNOWNCOMMAND; if (strncasecmp(command, "SET", 3) == 0) { rc = handleSET(sn->session, bus, devicegroup, parameter, reply); } else if (strncasecmp(command, "GET", 3) == 0) { rc = handleGET(sn->session, bus, devicegroup, parameter, reply, sizeof(reply)); } else if (strncasecmp(command, "WAIT", 4) == 0) { rc = handleWAIT(sn->session, bus, devicegroup, parameter, reply, sizeof(reply)); } else if (strncasecmp(command, "INIT", 4) == 0) { rc = handleINIT(sn->session, bus, devicegroup, parameter, reply); } else if (strncasecmp(command, "TERM", 4) == 0) { rc = handleTERM(sn->session, bus, devicegroup, parameter, reply); /*special option for session termination (?) */ if (rc < 0) { if (writen(sn->socket, reply, strlen(reply)) == -1) { syslog_session(sn->session, DBG_ERROR, "Socket write failed: %s (errno = %d)\n", strerror(errno), errno); break; } break; } rc = abs(rc); } else if (strncasecmp(command, "VERIFY", 6) == 0) { rc = handleVERIFY(sn->session, bus, devicegroup, parameter, reply); } else if (strncasecmp(command, "RESET", 5) == 0) { rc = handleRESET(sn->session, bus, devicegroup, parameter, reply); } } /* bus > num_buses */ else { rc = SRCP_WRONGVALUE; gettimeofday(&akt_time, NULL); srcp_fmt_msg(rc, reply, akt_time); } } /* nelem < 3 */ else { syslog_session(sn->session, DBG_DEBUG, "List too short: %d", nelem); rc = SRCP_LISTTOOSHORT; gettimeofday(&akt_time, NULL); srcp_fmt_msg(rc, reply, akt_time); } if (writen(sn->socket, reply, strlen(reply)) == -1) { syslog_session(sn->session, DBG_ERROR, "Socket write failed: %s (errno = %d)\n", strerror(errno), errno); break; } } return 0; }