aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/connection.c')
-rw-r--r--src/daemon/connection.c87
1 files changed, 49 insertions, 38 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c
index 3fd03a41..e4c5df33 100644
--- a/src/daemon/connection.c
+++ b/src/daemon/connection.c
@@ -1065,27 +1065,30 @@ call_connection_handler (struct MHD_Connection *connection)
1065 int instant_retry; 1065 int instant_retry;
1066 unsigned int i; 1066 unsigned int i;
1067 int malformed; 1067 int malformed;
1068 char * buffer_head;
1068 1069
1069 if (connection->response != NULL) 1070 if (connection->response != NULL)
1070 return; /* already queued a response */ 1071 return; /* already queued a response */
1072
1073 buffer_head = connection->read_buffer;
1074 available = connection->read_buffer_offset;
1071 do 1075 do
1072 { 1076 {
1073 instant_retry = MHD_NO; 1077 instant_retry = MHD_NO;
1074 available = connection->read_buffer_offset;
1075 if ((connection->have_chunked_upload == MHD_YES) && 1078 if ((connection->have_chunked_upload == MHD_YES) &&
1076 (connection->remaining_upload_size == -1)) 1079 (connection->remaining_upload_size == -1))
1077 { 1080 {
1078 if ((connection->current_chunk_offset == 1081 if ((connection->current_chunk_offset == connection->current_chunk_size) &&
1079 connection->current_chunk_size) 1082 (connection->current_chunk_offset != 0) &&
1080 && (connection->current_chunk_offset != 0) && (available >= 2)) 1083 (available >= 2))
1081 { 1084 {
1082 /* skip new line at the *end* of a chunk */ 1085 /* skip new line at the *end* of a chunk */
1083 i = 0; 1086 i = 0;
1084 if ((connection->read_buffer[i] == '\r') || 1087 if ((buffer_head[i] == '\r') ||
1085 (connection->read_buffer[i] == '\n')) 1088 (buffer_head[i] == '\n'))
1086 i++; /* skip 1st part of line feed */ 1089 i++; /* skip 1st part of line feed */
1087 if ((connection->read_buffer[i] == '\r') || 1090 if ((buffer_head[i] == '\r') ||
1088 (connection->read_buffer[i] == '\n')) 1091 (buffer_head[i] == '\n'))
1089 i++; /* skip 2nd part of line feed */ 1092 i++; /* skip 2nd part of line feed */
1090 if (i == 0) 1093 if (i == 0)
1091 { 1094 {
@@ -1097,10 +1100,8 @@ call_connection_handler (struct MHD_Connection *connection)
1097 connection_close_error (connection); 1100 connection_close_error (connection);
1098 return; 1101 return;
1099 } 1102 }
1100 connection->read_buffer_offset -= i;
1101 available -= i; 1103 available -= i;
1102 memmove (connection->read_buffer, 1104 buffer_head += i;
1103 &connection->read_buffer[i], available);
1104 connection->current_chunk_offset = 0; 1105 connection->current_chunk_offset = 0;
1105 connection->current_chunk_size = 0; 1106 connection->current_chunk_size = 0;
1106 } 1107 }
@@ -1115,8 +1116,7 @@ call_connection_handler (struct MHD_Connection *connection)
1115 connection->current_chunk_offset; 1116 connection->current_chunk_offset;
1116 if (processed > available) 1117 if (processed > available)
1117 processed = available; 1118 processed = available;
1118 available -= processed; 1119 if (available > processed)
1119 if (available > 0)
1120 instant_retry = MHD_YES; 1120 instant_retry = MHD_YES;
1121 } 1121 }
1122 else 1122 else
@@ -1125,25 +1125,31 @@ call_connection_handler (struct MHD_Connection *connection)
1125 i = 0; 1125 i = 0;
1126 while (i < available) 1126 while (i < available)
1127 { 1127 {
1128 if ((connection->read_buffer[i] == '\r') || 1128 if ((buffer_head[i] == '\r') ||
1129 (connection->read_buffer[i] == '\n')) 1129 (buffer_head[i] == '\n'))
1130 break; 1130 break;
1131 i++; 1131 i++;
1132 if (i >= 6) 1132 if (i >= 6)
1133 break; 1133 break;
1134 } 1134 }
1135 if (i >= available) 1135 /* take '\n' into account; if '\n'
1136 return; /* need more data... */ 1136 is the unavailable character, we
1137 will need to wait until we have it
1138 before going further */
1139 if ( (i+1 >= available) &&
1140 ! ( (i == 1) &&
1141 (available == 2) &&
1142 (buffer_head[0] == '0') ) )
1143 break; /* need more data... */
1137 malformed = (i >= 6); 1144 malformed = (i >= 6);
1138 if (!malformed) 1145 if (!malformed)
1139 { 1146 {
1140 connection->read_buffer[i] = '\0'; 1147 buffer_head[i] = '\0';
1141 malformed = (1 != sscanf (connection->read_buffer, 1148 malformed =
1142 "%X", 1149 (1 != sscanf (buffer_head, "%X",
1143 &connection->current_chunk_size)) 1150 &connection->current_chunk_size)) &&
1144 && (1 != 1151 (1 != sscanf (buffer_head, "%x",
1145 sscanf (connection->read_buffer, "%x", 1152 &connection->current_chunk_size));
1146 &connection->current_chunk_size));
1147 } 1153 }
1148 if (malformed) 1154 if (malformed)
1149 { 1155 {
@@ -1156,18 +1162,21 @@ call_connection_handler (struct MHD_Connection *connection)
1156 return; 1162 return;
1157 } 1163 }
1158 i++; 1164 i++;
1159 if ((connection->read_buffer[i] == '\r') || 1165 if ((i<available) &&
1160 (connection->read_buffer[i] == '\n')) 1166 ( (buffer_head[i] == '\r') ||
1167 (buffer_head[i] == '\n')) )
1161 i++; /* skip 2nd part of line feed */ 1168 i++; /* skip 2nd part of line feed */
1162 memmove (connection->read_buffer, 1169
1163 &connection->read_buffer[i], available - i); 1170 buffer_head += i;
1164 connection->read_buffer_offset -= i; 1171 available -= i;
1165 connection->current_chunk_offset = 0; 1172 connection->current_chunk_offset = 0;
1166 instant_retry = MHD_YES; 1173
1174 if (available > 0)
1175 instant_retry = MHD_YES;
1167 if (connection->current_chunk_size == 0) 1176 if (connection->current_chunk_size == 0)
1168 { 1177 {
1169 connection->remaining_upload_size = 0; 1178 connection->remaining_upload_size = 0;
1170 return; 1179 break;
1171 } 1180 }
1172 continue; 1181 continue;
1173 } 1182 }
@@ -1176,7 +1185,6 @@ call_connection_handler (struct MHD_Connection *connection)
1176 { 1185 {
1177 /* no chunked encoding, give all to the client */ 1186 /* no chunked encoding, give all to the client */
1178 processed = available; 1187 processed = available;
1179 available = 0;
1180 } 1188 }
1181 used = processed; 1189 used = processed;
1182 if (MHD_NO == 1190 if (MHD_NO ==
@@ -1185,7 +1193,7 @@ call_connection_handler (struct MHD_Connection *connection)
1185 connection, connection->url, 1193 connection, connection->url,
1186 connection->method, 1194 connection->method,
1187 connection->version, 1195 connection->version,
1188 connection->read_buffer, 1196 buffer_head,
1189 &processed, 1197 &processed,
1190 &connection->client_context)) 1198 &connection->client_context))
1191 { 1199 {
@@ -1203,16 +1211,19 @@ call_connection_handler (struct MHD_Connection *connection)
1203 instant_retry = MHD_NO; /* client did not process everything */ 1211 instant_retry = MHD_NO; /* client did not process everything */
1204 used -= processed; 1212 used -= processed;
1205 if (connection->have_chunked_upload == MHD_YES) 1213 if (connection->have_chunked_upload == MHD_YES)
1206 connection->current_chunk_offset += used; 1214 connection->current_chunk_offset += used;
1207 /* dh left "processed" bytes in buffer for next time... */ 1215 /* dh left "processed" bytes in buffer for next time... */
1208 if (used > 0) 1216 buffer_head += used;
1209 memmove (connection->read_buffer, 1217 available -= used;
1210 &connection->read_buffer[used], processed + available);
1211 if (connection->remaining_upload_size != -1) 1218 if (connection->remaining_upload_size != -1)
1212 connection->remaining_upload_size -= used; 1219 connection->remaining_upload_size -= used;
1213 connection->read_buffer_offset = processed + available;
1214 } 1220 }
1215 while (instant_retry == MHD_YES); 1221 while (instant_retry == MHD_YES);
1222 if (available > 0)
1223 memmove(connection->read_buffer,
1224 buffer_head,
1225 available);
1226 connection->read_buffer_offset = available;
1216} 1227}
1217 1228
1218/** 1229/**