Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
if(get_line(buffer, line, false) == BUFFER_CRLF)
HTTPmsg__Types::log_debug(socket_debugging, test_port_type, test_port_name, "Trailing \\r\\n ok!");
else
TTCN_Logger::log(TTCN_WARNING,"Trailing \\r\\n after the closing chunk is not present, instead it is <%s>!", (const char*)line);
}
/* else if(chunk_size < 0) // the chunk_size is unsigned, never true
{
HTTPmsg__Types::log_debug(socket_debugging, test_port_type, test_port_name, "chunk_size less than 0");
decoding_params.error = TRUE;
chunk_size = 0;
}*/
else // chunk_size > 0
{
HTTPmsg__Types::log_debug(socket_debugging, test_port_type, test_port_name, "processing next chunk, size: %d", chunk_size);
if(buffer->get_read_len() < chunk_size)
{
HTTPmsg__Types::log_debug(socket_debugging, test_port_type, test_port_name, "chunk size is greater than the buffer length, more data is needed");
decoding_params.isMessage = FALSE;
chunk_size = 0;
}
}
}
break;
case FALSE:
HTTPmsg__Types::log_debug(socket_debugging, test_port_type, test_port_name, "buffer does not contain a whole line, more data is needed");
decoding_params.isMessage = FALSE;
chunk_size = 0;
break;
case BUFFER_CRLF:
HTTPmsg__Types::log_debug(socket_debugging, test_port_type, test_port_name, "beginning CRLF removed");
continue;
case BUFFER_FAIL:
HTTPmsg__Types::log_debug(socket_debugging, test_port_type, test_port_name, "BUFFER_FAIL");
decoding_params.error = FALSE;
chunk_size = 0;
break;
default:
decoding_params.isMessage = FALSE;
chunk_size = 0;
HTTPmsg__Types::log_debug(socket_debugging, test_port_type, test_port_name, "more data is needed");
}
body = body + OCTETSTRING(chunk_size, buffer->get_read_data());
HTTPmsg__Types::log_debug(socket_debugging, test_port_type, test_port_name, "pull %d bytes from %d", chunk_size, buffer->get_read_len());
buffer->set_pos(buffer->get_pos() + chunk_size);
// hack
if(buffer->get_read_len() && buffer->get_read_data()[0] == '\n') // don't read from the buffer if there is nothing in it.
{
HTTPmsg__Types::log_debug(socket_debugging, test_port_type, test_port_name,"hack: adjusted buffer position after the '\\n'");
buffer->set_pos(buffer->get_pos() + 1);
}
HTTPmsg__Types::log_debug(socket_debugging, test_port_type, test_port_name, "remaining data: <%s>, len: %d", (const char *)CHARSTRING(buffer->get_read_len(), (const char*)buffer->get_read_data()), buffer->get_read_len());
}
}
int get_line(TTCN_Buffer* buffer, CHARSTRING& to, const bool concatenate_header_lines)
{
unsigned int i = 0;
const unsigned char *cc_to = buffer->get_read_data();
if(!buffer->get_read_len())
return FALSE;
while(1)
{
for( ; i < buffer->get_read_len() && cc_to[i] != '\0' && cc_to[i] != '\r' && cc_to[i] != '\n'; i++);
if(i >= buffer->get_read_len())
{
to = CHARSTRING("");
return FALSE;
}
else
{
if(cc_to[i] == '\n') {//
if(report_lf){
switch(HTTPmsg__Types::crlf__mode){
case HTTPmsg__Types::strict__crlf__mode::ERROR_:
return BUFFER_FAIL;
break;
case HTTPmsg__Types::strict__crlf__mode::WARNING__ONCE:
report_lf=false;
// no break
case HTTPmsg__Types::strict__crlf__mode::WARNING:
TTCN_warning("Missing '\\r'.");
break;
default:
break;
}
}
if(i > 0 && (i + 1) < buffer->get_read_len() && concatenate_header_lines && (cc_to[i+1] == ' ' || cc_to[i+1] == '\t'))
i += 1;
else
{
to = CHARSTRING(i, (const char*)cc_to);
buffer->set_pos(buffer->get_pos() + i + 1);
return i == 0 ? BUFFER_CRLF : TRUE;
}
} else
{
if((i + 1) < buffer->get_read_len() && cc_to[i + 1] != '\n')
return BUFFER_FAIL;
else if(i > 0 && (i + 2) < buffer->get_read_len() && concatenate_header_lines && (cc_to[i+2] == ' ' || cc_to[i+2] == '\t'))
i += 2;
else
{
to = CHARSTRING(i, (const char*)cc_to);
buffer->set_pos(buffer->get_pos() + i + 2);
return i == 0 ? BUFFER_CRLF : TRUE;
}
}
}
}
}
void log_to_hexa(TTCN_Buffer* buffer)
{
int len = buffer->get_read_len();
const unsigned char* ptr = buffer->get_read_data();
for(int i = buffer->get_pos(); i < len; i++)
{
TTCN_Logger::log_event(" %02X", ptr[i]);
}
}
const char* HTTPmsg__PT::local_port_name() { return "";}
const char* HTTPmsg__PT::remote_address_name() { return "";}
const char* HTTPmsg__PT::local_address_name() { return "";}
const char* HTTPmsg__PT::remote_port_name() { return "";}
const char* HTTPmsg__PT::use_notification_ASPs_name() { return "use_notification_ASPs";}
const char* HTTPmsg__PT::halt_on_connection_reset_name(){ return "";}
const char* HTTPmsg__PT::server_mode_name() { return "";}
const char* HTTPmsg__PT::socket_debugging_name() { return "http_debugging";}
const char* HTTPmsg__PT::nagling_name() { return "";}
const char* HTTPmsg__PT::server_backlog_name() { return "server_backlog";}
const char* HTTPmsg__PT::ssl_use_ssl_name() { return "";}
const char* HTTPmsg__PT::ssl_use_session_resumption_name() { return "";}
const char* HTTPmsg__PT::ssl_private_key_file_name() { return "KEYFILE";}
const char* HTTPmsg__PT::ssl_trustedCAlist_file_name() { return "TRUSTEDCALIST_FILE";}
const char* HTTPmsg__PT::ssl_certificate_file_name() { return "CERTIFICATEFILE";}
const char* HTTPmsg__PT::ssl_password_name() { return "PASSWORD";}
const char* HTTPmsg__PT::ssl_verifycertificate_name() { return "VERIFYCERTIFICATE";}
} //eof namespace "HTTPmsg__PortType"
namespace HTTPmsg__Types {
using namespace HTTPmsg__PortType;
//=========================================================================
//==== Working Functions independent from sending and receiving:===
//=========================================================================
//from AbstractSocket
void log_debug(const bool socket_debugging, const char *test_port_type, const char *test_port_name, const char *fmt, ...)
{
if (socket_debugging) {
TTCN_Logger::begin_event(TTCN_DEBUG);
if ((test_port_type!=NULL && test_port_name!=NULL)&&(strlen(test_port_type)!=0 && strlen(test_port_name)!=0))
TTCN_Logger::log_event("%s test port (%s): ", test_port_type, test_port_name);
va_list args;
va_start(args, fmt);
TTCN_Logger::log_event_va_list(fmt, args);
va_end(args);
TTCN_Logger::end_event();
}
}
void log_warning(const char *test_port_type, const char *test_port_name, const char *fmt, ...)
{
TTCN_Logger::begin_event(TTCN_WARNING);
if (test_port_type!=NULL && test_port_name!=NULL)
TTCN_Logger::log_event("%s test port (%s): ", test_port_type, test_port_name);
va_list args;
va_start(args, fmt);
TTCN_Logger::log_event_va_list(fmt, args);
va_end(args);
TTCN_Logger::end_event();
}
//=========================================================================
//==== Encoder-decoder Functions independent from sending and receiving:===
//=========================================================================
/*********************************************************
* Function: enc__HTTPMessage
*
* Purpose:
* To encode msg type of HTTPMessage into OCTETSTRING separated from sending functionality
* It is for users using this test port as a protocol module
*
* References:
* RFC2616
*
* Precondition:
* msg is filled in properly
* Postcondition:
*
*
* Parameters:
* msg - the HTTP Message to be encoded
*
* Return Value:
* OCTETSTRING - the encoded message
* Detailed Comments:
* -
*
*********************************************************/
OCTETSTRING enc__HTTPMessage( const HTTPmsg__Types::HTTPMessage& msg ) {
TTCN_Buffer buf;
buf.clear();
HTTPmsg__PortType::f_HTTP_encodeCommon( msg, buf);
return OCTETSTRING(buf.get_len(), buf.get_data());
}
/*********************************************************
* Function: dec__HTTPMessage
*
* Purpose:
* To decode msg type of OCTETSTRING into HTTPMessage separated from receiving functionality
* It is for users using this test port as a protocol module
*
* References:
* RFC2616
*
* Precondition:
* stream is filled in properly
* Postcondition:
* -
*
* Parameters:
* stream - the message to be decoded
* msg - reference to the record type of HTTPMessage which will contain the decoded value if the return value less than the length of the original stream
* Return Value:
* integer - the length of the remaining data which is not decoded yet.
* Detailed Comments:
* If the full stream is decoded, the return value is zero
* If nothing is decoded (decoding failed) the return value equals to the original length of the stream
*
*********************************************************/
INTEGER dec__HTTPMessage(OCTETSTRING const& stream, HTTPMessage& msg, const BOOLEAN& socket_debugging = dec__HTTPMessage_socket__debugging_defval )
{
TTCN_Logger::log(TTCN_DEBUG, "starting HTTPmsg__Types::dec__HTTPMessage");
TTCN_Buffer *buf_p = new TTCN_Buffer() ;
buf_p->put_os(stream);
int buf_len = buf_p->get_read_len();
if( buf_len > 0)
{
if(f_HTTP_decodeCommon(buf_p, msg, true, socket_debugging, NULL, NULL))
{
log_debug(socket_debugging,"","","dec__HTTPMessage, after decoding:\nbuf_len: %d\nget_len: %d\nget_read_len:%d",
buf_len,
buf_p->get_len(),
buf_p->get_read_len());
buf_len = buf_p->get_read_len(); //remaining data length
}
else
buf_len = -1;
} else buf_len = -1;
delete buf_p;
return buf_len;
}
}//namespace