mirror of https://git.48k.eu/ogserver
				
				
				
			#915 add og_client_state_process_payload()
Move code that handles the message payload into function.master
							parent
							
								
									d491dfdb2d
								
							
						
					
					
						commit
						107b17a51b
					
				|  | @ -3560,12 +3560,38 @@ static int og_client_state_recv_hdr(struct og_client *cli) | ||||||
| 	return 1; | 	return 1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static int og_client_state_process_payload(struct og_client *cli) | ||||||
|  | { | ||||||
|  | 	TRAMA *ptrTrama; | ||||||
|  | 	char *data; | ||||||
|  | 	int len; | ||||||
|  | 
 | ||||||
|  | 	len = cli->msg_len - (LONGITUD_CABECERATRAMA + LONHEXPRM); | ||||||
|  | 	data = &cli->buf[LONGITUD_CABECERATRAMA + LONHEXPRM]; | ||||||
|  | 
 | ||||||
|  | 	ptrTrama = (TRAMA *)reservaMemoria(sizeof(TRAMA)); | ||||||
|  | 	if (!ptrTrama) { | ||||||
|  | 		syslog(LOG_ERR, "OOM\n"); | ||||||
|  | 		return -1; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	initParametros(ptrTrama, len); | ||||||
|  | 	memcpy(ptrTrama, cli->buf, LONGITUD_CABECERATRAMA); | ||||||
|  | 	memcpy(ptrTrama->parametros, data, len); | ||||||
|  | 	ptrTrama->lonprm = len; | ||||||
|  | 
 | ||||||
|  | 	gestionaTrama(ptrTrama, cli); | ||||||
|  | 
 | ||||||
|  | 	liberaMemoria(ptrTrama->parametros); | ||||||
|  | 	liberaMemoria(ptrTrama); | ||||||
|  | 
 | ||||||
|  | 	return 1; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static void og_client_read_cb(struct ev_loop *loop, struct ev_io *io, int events) | static void og_client_read_cb(struct ev_loop *loop, struct ev_io *io, int events) | ||||||
| { | { | ||||||
| 	struct og_client *cli; | 	struct og_client *cli; | ||||||
| 	TRAMA *ptrTrama; | 	int ret; | ||||||
| 	int ret, len; |  | ||||||
| 	char *data; |  | ||||||
| 
 | 
 | ||||||
| 	cli = container_of(io, struct og_client, io); | 	cli = container_of(io, struct og_client, io); | ||||||
| 
 | 
 | ||||||
|  | @ -3619,24 +3645,9 @@ static void og_client_read_cb(struct ev_loop *loop, struct ev_io *io, int events | ||||||
| 		       inet_ntoa(cli->addr.sin_addr), | 		       inet_ntoa(cli->addr.sin_addr), | ||||||
| 		       ntohs(cli->addr.sin_port)); | 		       ntohs(cli->addr.sin_port)); | ||||||
| 
 | 
 | ||||||
| 		len = cli->msg_len - (LONGITUD_CABECERATRAMA + LONHEXPRM); | 		ret = og_client_state_process_payload(cli); | ||||||
| 		data = &cli->buf[LONGITUD_CABECERATRAMA + LONHEXPRM]; | 		if (ret < 0) | ||||||
| 
 |  | ||||||
| 		ptrTrama = (TRAMA *)reservaMemoria(sizeof(TRAMA)); |  | ||||||
| 		if (!ptrTrama) { |  | ||||||
| 			syslog(LOG_ERR, "OOM\n"); |  | ||||||
| 			goto close; | 			goto close; | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		initParametros(ptrTrama, len); |  | ||||||
| 		memcpy(ptrTrama, cli->buf, LONGITUD_CABECERATRAMA); |  | ||||||
| 		memcpy(ptrTrama->parametros, data, len); |  | ||||||
| 		ptrTrama->lonprm = len; |  | ||||||
| 
 |  | ||||||
| 		gestionaTrama(ptrTrama, cli); |  | ||||||
| 
 |  | ||||||
| 		liberaMemoria(ptrTrama->parametros); |  | ||||||
| 		liberaMemoria(ptrTrama); |  | ||||||
| 
 | 
 | ||||||
| 		if (cli->keepalive_idx < 0) { | 		if (cli->keepalive_idx < 0) { | ||||||
| 			syslog(LOG_DEBUG, "server closing connection to %s:%hu\n", | 			syslog(LOG_DEBUG, "server closing connection to %s:%hu\n", | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue